List of usage examples for javax.xml.datatype DatatypeConstants INDETERMINATE
int INDETERMINATE
To view the source code for javax.xml.datatype DatatypeConstants INDETERMINATE.
Click Source Link
Comparison result.
From source file:DatatypeAPIUsage.java
public static void main(String[] args) { try {//from w w w. ja v a 2 s . co m DatatypeFactory df = DatatypeFactory.newInstance(); // my work number in milliseconds: Duration myPhone = df.newDuration(9054133519l); Duration myLife = df.newDuration(true, 29, 2, 15, 13, 45, 0); int compareVal = myPhone.compare(myLife); switch (compareVal) { case DatatypeConstants.LESSER: System.out.println("There are fewer milliseconds in my phone number than my lifespan."); break; case DatatypeConstants.EQUAL: System.out.println("The same number of milliseconds are in my phone number and my lifespan."); break; case DatatypeConstants.GREATER: System.out.println("There are more milliseconds in my phone number than my lifespan."); break; case DatatypeConstants.INDETERMINATE: System.out.println("The comparison could not be carried out."); } // create a yearMonthDuration Duration ymDuration = df.newDurationYearMonth("P12Y10M"); System.out.println("P12Y10M is of type: " + ymDuration.getXMLSchemaType()); // create a dayTimeDuration (really this time) Duration dtDuration = df.newDurationDayTime("P10DT10H12M0S"); System.out.println("P10DT10H12M0S is of type: " + dtDuration.getXMLSchemaType()); // try to fool the factory! try { ymDuration = df.newDurationYearMonth("P12Y10M1D"); } catch (IllegalArgumentException e) { System.out.println("'duration': P12Y10M1D is not 'yearMonthDuration'!!!"); } XMLGregorianCalendar xgc = df.newXMLGregorianCalendar(); xgc.setYear(1975); xgc.setMonth(DatatypeConstants.AUGUST); xgc.setDay(11); xgc.setHour(6); xgc.setMinute(44); xgc.setSecond(0); xgc.setMillisecond(0); xgc.setTimezone(5); xgc.add(myPhone); System.out.println("The approximate end of the number of milliseconds in my phone number was " + xgc); // adding a duration to XMLGregorianCalendar xgc.add(myLife); System.out.println("Adding the duration myLife to the above calendar:" + xgc); // create a new XMLGregorianCalendar using the string format of xgc. XMLGregorianCalendar xgcCopy = df.newXMLGregorianCalendar(xgc.toXMLFormat()); // should be equal-if not what happened!! if (xgcCopy.compare(xgc) != DatatypeConstants.EQUAL) { System.out.println("oooops!"); } else { System.out.println("Very good: " + xgc + " is equal to " + xgcCopy); } } catch (DatatypeConfigurationException dce) { System.err.println("error: Datatype error occurred - " + dce.getMessage()); dce.printStackTrace(System.err); } }
From source file:Main.java
/** * Validate that the current time falls between the two boundaries * * @param now// w w w . j a v a 2s . co m * @param notbefore * @param notOnOrAfter * * @return */ public static boolean isValid(XMLGregorianCalendar now, XMLGregorianCalendar notbefore, XMLGregorianCalendar notOnOrAfter) { int val = 0; if (notbefore != null) { val = notbefore.compare(now); if (val == DatatypeConstants.INDETERMINATE || val == DatatypeConstants.GREATER) return false; } if (notOnOrAfter != null) { val = notOnOrAfter.compare(now); if (val != DatatypeConstants.GREATER) return false; } return true; }
From source file:de.escidoc.core.test.EscidocTestBase.java
/** * Returns a positive integer if ts1 depicts a time after ts2 (ts1 > ts2), 0 if ts1 and ts2 depict the same time * (ts1 == ts2), and a negative integer if if ts1 depicts a time before ts2 (ts1 < ts2). * /* w w w .j a v a2 s . c o m*/ * @param ts1 * The first timestamp. * @param ts2 * The second timestamp. * @return The comparison result. * @throws Exception * If anything fails (e.g. one timstamp has incorrect format). */ public static int compareTimestamps(final String ts1, final String ts2) throws Exception { int result = 0; XMLGregorianCalendar date1 = DatatypeFactory.newInstance().newXMLGregorianCalendar(ts1); XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(ts2); int diff = date1.compare(date2); if (diff == DatatypeConstants.LESSER) { result = -1; } else if (diff == DatatypeConstants.GREATER) { result = 1; } else if (diff == DatatypeConstants.EQUAL) { result = 0; } else if (diff == DatatypeConstants.INDETERMINATE) { throw new Exception("Date comparing: INDETERMINATE"); } return result; }