Package de.danet.an.util.Duration

Examples of de.danet.an.util.Duration.ValueEvaluator


  assertTrue (((Duration)o).getMinutes() == 0);
  assertTrue (((Duration)o).getSeconds() == (float)0);

  o = XPDLUtil.parseDuration
      ("5 years x months 2days 3min 35.0sec",
       new ValueEvaluator () {
     public float evaluate (String s) throws ParseException {
         try {
       if (s.equals ("x")) {
           return -1;
       }
       return Float.parseFloat (s);
         } catch (NumberFormatException e) {
       throw new ParseException
           ("Not a number: " + s + ": " + e.getMessage (), 0);
         }
     }
       });
  assertTrue (o instanceof Duration);
  assertTrue (((Duration)o).getYears() == 5);
  assertTrue (((Duration)o).getMonths() == -1);
  assertTrue (((Duration)o).getDays() == 2);
  assertTrue (((Duration)o).getHours() == 0);
  assertTrue (((Duration)o).getMinutes() == 3);
  assertTrue (((Duration)o).getSeconds() == (float)35);

  o = XPDLUtil.parseDuration ("P5Y3M2DT3M35.0S");
  assertTrue (o instanceof Duration);
  assertTrue (((Duration)o).getYears() == 5);
  assertTrue (((Duration)o).getMonths() == 3);
  assertTrue (((Duration)o).getDays() == 2);
  assertTrue (((Duration)o).getHours() == 0);
  assertTrue (((Duration)o).getMinutes() == 3);
  assertTrue (((Duration)o).getSeconds() == (float)35);

  boolean gotEx = false;
  try {
      o = XPDLUtil.parseDuration ("Just garbage");
  } catch (ParseException e) {
      gotEx = true;
  }
  assertTrue (gotEx);

  o = XPDLUtil.parseDuration
      ("some_var days another-var - 2 hrs",
       new ValueEvaluator () {
     public float evaluate (String s) throws ParseException {
         try {
       if (s.equals ("some_var")) {
           return -1;
       }
View Full Code Here

TOP

Related Classes of de.danet.an.util.Duration.ValueEvaluator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.