XMLDatatypeUtil { public static int compare(String value1, String value2, IRI datatype) { if (datatype.equals(XSD.DECIMAL)) { return compareDecimals(value1, value2); } else if (datatype.equals(XSD.INTEGER)) { return compareIntegers(value1, value2); } else if (datatype.equals(XSD.NEGATIVE_INTEGER)) { return compareNegativeIntegers(value1, value2); } else if (datatype.equals(XSD.NON_POSITIVE_INTEGER)) { return compareNonPositiveIntegers(value1, value2); } else if (datatype.equals(XSD.NON_NEGATIVE_INTEGER)) { return compareNonNegativeIntegers(value1, value2); } else if (datatype.equals(XSD.POSITIVE_INTEGER)) { return comparePositiveIntegers(value1, value2); } else if (datatype.equals(XSD.LONG)) { return compareLongs(value1, value2); } else if (datatype.equals(XSD.INT)) { return compareInts(value1, value2); } else if (datatype.equals(XSD.SHORT)) { return compareShorts(value1, value2); } else if (datatype.equals(XSD.BYTE)) { return compareBytes(value1, value2); } else if (datatype.equals(XSD.UNSIGNED_LONG)) { return compareUnsignedLongs(value1, value2); } else if (datatype.equals(XSD.UNSIGNED_INT)) { return compareUnsignedInts(value1, value2); } else if (datatype.equals(XSD.UNSIGNED_SHORT)) { return compareUnsignedShorts(value1, value2); } else if (datatype.equals(XSD.UNSIGNED_BYTE)) { return compareUnsignedBytes(value1, value2); } else if (datatype.equals(XSD.FLOAT)) { return compareFloats(value1, value2); } else if (datatype.equals(XSD.DOUBLE)) { return compareDoubles(value1, value2); } else if (datatype.equals(XSD.DATETIME) || datatype.equals(XSD.DATETIMESTAMP)) { return compareDateTime(value1, value2); } else { throw new IllegalArgumentException("datatype is not ordered"); } }  static boolean isPrimitiveDatatype(IRI datatype); static boolean isDerivedDatatype(IRI datatype); static boolean isBuiltInDatatype(IRI datatype); static boolean isNumericDatatype(IRI datatype); static boolean isDecimalDatatype(IRI datatype); static boolean isIntegerDatatype(IRI datatype); static boolean isFloatingPointDatatype(IRI datatype); static boolean isCalendarDatatype(IRI datatype); static boolean isDurationDatatype(IRI datatype); static boolean isOrderedDatatype(IRI datatype); static boolean isValidValue(String value, IRI datatype); static boolean isValidDecimal(String value); static boolean isValidInteger(String value); static boolean isValidNegativeInteger(String value); static boolean isValidNonPositiveInteger(String value); static boolean isValidNonNegativeInteger(String value); static boolean isValidPositiveInteger(String value); static boolean isValidLong(String value); static boolean isValidInt(String value); static boolean isValidShort(String value); static boolean isValidByte(String value); static boolean isValidUnsignedLong(String value); static boolean isValidUnsignedInt(String value); static boolean isValidUnsignedShort(String value); static boolean isValidUnsignedByte(String value); static boolean isValidFloat(String value); static boolean isValidDouble(String value); static boolean isValidBoolean(String value); static boolean isValidDuration(String value); static boolean isValidDayTimeDuration(String value); static boolean isValidYearMonthDuration(String value); static boolean isValidDateTime(String value); static boolean isValidDateTimeStamp(String value); static boolean isValidDate(String value); static boolean isValidTime(String value); static boolean isValidGDay(String value); static boolean isValidGMonth(String value); static boolean isValidGMonthDay(String value); static boolean isValidGYear(String value); static boolean isValidGYearMonth(String value); static boolean isValidQName(String value); static boolean isValidAnyURI(String value); static String normalize(String value, IRI datatype); static String normalizeBoolean(String value); static String normalizeDecimal(String decimal); static String normalizeInteger(String value); static String normalizeNegativeInteger(String value); static String normalizeNonPositiveInteger(String value); static String normalizeNonNegativeInteger(String value); static String normalizePositiveInteger(String value); static String normalizeLong(String value); static String normalizeInt(String value); static String normalizeShort(String value); static String normalizeByte(String value); static String normalizeUnsignedLong(String value); static String normalizeUnsignedInt(String value); static String normalizeUnsignedShort(String value); static String normalizeUnsignedByte(String value); static String normalizeFloat(String value); static String normalizeDouble(String value); static String normalizeFPNumber(String value); static String normalizeDateTime(String value); static String collapseWhiteSpace(String s); static int compare(String value1, String value2, IRI datatype); static int compareDecimals(String dec1, String dec2); static int compareCanonicalDecimals(String dec1, String dec2); static int compareIntegers(String int1, String int2); static int compareCanonicalIntegers(String int1, String int2); static int compareNegativeIntegers(String int1, String int2); static int compareNonPositiveIntegers(String int1, String int2); static int compareNonNegativeIntegers(String int1, String int2); static int comparePositiveIntegers(String int1, String int2); static int compareLongs(String int1, String int2); static int compareInts(String int1, String int2); static int compareShorts(String int1, String int2); static int compareBytes(String int1, String int2); static int compareUnsignedLongs(String int1, String int2); static int compareUnsignedInts(String int1, String int2); static int compareUnsignedShorts(String int1, String int2); static int compareUnsignedBytes(String int1, String int2); static int compareFloats(String float1, String float2); static int compareCanonicalFloats(String float1, String float2); static int compareDoubles(String double1, String double2); static int compareCanonicalDoubles(String double1, String double2); static int compareFPNumbers(String fp1, String fp2); static int compareCanonicalFPNumbers(String float1, String float2); static int compareDateTime(String value1, String value2); static boolean parseBoolean(String s); static byte parseByte(String s); static short parseShort(String s); static int parseInt(String s); static long parseLong(String s); static float parseFloat(String s); static double parseDouble(String s); static BigInteger parseInteger(String s); static BigDecimal parseDecimal(String s); static XMLGregorianCalendar parseCalendar(String s); static Duration parseDuration(String s); static IRI qnameToURI(QName qname); static String toString(Number value); static final String POSITIVE_INFINITY; static final String NEGATIVE_INFINITY; static final String NaN; }
@Test public void testCompareDateTimeStamp() { int sameOffset = XMLDatatypeUtil.compare("2019-12-06T00:00:00Z", "2019-12-06T00:00:00+00:00", XSD.DATETIMESTAMP); assertTrue("Not the same", sameOffset == 0); int offset1 = XMLDatatypeUtil.compare("2019-12-06T14:00:00+02:00", "2019-12-06T13:00:00+02:00", XSD.DATETIMESTAMP); assertTrue("Wrong order", offset1 > 0); int offset2 = XMLDatatypeUtil.compare("2019-12-06T12:00:00+02:00", "2019-12-06T13:00:00-04:00", XSD.DATETIMESTAMP); assertTrue("Wrong order", offset2 < 0); }