Java Code Examples for javax.xml.datatype.DatatypeConstants#LESSER
The following examples show how to use
javax.xml.datatype.DatatypeConstants#LESSER .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLGregorianCalendarImpl.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * <p>Implement Step B from * http://www.w3.org/TR/xmlschema-2/#dateTime-order.</p> */ private static int compareField(int Pfield, int Qfield) { if (Pfield == Qfield) { //fields are either equal in value or both undefined. // Step B. 1.1 AND optimized result of performing 1.1-1.4. return DatatypeConstants.EQUAL; } else { if (Pfield == DatatypeConstants.FIELD_UNDEFINED || Qfield == DatatypeConstants.FIELD_UNDEFINED) { // Step B. 1.2 return DatatypeConstants.INDETERMINATE; } else { // Step B. 1.3-4. return (Pfield < Qfield ? DatatypeConstants.LESSER : DatatypeConstants.GREATER); } } }
Example 2
Source File: SamlUtil.java From keycloak with Apache License 2.0 | 6 votes |
public static SamlSession validateSamlSession(Object potentialSamlSession, SamlDeployment deployment) { if (potentialSamlSession == null) { log.debug("SamlSession was not found in the session"); return null; } if (!(potentialSamlSession instanceof SamlSession)) { log.debug("Provided samlSession was not SamlSession type"); return null; } SamlSession samlSession = (SamlSession) potentialSamlSession; XMLGregorianCalendar sessionNotOnOrAfter = samlSession.getSessionNotOnOrAfter(); if (sessionNotOnOrAfter != null) { XMLGregorianCalendar now = XMLTimeUtil.getIssueInstant(); XMLTimeUtil.add(sessionNotOnOrAfter, deployment.getIDP().getAllowedClockSkew()); // add clockSkew if (now.compare(sessionNotOnOrAfter) != DatatypeConstants.LESSER) { return null; } } return samlSession; }
Example 3
Source File: FEELXMLGregorianCalendar.java From jdmn with Apache License 2.0 | 6 votes |
/** * Implement Step B from * http://www.w3.org/TR/xmlschema-2/#dateTime-order.</p> */ private static int compareField(int field1, int field2) { if (field1 == field2) { //fields are either equal in value or both undefined. // Step B. 1.1 AND optimized result of performing 1.1-1.4. return DatatypeConstants.EQUAL; } else { if (field1 == DatatypeConstants.FIELD_UNDEFINED || field2 == DatatypeConstants.FIELD_UNDEFINED) { // Step B. 1.2 return DatatypeConstants.INDETERMINATE; } else { // Step B. 1.3-4. return field1 < field2 ? DatatypeConstants.LESSER : DatatypeConstants.GREATER; } } }
Example 4
Source File: ConditionsValidator.java From keycloak with Apache License 2.0 | 6 votes |
/** * Validate as per Section 2.5.1.2 * @return */ private Result validateExpiration() { XMLGregorianCalendar notBefore = conditions.getNotBefore(); XMLGregorianCalendar notOnOrAfter = conditions.getNotOnOrAfter(); if (notBefore == null && notOnOrAfter == null) { return Result.VALID; } if (notBefore != null && notOnOrAfter != null && notBefore.compare(notOnOrAfter) != DatatypeConstants.LESSER) { return Result.INVALID; } XMLGregorianCalendar updatedNotBefore = XMLTimeUtil.subtract(notBefore, clockSkewInMillis); XMLGregorianCalendar updatedOnOrAfter = XMLTimeUtil.add(notOnOrAfter, clockSkewInMillis); LOG.debugf("Evaluating Conditions of Assertion %s. notBefore=%s, notOnOrAfter=%s, updatedNotBefore: %s, updatedOnOrAfter=%s, now: %s", assertionId, notBefore, notOnOrAfter, updatedNotBefore, updatedOnOrAfter, now); boolean valid = XMLTimeUtil.isValid(now, updatedNotBefore, updatedOnOrAfter); if (! valid) { LOG.infof("Assertion %s expired.", assertionId); } return valid ? Result.VALID : Result.INVALID; }
Example 5
Source File: XMLGregorianCalendarImpl.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * <p>Implement Step B from * http://www.w3.org/TR/xmlschema-2/#dateTime-order.</p> */ private static int compareField(int Pfield, int Qfield) { if (Pfield == Qfield) { //fields are either equal in value or both undefined. // Step B. 1.1 AND optimized result of performing 1.1-1.4. return DatatypeConstants.EQUAL; } else { if (Pfield == DatatypeConstants.FIELD_UNDEFINED || Qfield == DatatypeConstants.FIELD_UNDEFINED) { // Step B. 1.2 return DatatypeConstants.INDETERMINATE; } else { // Step B. 1.3-4. return (Pfield < Qfield ? DatatypeConstants.LESSER : DatatypeConstants.GREATER); } } }
Example 6
Source File: XMLGregorianCalendarImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * <p>Implement Step B from * http://www.w3.org/TR/xmlschema-2/#dateTime-order.</p> */ private static int compareField(int Pfield, int Qfield) { if (Pfield == Qfield) { //fields are either equal in value or both undefined. // Step B. 1.1 AND optimized result of performing 1.1-1.4. return DatatypeConstants.EQUAL; } else { if (Pfield == DatatypeConstants.FIELD_UNDEFINED || Qfield == DatatypeConstants.FIELD_UNDEFINED) { // Step B. 1.2 return DatatypeConstants.INDETERMINATE; } else { // Step B. 1.3-4. return (Pfield < Qfield ? DatatypeConstants.LESSER : DatatypeConstants.GREATER); } } }
Example 7
Source File: XMLGregorianCalendarImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * <p>Implement Step B from * http://www.w3.org/TR/xmlschema-2/#dateTime-order.</p> */ private static int compareField(int Pfield, int Qfield) { if (Pfield == Qfield) { //fields are either equal in value or both undefined. // Step B. 1.1 AND optimized result of performing 1.1-1.4. return DatatypeConstants.EQUAL; } else { if (Pfield == DatatypeConstants.FIELD_UNDEFINED || Qfield == DatatypeConstants.FIELD_UNDEFINED) { // Step B. 1.2 return DatatypeConstants.INDETERMINATE; } else { // Step B. 1.3-4. return (Pfield < Qfield ? DatatypeConstants.LESSER : DatatypeConstants.GREATER); } } }
Example 8
Source File: DoubleDurationType.java From jdmn with Apache License 2.0 | 5 votes |
@Override public Boolean durationLessEqualThan(Duration first, Duration second) { if (first == null && second == null) { return false; } else if (first == null) { return null; } else if (second == null) { return null; } else { int compare = compare(first, second); return compare == DatatypeConstants.LESSER || compare == DatatypeConstants.EQUAL; } }
Example 9
Source File: DoubleSignavioDurationType.java From jdmn with Apache License 2.0 | 5 votes |
@Override public Boolean durationLessEqualThan(Duration first, Duration second) { if (first == null && second == null) { return null; } else if (first == null) { return null; } else if (second == null) { return null; } else { int compare = compare(first, second); return compare == DatatypeConstants.LESSER || compare == DatatypeConstants.EQUAL; } }
Example 10
Source File: XMLGregorianCalendarImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * <p>Compare two instances of W3C XML Schema 1.0 date/time datatypes * according to partial order relation defined in * <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">W3C XML Schema 1.0 Part 2, Section 3.2.7.3, * <i>Order relation on dateTime</i></a>.</p> * * <p><code>xsd:dateTime</code> datatype field mapping to accessors of * this class are defined in * <a href="#datetimefieldmapping">date/time field mapping table</a>.</p> * * @param rhs instance of <code>XMLGregorianCalendar</code> to compare * * @return the relationship between <code>lhs</code> and <code>rhs</code> as * {@link DatatypeConstants#LESSER}, * {@link DatatypeConstants#EQUAL}, * {@link DatatypeConstants#GREATER} or * {@link DatatypeConstants#INDETERMINATE}. * * @throws NullPointerException if <code>lhs</code> or <code>rhs</code> * parameters are null. */ public int compare(XMLGregorianCalendar rhs) { XMLGregorianCalendar lhs = this; int result = DatatypeConstants.INDETERMINATE; XMLGregorianCalendarImpl P = (XMLGregorianCalendarImpl) lhs; XMLGregorianCalendarImpl Q = (XMLGregorianCalendarImpl) rhs; if (P.getTimezone() == Q.getTimezone()) { // Optimization: // both instances are in same timezone or // both are FIELD_UNDEFINED. // Avoid costly normalization of timezone to 'Z' time. return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { // Both instances have different timezones. // Normalize to UTC time and compare. P = (XMLGregorianCalendarImpl) P.normalize(); Q = (XMLGregorianCalendarImpl) Q.normalize(); return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { if (P.getTimezone() != 0) { P = (XMLGregorianCalendarImpl) P.normalize(); } // C. step 1 XMLGregorianCalendar MinQ = Q.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(P, MinQ); if (result == DatatypeConstants.LESSER) { return result; } // C. step 2 XMLGregorianCalendar MaxQ = Q.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(P, MaxQ); if (result == DatatypeConstants.GREATER) { return result; } else { // C. step 3 return DatatypeConstants.INDETERMINATE; } } else { // Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED // P has no timezone and Q does. if (Q.getTimezone() != 0) { Q = (XMLGregorianCalendarImpl) Q.normalizeToTimezone(Q.getTimezone()); } // D. step 1 XMLGregorianCalendar MaxP = P.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(MaxP, Q); if (result == DatatypeConstants.LESSER) { return result; } // D. step 2 XMLGregorianCalendar MinP = P.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(MinP, Q); if (result == DatatypeConstants.GREATER) { return result; } else { // D. step 3 return DatatypeConstants.INDETERMINATE; } } }
Example 11
Source File: XMLGregorianCalendarImpl.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * <p>Compare two instances of W3C XML Schema 1.0 date/time datatypes * according to partial order relation defined in * <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">W3C XML Schema 1.0 Part 2, Section 3.2.7.3, * <i>Order relation on dateTime</i></a>.</p> * * <p><code>xsd:dateTime</code> datatype field mapping to accessors of * this class are defined in * <a href="#datetimefieldmapping">date/time field mapping table</a>.</p> * * @param rhs instance of <code>XMLGregorianCalendar</code> to compare * * @return the relationship between <code>lhs</code> and <code>rhs</code> as * {@link DatatypeConstants#LESSER}, * {@link DatatypeConstants#EQUAL}, * {@link DatatypeConstants#GREATER} or * {@link DatatypeConstants#INDETERMINATE}. * * @throws NullPointerException if <code>lhs</code> or <code>rhs</code> * parameters are null. */ public int compare(XMLGregorianCalendar rhs) { XMLGregorianCalendar lhs = this; int result = DatatypeConstants.INDETERMINATE; XMLGregorianCalendarImpl P = (XMLGregorianCalendarImpl) lhs; XMLGregorianCalendarImpl Q = (XMLGregorianCalendarImpl) rhs; if (P.getTimezone() == Q.getTimezone()) { // Optimization: // both instances are in same timezone or // both are FIELD_UNDEFINED. // Avoid costly normalization of timezone to 'Z' time. return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { // Both instances have different timezones. // Normalize to UTC time and compare. P = (XMLGregorianCalendarImpl) P.normalize(); Q = (XMLGregorianCalendarImpl) Q.normalize(); return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { if (P.getTimezone() != 0) { P = (XMLGregorianCalendarImpl) P.normalize(); } // C. step 1 XMLGregorianCalendar MinQ = Q.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(P, MinQ); if (result == DatatypeConstants.LESSER) { return result; } // C. step 2 XMLGregorianCalendar MaxQ = Q.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(P, MaxQ); if (result == DatatypeConstants.GREATER) { return result; } else { // C. step 3 return DatatypeConstants.INDETERMINATE; } } else { // Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED // P has no timezone and Q does. if (Q.getTimezone() != 0) { Q = (XMLGregorianCalendarImpl) Q.normalizeToTimezone(Q.getTimezone()); } // D. step 1 XMLGregorianCalendar MaxP = P.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(MaxP, Q); if (result == DatatypeConstants.LESSER) { return result; } // D. step 2 XMLGregorianCalendar MinP = P.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(MinP, Q); if (result == DatatypeConstants.GREATER) { return result; } else { // D. step 3 return DatatypeConstants.INDETERMINATE; } } }
Example 12
Source File: DurationTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static String cmp2str(int cmp) { return cmp == DatatypeConstants.LESSER ? "LESSER" : cmp == DatatypeConstants.GREATER ? "GREATER" : cmp == DatatypeConstants.EQUAL ? "EQUAL" : cmp == DatatypeConstants.INDETERMINATE ? "INDETERMINATE" : "UNDEFINED"; }
Example 13
Source File: XMLGregorianCalendarImpl.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * <p>Compare two instances of W3C XML Schema 1.0 date/time datatypes * according to partial order relation defined in * <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">W3C XML Schema 1.0 Part 2, Section 3.2.7.3, * <i>Order relation on dateTime</i></a>.</p> * * <p><code>xsd:dateTime</code> datatype field mapping to accessors of * this class are defined in * <a href="#datetimefieldmapping">date/time field mapping table</a>.</p> * * @param rhs instance of <code>XMLGregorianCalendar</code> to compare * * @return the relationship between <code>lhs</code> and <code>rhs</code> as * {@link DatatypeConstants#LESSER}, * {@link DatatypeConstants#EQUAL}, * {@link DatatypeConstants#GREATER} or * {@link DatatypeConstants#INDETERMINATE}. * * @throws NullPointerException if <code>lhs</code> or <code>rhs</code> * parameters are null. */ public int compare(XMLGregorianCalendar rhs) { XMLGregorianCalendar lhs = this; int result = DatatypeConstants.INDETERMINATE; XMLGregorianCalendarImpl P = (XMLGregorianCalendarImpl) lhs; XMLGregorianCalendarImpl Q = (XMLGregorianCalendarImpl) rhs; if (P.getTimezone() == Q.getTimezone()) { // Optimization: // both instances are in same timezone or // both are FIELD_UNDEFINED. // Avoid costly normalization of timezone to 'Z' time. return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { // Both instances have different timezones. // Normalize to UTC time and compare. P = (XMLGregorianCalendarImpl) P.normalize(); Q = (XMLGregorianCalendarImpl) Q.normalize(); return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { if (P.getTimezone() != 0) { P = (XMLGregorianCalendarImpl) P.normalize(); } // C. step 1 XMLGregorianCalendar MinQ = Q.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(P, MinQ); if (result == DatatypeConstants.LESSER) { return result; } // C. step 2 XMLGregorianCalendar MaxQ = Q.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(P, MaxQ); if (result == DatatypeConstants.GREATER) { return result; } else { // C. step 3 return DatatypeConstants.INDETERMINATE; } } else { // Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED // P has no timezone and Q does. if (Q.getTimezone() != 0) { Q = (XMLGregorianCalendarImpl) Q.normalizeToTimezone(Q.getTimezone()); } // D. step 1 XMLGregorianCalendar MaxP = P.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(MaxP, Q); if (result == DatatypeConstants.LESSER) { return result; } // D. step 2 XMLGregorianCalendar MinP = P.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(MinP, Q); if (result == DatatypeConstants.GREATER) { return result; } else { // D. step 3 return DatatypeConstants.INDETERMINATE; } } }
Example 14
Source File: FEELXMLGregorianCalendar.java From jdmn with Apache License 2.0 | 4 votes |
@Override public int compare(XMLGregorianCalendar other) { FEELXMLGregorianCalendar lhs = this; FEELXMLGregorianCalendar rhs = (FEELXMLGregorianCalendar) other; int result; if (lhs.getTimezone() == rhs.getTimezone()) { // Optimization: // both instances are in same timezone or // both are FIELD_UNDEFINED. // Avoid costly normalization of timezone to 'Z' time. return internalCompare(lhs, rhs); } else if (lhs.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && rhs.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { // Both instances have different timezones. // Normalize to UTC time and compare. lhs = (FEELXMLGregorianCalendar) lhs.normalize(); rhs = (FEELXMLGregorianCalendar) rhs.normalize(); return internalCompare(lhs, rhs); } else if (lhs.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { if (lhs.getTimezone() != 0) { lhs = (FEELXMLGregorianCalendar) lhs.normalize(); } // C. step 1 XMLGregorianCalendar minQ = rhs.normalizeToTimezone(MIN_OFFSET); result = internalCompare(lhs, minQ); if (result == DatatypeConstants.LESSER) { return result; } // C. step 2 XMLGregorianCalendar maxQ = rhs.normalizeToTimezone(MAX_OFFSET); result = internalCompare(lhs, maxQ); if (result == DatatypeConstants.GREATER) { return result; } else { // C. step 3 return DatatypeConstants.INDETERMINATE; } } else { // rhs.getTimezone() != DatatypeConstants.FIELD_UNDEFINED // lhs has no timezone and rhs does. if (rhs.getTimezone() != 0) { rhs = (FEELXMLGregorianCalendar) rhs.normalizeToTimezone(rhs.zoneID); } // D. step 1 XMLGregorianCalendar maxP = lhs.normalizeToTimezone(MAX_OFFSET); result = internalCompare(maxP, rhs); if (result == DatatypeConstants.LESSER) { return result; } // D. step 2 XMLGregorianCalendar minP = lhs.normalizeToTimezone(MIN_OFFSET); result = internalCompare(minP, rhs); if (result == DatatypeConstants.GREATER) { return result; } else { // D. step 3 return DatatypeConstants.INDETERMINATE; } } }
Example 15
Source File: DurationComparison.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * See JDK-5077522, Duration.compare returns equal for INDETERMINATE * comparisons */ public void testCompareWithInderterminateRelation() { final String [][] partialOrder = { // partialOrder {"P1Y", "<>", "P365D"}, {"P1Y", "<>", "P366D"}, {"P1M", "<>", "P28D"}, {"P1M", "<>", "P29D"}, {"P1M", "<>", "P30D"}, {"P1M", "<>", "P31D"}, {"P5M", "<>", "P150D"}, {"P5M", "<>", "P151D"}, {"P5M", "<>", "P152D"}, {"P5M", "<>", "P153D"}, {"PT2419200S", "<>", "P1M"}, {"PT2678400S", "<>", "P1M"}, {"PT31536000S", "<>", "P1Y"}, {"PT31622400S", "<>", "P1Y"}, {"PT525600M", "<>", "P1Y"}, {"PT527040M", "<>", "P1Y"}, {"PT8760H", "<>", "P1Y"}, {"PT8784H", "<>", "P1Y"}, {"P365D", "<>", "P1Y"}, }; DatatypeFactory df = null; try { df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException ex) { ex.printStackTrace(); fail(ex.toString()); } for (int valueIndex = 0; valueIndex < partialOrder.length; ++valueIndex) { Duration duration1 = df.newDuration(partialOrder[valueIndex][0]); Duration duration2 = df.newDuration(partialOrder[valueIndex][2]); int cmp = duration1.compare(duration2); int expected = ">".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.GREATER : "<".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.LESSER : "==".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.EQUAL : DatatypeConstants.INDETERMINATE; if (expected != cmp) { fail("returned " + cmp2str(cmp) + " for durations \'" + duration1 + "\' and " + duration2 + "\', but expected " + cmp2str(expected)); } else { success("Comparing " + duration1 + " and " + duration2 + ": INDETERMINATE"); } } }
Example 16
Source File: DurationTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Inspired by CR 5077522 Duration.compare makes mistakes for some values. */ @Test public void testCompareWithInderterminateRelation() { final String[][] partialOrder = { // partialOrder { "P1Y", "<>", "P365D" }, { "P1Y", "<>", "P366D" }, { "P1M", "<>", "P28D" }, { "P1M", "<>", "P29D" }, { "P1M", "<>", "P30D" }, { "P1M", "<>", "P31D" }, { "P5M", "<>", "P150D" }, { "P5M", "<>", "P151D" }, { "P5M", "<>", "P152D" }, { "P5M", "<>", "P153D" }, { "PT2419200S", "<>", "P1M" }, { "PT2678400S", "<>", "P1M" }, { "PT31536000S", "<>", "P1Y" }, { "PT31622400S", "<>", "P1Y" }, { "PT525600M", "<>", "P1Y" }, { "PT527040M", "<>", "P1Y" }, { "PT8760H", "<>", "P1Y" }, { "PT8784H", "<>", "P1Y" }, { "P365D", "<>", "P1Y" }, }; DatatypeFactory df = null; try { df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException ex) { ex.printStackTrace(); Assert.fail(ex.toString()); } boolean compareErrors = false; for (int valueIndex = 0; valueIndex < partialOrder.length; ++valueIndex) { Duration duration1 = df.newDuration(partialOrder[valueIndex][0]); Duration duration2 = df.newDuration(partialOrder[valueIndex][2]); int cmp = duration1.compare(duration2); int expected = ">".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.GREATER : "<".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.LESSER : "==".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.EQUAL : DatatypeConstants.INDETERMINATE; // just note any errors, do not fail until all cases have been // tested if (expected != cmp) { compareErrors = true; System.err.println("returned " + cmp2str(cmp) + " for durations \'" + duration1 + "\' and " + duration2 + "\', but expected " + cmp2str(expected)); } } if (compareErrors) { // TODO; fix bug, these tests should pass if (false) { Assert.fail("Errors in comparing indeterminate relations, see Stderr"); } else { System.err.println("Please fix this bug: " + "Errors in comparing indeterminate relations, see Stderr"); } } }
Example 17
Source File: XMLGregorianCalendarImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * <p>Compare two instances of W3C XML Schema 1.0 date/time datatypes * according to partial order relation defined in * <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">W3C XML Schema 1.0 Part 2, Section 3.2.7.3, * <i>Order relation on dateTime</i></a>.</p> * * <p><code>xsd:dateTime</code> datatype field mapping to accessors of * this class are defined in * <a href="#datetimefieldmapping">date/time field mapping table</a>.</p> * * @param rhs instance of <code>XMLGregorianCalendar</code> to compare * * @return the relationship between <code>lhs</code> and <code>rhs</code> as * {@link DatatypeConstants#LESSER}, * {@link DatatypeConstants#EQUAL}, * {@link DatatypeConstants#GREATER} or * {@link DatatypeConstants#INDETERMINATE}. * * @throws NullPointerException if <code>lhs</code> or <code>rhs</code> * parameters are null. */ public int compare(XMLGregorianCalendar rhs) { XMLGregorianCalendar lhs = this; int result = DatatypeConstants.INDETERMINATE; XMLGregorianCalendarImpl P = (XMLGregorianCalendarImpl) lhs; XMLGregorianCalendarImpl Q = (XMLGregorianCalendarImpl) rhs; if (P.getTimezone() == Q.getTimezone()) { // Optimization: // both instances are in same timezone or // both are FIELD_UNDEFINED. // Avoid costly normalization of timezone to 'Z' time. return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { // Both instances have different timezones. // Normalize to UTC time and compare. P = (XMLGregorianCalendarImpl) P.normalize(); Q = (XMLGregorianCalendarImpl) Q.normalize(); return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { if (P.getTimezone() != 0) { P = (XMLGregorianCalendarImpl) P.normalize(); } // C. step 1 XMLGregorianCalendar MinQ = Q.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(P, MinQ); if (result == DatatypeConstants.LESSER) { return result; } // C. step 2 XMLGregorianCalendar MaxQ = Q.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(P, MaxQ); if (result == DatatypeConstants.GREATER) { return result; } else { // C. step 3 return DatatypeConstants.INDETERMINATE; } } else { // Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED // P has no timezone and Q does. if (Q.getTimezone() != 0) { Q = (XMLGregorianCalendarImpl) Q.normalizeToTimezone(Q.getTimezone()); } // D. step 1 XMLGregorianCalendar MaxP = P.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(MaxP, Q); if (result == DatatypeConstants.LESSER) { return result; } // D. step 2 XMLGregorianCalendar MinP = P.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(MinP, Q); if (result == DatatypeConstants.GREATER) { return result; } else { // D. step 3 return DatatypeConstants.INDETERMINATE; } } }
Example 18
Source File: XMLGregorianCalendarImpl.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * <p>Compare two instances of W3C XML Schema 1.0 date/time datatypes * according to partial order relation defined in * <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">W3C XML Schema 1.0 Part 2, Section 3.2.7.3, * <i>Order relation on dateTime</i></a>.</p> * * <p><code>xsd:dateTime</code> datatype field mapping to accessors of * this class are defined in * <a href="#datetimefieldmapping">date/time field mapping table</a>.</p> * * @param rhs instance of <code>XMLGregorianCalendar</code> to compare * * @return the relationship between <code>lhs</code> and <code>rhs</code> as * {@link DatatypeConstants#LESSER}, * {@link DatatypeConstants#EQUAL}, * {@link DatatypeConstants#GREATER} or * {@link DatatypeConstants#INDETERMINATE}. * * @throws NullPointerException if <code>lhs</code> or <code>rhs</code> * parameters are null. */ public int compare(XMLGregorianCalendar rhs) { XMLGregorianCalendar lhs = this; int result = DatatypeConstants.INDETERMINATE; XMLGregorianCalendarImpl P = (XMLGregorianCalendarImpl) lhs; XMLGregorianCalendarImpl Q = (XMLGregorianCalendarImpl) rhs; if (P.getTimezone() == Q.getTimezone()) { // Optimization: // both instances are in same timezone or // both are FIELD_UNDEFINED. // Avoid costly normalization of timezone to 'Z' time. return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { // Both instances have different timezones. // Normalize to UTC time and compare. P = (XMLGregorianCalendarImpl) P.normalize(); Q = (XMLGregorianCalendarImpl) Q.normalize(); return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { if (P.getTimezone() != 0) { P = (XMLGregorianCalendarImpl) P.normalize(); } // C. step 1 XMLGregorianCalendar MinQ = Q.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(P, MinQ); if (result == DatatypeConstants.LESSER) { return result; } // C. step 2 XMLGregorianCalendar MaxQ = Q.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(P, MaxQ); if (result == DatatypeConstants.GREATER) { return result; } else { // C. step 3 return DatatypeConstants.INDETERMINATE; } } else { // Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED // P has no timezone and Q does. if (Q.getTimezone() != 0) { Q = (XMLGregorianCalendarImpl) Q.normalizeToTimezone(Q.getTimezone()); } // D. step 1 XMLGregorianCalendar MaxP = P.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(MaxP, Q); if (result == DatatypeConstants.LESSER) { return result; } // D. step 2 XMLGregorianCalendar MinP = P.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(MinP, Q); if (result == DatatypeConstants.GREATER) { return result; } else { // D. step 3 return DatatypeConstants.INDETERMINATE; } } }
Example 19
Source File: XMLGregorianCalendarImpl.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * <p>Compare two instances of W3C XML Schema 1.0 date/time datatypes * according to partial order relation defined in * <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">W3C XML Schema 1.0 Part 2, Section 3.2.7.3, * <i>Order relation on dateTime</i></a>.</p> * * <p><code>xsd:dateTime</code> datatype field mapping to accessors of * this class are defined in * <a href="#datetimefieldmapping">date/time field mapping table</a>.</p> * * @param rhs instance of <code>XMLGregorianCalendar</code> to compare * * @return the relationship between <code>lhs</code> and <code>rhs</code> as * {@link DatatypeConstants#LESSER}, * {@link DatatypeConstants#EQUAL}, * {@link DatatypeConstants#GREATER} or * {@link DatatypeConstants#INDETERMINATE}. * * @throws NullPointerException if <code>lhs</code> or <code>rhs</code> * parameters are null. */ public int compare(XMLGregorianCalendar rhs) { XMLGregorianCalendar lhs = this; int result = DatatypeConstants.INDETERMINATE; XMLGregorianCalendarImpl P = (XMLGregorianCalendarImpl) lhs; XMLGregorianCalendarImpl Q = (XMLGregorianCalendarImpl) rhs; if (P.getTimezone() == Q.getTimezone()) { // Optimization: // both instances are in same timezone or // both are FIELD_UNDEFINED. // Avoid costly normalization of timezone to 'Z' time. return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { // Both instances have different timezones. // Normalize to UTC time and compare. P = (XMLGregorianCalendarImpl) P.normalize(); Q = (XMLGregorianCalendarImpl) Q.normalize(); return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { if (P.getTimezone() != 0) { P = (XMLGregorianCalendarImpl) P.normalize(); } // C. step 1 XMLGregorianCalendar MinQ = Q.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(P, MinQ); if (result == DatatypeConstants.LESSER) { return result; } // C. step 2 XMLGregorianCalendar MaxQ = Q.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(P, MaxQ); if (result == DatatypeConstants.GREATER) { return result; } else { // C. step 3 return DatatypeConstants.INDETERMINATE; } } else { // Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED // P has no timezone and Q does. if (Q.getTimezone() != 0) { Q = (XMLGregorianCalendarImpl) Q.normalizeToTimezone(Q.getTimezone()); } // D. step 1 XMLGregorianCalendar MaxP = P.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(MaxP, Q); if (result == DatatypeConstants.LESSER) { return result; } // D. step 2 XMLGregorianCalendar MinP = P.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(MinP, Q); if (result == DatatypeConstants.GREATER) { return result; } else { // D. step 3 return DatatypeConstants.INDETERMINATE; } } }
Example 20
Source File: XMLGregorianCalendarImpl.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * <p>Compare two instances of W3C XML Schema 1.0 date/time datatypes * according to partial order relation defined in * <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">W3C XML Schema 1.0 Part 2, Section 3.2.7.3, * <i>Order relation on dateTime</i></a>.</p> * * <p><code>xsd:dateTime</code> datatype field mapping to accessors of * this class are defined in * <a href="#datetimefieldmapping">date/time field mapping table</a>.</p> * * @param rhs instance of <code>XMLGregorianCalendar</code> to compare * * @return the relationship between <code>lhs</code> and <code>rhs</code> as * {@link DatatypeConstants#LESSER}, * {@link DatatypeConstants#EQUAL}, * {@link DatatypeConstants#GREATER} or * {@link DatatypeConstants#INDETERMINATE}. * * @throws NullPointerException if <code>lhs</code> or <code>rhs</code> * parameters are null. */ public int compare(XMLGregorianCalendar rhs) { XMLGregorianCalendar lhs = this; int result = DatatypeConstants.INDETERMINATE; XMLGregorianCalendarImpl P = (XMLGregorianCalendarImpl) lhs; XMLGregorianCalendarImpl Q = (XMLGregorianCalendarImpl) rhs; if (P.getTimezone() == Q.getTimezone()) { // Optimization: // both instances are in same timezone or // both are FIELD_UNDEFINED. // Avoid costly normalization of timezone to 'Z' time. return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED && Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { // Both instances have different timezones. // Normalize to UTC time and compare. P = (XMLGregorianCalendarImpl) P.normalize(); Q = (XMLGregorianCalendarImpl) Q.normalize(); return internalCompare(P, Q); } else if (P.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) { if (P.getTimezone() != 0) { P = (XMLGregorianCalendarImpl) P.normalize(); } // C. step 1 XMLGregorianCalendar MinQ = Q.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(P, MinQ); if (result == DatatypeConstants.LESSER) { return result; } // C. step 2 XMLGregorianCalendar MaxQ = Q.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(P, MaxQ); if (result == DatatypeConstants.GREATER) { return result; } else { // C. step 3 return DatatypeConstants.INDETERMINATE; } } else { // Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED // P has no timezone and Q does. if (Q.getTimezone() != 0) { Q = (XMLGregorianCalendarImpl) Q.normalizeToTimezone(Q.getTimezone()); } // D. step 1 XMLGregorianCalendar MaxP = P.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET); result = internalCompare(MaxP, Q); if (result == DatatypeConstants.LESSER) { return result; } // D. step 2 XMLGregorianCalendar MinP = P.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET); result = internalCompare(MinP, Q); if (result == DatatypeConstants.GREATER) { return result; } else { // D. step 3 return DatatypeConstants.INDETERMINATE; } } }