Class XMLDatatypeUtil
- java.lang.Object
-
- org.eclipse.rdf4j.model.datatypes.XMLDatatypeUtil
-
public class XMLDatatypeUtil extends Object
Provides methods for handling the standard XML Schema datatypes.- Author:
- Arjohn Kampman
-
-
Field Summary
Fields Modifier and Type Field Description static StringNaNstatic StringNEGATIVE_INFINITYstatic StringPOSITIVE_INFINITY
-
Constructor Summary
Constructors Constructor Description XMLDatatypeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcollapseWhiteSpace(String s)Replaces all contiguous sequences of #x9 (tab), #xA (line feed) and #xD (carriage return) with a single #x20 (space) character, and removes any leading and trailing whitespace characters, as specified for whiteSpace facet collapse.static intcompare(String value1, String value2, IRI datatype)static intcompareBytes(String int1, String int2)static intcompareCanonicalDecimals(String dec1, String dec2)Compares two canonical decimals to each other.static intcompareCanonicalDoubles(String double1, String double2)Compares two canonical doubles to eachother.static intcompareCanonicalFloats(String float1, String float2)Compares two canonical floats to each other.static intcompareCanonicalFPNumbers(String float1, String float2)Compares two canonical floating point numbers to each other.static intcompareCanonicalIntegers(String int1, String int2)Compares two canonical integers to each other.static intcompareDateTime(String value1, String value2)Compares two dateTime objects.static intcompareDecimals(String dec1, String dec2)Compares two decimals to eachother.static intcompareDoubles(String double1, String double2)Compares two doubles to each other.static intcompareFloats(String float1, String float2)Compares two floats to each other.static intcompareFPNumbers(String fp1, String fp2)Compares two floating point numbers to eachother.static intcompareIntegers(String int1, String int2)Compares two integers to each other.static intcompareInts(String int1, String int2)static intcompareLongs(String int1, String int2)static intcompareNegativeIntegers(String int1, String int2)static intcompareNonNegativeIntegers(String int1, String int2)static intcompareNonPositiveIntegers(String int1, String int2)static intcomparePositiveIntegers(String int1, String int2)static intcompareShorts(String int1, String int2)static intcompareUnsignedBytes(String int1, String int2)static intcompareUnsignedInts(String int1, String int2)static intcompareUnsignedLongs(String int1, String int2)static intcompareUnsignedShorts(String int1, String int2)static booleanisBuiltInDatatype(IRI datatype)Checks whether the supplied datatype is a built-in XML Schema datatype.static booleanisCalendarDatatype(IRI datatype)Checks whether the supplied datatype is equal to xsd:dateTime, xsd:date, xsd:time, xsd:gYearMonth, xsd:gMonthDay, xsd:gYear, xsd:gMonth or xsd:gDay.These are the primitive datatypes that represent dates and/or times.static booleanisDecimalDatatype(IRI datatype)Checks whether the supplied datatype is equal to xsd:decimal or one of the built-in datatypes that is derived from xsd:decimal.static booleanisDerivedDatatype(IRI datatype)Checks whether the supplied datatype is a derived XML Schema datatype.static booleanisDurationDatatype(IRI datatype)Checks whether the supplied datatype is equal to xsd:duration, xsd:dayTimeDuration, xsd:yearMonthDuration.static booleanisFloatingPointDatatype(IRI datatype)Checks whether the supplied datatype is equal to xsd:float or xsd:double.static booleanisIntegerDatatype(IRI datatype)Checks whether the supplied datatype is equal to xsd:integer or one of the built-in datatypes that is derived from xsd:integer.static booleanisNumericDatatype(IRI datatype)Checks whether the supplied datatype is a numeric datatype, i.e.if it is equal to xsd:float, xsd:double, xsd:decimal or one of the datatypes derived from xsd:decimal.static booleanisOrderedDatatype(IRI datatype)Checks whether the supplied datatype is ordered.The values of an ordered datatype can be compared to each other using operators like < and >.static booleanisPrimitiveDatatype(IRI datatype)Checks whether the supplied datatype is a primitive XML Schema datatype.static booleanisValidAnyURI(String value)Determines if the supplied value is an Internationalized Resource Identifier Reference (IRI).static booleanisValidBoolean(String value)Verifies if the supplied lexical value is a valid boolean or not.static booleanisValidByte(String value)Verifies if the supplied lexical value is a valid byte or not.static booleanisValidDate(String value)Determines if the supplied value is a valid xsd:date string.static booleanisValidDateTime(String value)Verifies if the supplied lexical value is a valid date-time.static booleanisValidDateTimeStamp(String value)Verifies if the supplied lexical value is a valid date-timestamp.static booleanisValidDayTimeDuration(String value)Verifies if the supplied lexical value is a valid day-time duration ot not.static booleanisValidDecimal(String value)Verifies if the supplied lexical value is a valid decimal or not.static booleanisValidDouble(String value)Verifies if the supplied lexical value is a valid double or not.static booleanisValidDuration(String value)Verifies if the supplied lexical value is a valid duration.static booleanisValidFloat(String value)Verifies if the supplied lexical value is a valid float or not.static booleanisValidGDay(String value)Determines if the supplied value is a valid xsd:gDay string.static booleanisValidGMonth(String value)Determines if the supplied value is a valid xsd:gMonth string.static booleanisValidGMonthDay(String value)Determines if the supplied value is a valid xsd:gMonthDay string.static booleanisValidGYear(String value)Determines if the supplied value is a valid xsd:gYear string.static booleanisValidGYearMonth(String value)Determines if the supplied value is a valid xsd:gYearMonth string.static booleanisValidInt(String value)Verifies if the supplied lexical value is a valid integer or not.static booleanisValidInteger(String value)Verifies if the supplied lexical value is a valid integer or not.static booleanisValidLong(String value)Verifies if the supplied lexical value is a valid long or not.static booleanisValidNegativeInteger(String value)Verifies if the supplied lexical value is a valid negative integer or not.static booleanisValidNonNegativeInteger(String value)Verifies if the supplied lexical value is a valid non-negative integer or not.static booleanisValidNonPositiveInteger(String value)Verifies if the supplied lexical value is a valid non-positive integer or not.static booleanisValidPositiveInteger(String value)Verifies if the supplied lexical value is a valid positive integer or not.static booleanisValidQName(String value)Determines if the supplied value is a valid xsd:QName string.static booleanisValidShort(String value)Verifies if the supplied lexical value is a valid short or not.static booleanisValidTime(String value)Determines if the supplied value is a valid xsd:time string.static booleanisValidUnsignedByte(String value)Verifies if the supplied lexical value is a valid unsigned byte or not.static booleanisValidUnsignedInt(String value)Verifies if the supplied lexical value is a valid unsigned int.static booleanisValidUnsignedLong(String value)Verifies if the supplied lexical value is a valid unsigned long or not.static booleanisValidUnsignedShort(String value)Verifies if the supplied lexical value is a valid unsigned short or not.static booleanisValidValue(String value, CoreDatatype datatype)static booleanisValidValue(String value, CoreDatatype.XSD datatype)static booleanisValidValue(String value, IRI datatype)Verifies if the supplied lexical value is valid for the given datatype.static booleanisValidYearMonthDuration(String value)Verifies if the supplied lexical value is a valid year-month duration.static Stringnormalize(String value, CoreDatatype.XSD datatype)static Stringnormalize(String value, IRI datatype)Normalizes the supplied value according to the normalization rules for the supplied datatype.static StringnormalizeBoolean(String value)Normalizes a boolean value to its canonical representation.static StringnormalizeByte(String value)Normalizes an xsd:byte.static StringnormalizeDateTime(String value)Normalizes an xsd:dateTime.static StringnormalizeDecimal(String decimal)Normalizes a decimal to its canonical representation.static StringnormalizeDouble(String value)Normalizes a double to its canonical representation.static StringnormalizeFloat(String value)Normalizes a float to its canonical representation.static StringnormalizeFPNumber(String value)Normalizes a floating point number to its canonical representation.static StringnormalizeInt(String value)Normalizes an xsd:int.static StringnormalizeInteger(String value)Normalizes an integer to its canonical representation.static StringnormalizeLong(String value)Normalizes an xsd:long.static StringnormalizeNegativeInteger(String value)Normalizes an xsd:negativeInteger.static StringnormalizeNonNegativeInteger(String value)Normalizes an xsd:nonNegativeInteger.static StringnormalizeNonPositiveInteger(String value)Normalizes an xsd:nonPositiveInteger.static StringnormalizePositiveInteger(String value)Normalizes an xsd:positiveInteger.static StringnormalizeShort(String value)Normalizes an xsd:short.static StringnormalizeUnsignedByte(String value)Normalizes an xsd:unsignedByte.static StringnormalizeUnsignedInt(String value)Normalizes an xsd:unsignedInt.static StringnormalizeUnsignedLong(String value)Normalizes an xsd:unsignedLong.static StringnormalizeUnsignedShort(String value)Normalizes an xsd:unsignedShort.static booleanparseBoolean(String s)Parses the supplied xsd:boolean string and returns its value.static byteparseByte(String s)Parses the supplied xsd:byte string and returns its value.static XMLGregorianCalendarparseCalendar(String s)Parses the supplied calendar value string and returns its value.static BigDecimalparseDecimal(String s)Parses the supplied decimal/floating point string and returns its value.static doubleparseDouble(String s)Parses the supplied xsd:double string and returns its value.static DurationparseDuration(String s)Parses the supplied xsd:duration value string and returns its value.static floatparseFloat(String s)Parses the supplied xsd:float string and returns its value.static intparseInt(String s)Parses the supplied xsd:int strings and returns its value.static BigIntegerparseInteger(String s)Parses the supplied xsd:integer string and returns its value.static longparseLong(String s)Parses the supplied xsd:long string and returns its value.static shortparseShort(String s)Parses the supplied xsd:short string and returns its value.static CoreDatatype.XSDqnameToCoreDatatype(QName qname)static IRIqnameToURI(QName qname)Maps a datatype QName from the javax.xml.namespace package to an XML Schema 1.0 URI for the corresponding datatype.static StringtoString(Number value)
-
-
-
Field Detail
-
POSITIVE_INFINITY
public static final String POSITIVE_INFINITY
- See Also:
- Constant Field Values
-
NEGATIVE_INFINITY
public static final String NEGATIVE_INFINITY
- See Also:
- Constant Field Values
-
NaN
public static final String NaN
- See Also:
- Constant Field Values
-
-
Method Detail
-
isPrimitiveDatatype
public static boolean isPrimitiveDatatype(IRI datatype)
Checks whether the supplied datatype is a primitive XML Schema datatype.- Parameters:
datatype-- Returns:
- true if the datatype is a primitive type
-
isDerivedDatatype
public static boolean isDerivedDatatype(IRI datatype)
Checks whether the supplied datatype is a derived XML Schema datatype.- Parameters:
datatype-- Returns:
- true if the datatype is a derived type
-
isBuiltInDatatype
public static boolean isBuiltInDatatype(IRI datatype)
Checks whether the supplied datatype is a built-in XML Schema datatype.- Parameters:
datatype-- Returns:
- true if it is a primitive or derived XML Schema type
-
isNumericDatatype
public static boolean isNumericDatatype(IRI datatype)
Checks whether the supplied datatype is a numeric datatype, i.e.if it is equal to xsd:float, xsd:double, xsd:decimal or one of the datatypes derived from xsd:decimal.- Parameters:
datatype-- Returns:
- true of it is a decimal or floating point type
-
isDecimalDatatype
public static boolean isDecimalDatatype(IRI datatype)
Checks whether the supplied datatype is equal to xsd:decimal or one of the built-in datatypes that is derived from xsd:decimal.- Parameters:
datatype-- Returns:
- true if it is a decimal datatype
-
isIntegerDatatype
public static boolean isIntegerDatatype(IRI datatype)
Checks whether the supplied datatype is equal to xsd:integer or one of the built-in datatypes that is derived from xsd:integer.- Parameters:
datatype-- Returns:
- true if it is an integer type
-
isFloatingPointDatatype
public static boolean isFloatingPointDatatype(IRI datatype)
Checks whether the supplied datatype is equal to xsd:float or xsd:double.- Parameters:
datatype-- Returns:
- true if it is a floating point type
-
isCalendarDatatype
public static boolean isCalendarDatatype(IRI datatype)
Checks whether the supplied datatype is equal to xsd:dateTime, xsd:date, xsd:time, xsd:gYearMonth, xsd:gMonthDay, xsd:gYear, xsd:gMonth or xsd:gDay.These are the primitive datatypes that represent dates and/or times.- Parameters:
datatype-- Returns:
- true if it is a calendar type
- See Also:
XMLGregorianCalendar
-
isDurationDatatype
public static boolean isDurationDatatype(IRI datatype)
Checks whether the supplied datatype is equal to xsd:duration, xsd:dayTimeDuration, xsd:yearMonthDuration. These are the datatypes that represents durations.- Parameters:
datatype-- Returns:
- true if it is a duration type
- See Also:
Duration
-
isOrderedDatatype
public static boolean isOrderedDatatype(IRI datatype)
Checks whether the supplied datatype is ordered.The values of an ordered datatype can be compared to each other using operators like < and >.- Parameters:
datatype-- Returns:
- true if the datatype is ordered
-
isValidValue
public static boolean isValidValue(String value, IRI datatype)
Verifies if the supplied lexical value is valid for the given datatype.- Parameters:
value- a lexical valuedatatype- an XML Schema datatatype.- Returns:
- true if the supplied lexical value is valid, false otherwise.
-
isValidValue
public static boolean isValidValue(String value, CoreDatatype datatype)
-
isValidValue
public static boolean isValidValue(String value, CoreDatatype.XSD datatype)
-
isValidDecimal
public static boolean isValidDecimal(String value)
Verifies if the supplied lexical value is a valid decimal or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidInteger
public static boolean isValidInteger(String value)
Verifies if the supplied lexical value is a valid integer or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidNegativeInteger
public static boolean isValidNegativeInteger(String value)
Verifies if the supplied lexical value is a valid negative integer or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidNonPositiveInteger
public static boolean isValidNonPositiveInteger(String value)
Verifies if the supplied lexical value is a valid non-positive integer or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidNonNegativeInteger
public static boolean isValidNonNegativeInteger(String value)
Verifies if the supplied lexical value is a valid non-negative integer or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidPositiveInteger
public static boolean isValidPositiveInteger(String value)
Verifies if the supplied lexical value is a valid positive integer or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidLong
public static boolean isValidLong(String value)
Verifies if the supplied lexical value is a valid long or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidInt
public static boolean isValidInt(String value)
Verifies if the supplied lexical value is a valid integer or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidShort
public static boolean isValidShort(String value)
Verifies if the supplied lexical value is a valid short or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidByte
public static boolean isValidByte(String value)
Verifies if the supplied lexical value is a valid byte or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidUnsignedLong
public static boolean isValidUnsignedLong(String value)
Verifies if the supplied lexical value is a valid unsigned long or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidUnsignedInt
public static boolean isValidUnsignedInt(String value)
Verifies if the supplied lexical value is a valid unsigned int.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidUnsignedShort
public static boolean isValidUnsignedShort(String value)
Verifies if the supplied lexical value is a valid unsigned short or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidUnsignedByte
public static boolean isValidUnsignedByte(String value)
Verifies if the supplied lexical value is a valid unsigned byte or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidFloat
public static boolean isValidFloat(String value)
Verifies if the supplied lexical value is a valid float or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidDouble
public static boolean isValidDouble(String value)
Verifies if the supplied lexical value is a valid double or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidBoolean
public static boolean isValidBoolean(String value)
Verifies if the supplied lexical value is a valid boolean or not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidDuration
public static boolean isValidDuration(String value)
Verifies if the supplied lexical value is a valid duration.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidDayTimeDuration
public static boolean isValidDayTimeDuration(String value)
Verifies if the supplied lexical value is a valid day-time duration ot not.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidYearMonthDuration
public static boolean isValidYearMonthDuration(String value)
Verifies if the supplied lexical value is a valid year-month duration.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidDateTime
public static boolean isValidDateTime(String value)
Verifies if the supplied lexical value is a valid date-time.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidDateTimeStamp
public static boolean isValidDateTimeStamp(String value)
Verifies if the supplied lexical value is a valid date-timestamp.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidDate
public static boolean isValidDate(String value)
Determines if the supplied value is a valid xsd:date string.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidTime
public static boolean isValidTime(String value)
Determines if the supplied value is a valid xsd:time string.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidGDay
public static boolean isValidGDay(String value)
Determines if the supplied value is a valid xsd:gDay string.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidGMonth
public static boolean isValidGMonth(String value)
Determines if the supplied value is a valid xsd:gMonth string.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidGMonthDay
public static boolean isValidGMonthDay(String value)
Determines if the supplied value is a valid xsd:gMonthDay string.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidGYear
public static boolean isValidGYear(String value)
Determines if the supplied value is a valid xsd:gYear string.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidGYearMonth
public static boolean isValidGYearMonth(String value)
Determines if the supplied value is a valid xsd:gYearMonth string.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidQName
public static boolean isValidQName(String value)
Determines if the supplied value is a valid xsd:QName string. Note that this method only checks for syntax errors in the supplied string itself. It does not validate that the prefix is a declared and in-scope namespace prefix.- Parameters:
value-- Returns:
- true if valid, false otherwise
-
isValidAnyURI
public static boolean isValidAnyURI(String value)
Determines if the supplied value is an Internationalized Resource Identifier Reference (IRI). An anyURI value can be absolute or relative, and may have an optional fragment identifier (i.e., it may be an IRI Reference). This type should be used when the value fulfills the role of an IRI, as defined in [RFC 3987] or its successor(s) in the IETF Standards Track.- Parameters:
value-- Returns:
- true if a valid IRI, false otherwise
-
normalize
public static String normalize(String value, IRI datatype)
Normalizes the supplied value according to the normalization rules for the supplied datatype.- Parameters:
value- The value to normalize.datatype- The value's datatype.- Returns:
- The normalized value if there are any (supported) normalization rules for the supplied datatype, or the original supplied value otherwise.
- Throws:
IllegalArgumentException- If the supplied value is illegal considering the supplied datatype.
-
normalize
public static String normalize(String value, CoreDatatype.XSD datatype)
-
normalizeBoolean
public static String normalizeBoolean(String value)
Normalizes a boolean value to its canonical representation. More specifically, the values 1 and 0 will be normalized to the canonical values true and false, respectively. Supplied canonical values will remain as is.- Parameters:
value- The boolean value to normalize.- Returns:
- The normalized value.
- Throws:
IllegalArgumentException- If the supplied value is not a legal boolean.
-
normalizeDecimal
public static String normalizeDecimal(String decimal)
Normalizes a decimal to its canonical representation. For example: 120 becomes 120.0, +.3 becomes 0.3, 00012.45000 becomes 12.45 and -.0 becomes 0.0.- Parameters:
decimal- The decimal to normalize.- Returns:
- The canonical representation of decimal.
- Throws:
IllegalArgumentException- If one of the supplied strings is not a legal decimal.
-
normalizeInteger
public static String normalizeInteger(String value)
Normalizes an integer to its canonical representation. For example: +120 becomes 120 and 00012 becomes 12.- Parameters:
value- The value to normalize.- Returns:
- The canonical representation of value.
- Throws:
IllegalArgumentException- If the supplied value is not a legal integer.
-
normalizeNegativeInteger
public static String normalizeNegativeInteger(String value)
Normalizes an xsd:negativeInteger.
-
normalizeNonPositiveInteger
public static String normalizeNonPositiveInteger(String value)
Normalizes an xsd:nonPositiveInteger.
-
normalizeNonNegativeInteger
public static String normalizeNonNegativeInteger(String value)
Normalizes an xsd:nonNegativeInteger.
-
normalizePositiveInteger
public static String normalizePositiveInteger(String value)
Normalizes an xsd:positiveInteger.
-
normalizeUnsignedLong
public static String normalizeUnsignedLong(String value)
Normalizes an xsd:unsignedLong.
-
normalizeUnsignedInt
public static String normalizeUnsignedInt(String value)
Normalizes an xsd:unsignedInt.
-
normalizeUnsignedShort
public static String normalizeUnsignedShort(String value)
Normalizes an xsd:unsignedShort.
-
normalizeUnsignedByte
public static String normalizeUnsignedByte(String value)
Normalizes an xsd:unsignedByte.
-
normalizeFloat
public static String normalizeFloat(String value)
Normalizes a float to its canonical representation.- Parameters:
value- The value to normalize.- Returns:
- The canonical representation of value.
- Throws:
IllegalArgumentException- If the supplied value is not a legal float.
-
normalizeDouble
public static String normalizeDouble(String value)
Normalizes a double to its canonical representation.- Parameters:
value- The value to normalize.- Returns:
- The canonical representation of value.
- Throws:
IllegalArgumentException- If the supplied value is not a legal double.
-
normalizeFPNumber
public static String normalizeFPNumber(String value)
Normalizes a floating point number to its canonical representation.- Parameters:
value- The value to normalize.- Returns:
- The canonical representation of value.
- Throws:
IllegalArgumentException- If the supplied value is not a legal floating point number.
-
normalizeDateTime
public static String normalizeDateTime(String value)
Normalizes an xsd:dateTime.- Parameters:
value- The value to normalize.- Returns:
- The normalized value.
- Throws:
IllegalArgumentException- If the supplied value is not a legal xsd:dateTime value.
-
collapseWhiteSpace
public static String collapseWhiteSpace(String s)
Replaces all contiguous sequences of #x9 (tab), #xA (line feed) and #xD (carriage return) with a single #x20 (space) character, and removes any leading and trailing whitespace characters, as specified for whiteSpace facet collapse.- Parameters:
s-- Returns:
- new string
-
compareDecimals
public static int compareDecimals(String dec1, String dec2)
Compares two decimals to eachother.- Parameters:
dec1-dec2-- Returns:
- A negative number if dec1 is smaller than dec2, 0 if they are equal, or positive (>0) if dec1 is larger than dec2.
- Throws:
IllegalArgumentException- If one of the supplied strings is not a legal decimal.
-
compareCanonicalDecimals
public static int compareCanonicalDecimals(String dec1, String dec2)
Compares two canonical decimals to each other.- Parameters:
dec1-dec2-- Returns:
- A negative number if dec1 is smaller than dec2, 0 if they are equal, or positive (>0) if dec1 is larger than dec2. The result is undefined when one or both of the arguments is not a canonical decimal.
- Throws:
IllegalArgumentException- If one of the supplied strings is not a legal decimal.
-
compareIntegers
public static int compareIntegers(String int1, String int2)
Compares two integers to each other.- Parameters:
int1-int2-- Returns:
- A negative number if int1 is smaller than int2, 0 if they are equal, or positive (>0) if int1 is larger than int2.
- Throws:
IllegalArgumentException- If one of the supplied strings is not a legal integer.
-
compareCanonicalIntegers
public static int compareCanonicalIntegers(String int1, String int2)
Compares two canonical integers to each other.- Parameters:
int1-int2-- Returns:
- A negative number if int1 is smaller than int2, 0 if they are equal, or positive (>0) if int1 is larger than int2. The result is undefined when one or both of the arguments is not a canonical integer.
- Throws:
IllegalArgumentException- If one of the supplied strings is not a legal integer.
-
compareFloats
public static int compareFloats(String float1, String float2)
Compares two floats to each other.- Parameters:
float1-float2-- Returns:
- A negative number if float1 is smaller than float2, 0 if they are equal, or positive (>0) if float1 is larger than float2.
- Throws:
IllegalArgumentException- If one of the supplied strings is not a legal float or if NaN is compared to a float other than NaN.
-
compareCanonicalFloats
public static int compareCanonicalFloats(String float1, String float2)
Compares two canonical floats to each other.- Parameters:
float1-float2-- Returns:
- A negative number if float1 is smaller than float2, 0 if they are equal, or positive (>0) if float1 is larger than float2. The result is undefined when one or both of the arguments is not a canonical float.
- Throws:
IllegalArgumentException- If one of the supplied strings is not a legal float or if NaN is compared to a float other than NaN.
-
compareDoubles
public static int compareDoubles(String double1, String double2)
Compares two doubles to each other.- Parameters:
double1-double2-- Returns:
- A negative number if double1 is smaller than double2, 0 if they are equal, or positive (>0) if double1 is larger than double2.
- Throws:
IllegalArgumentException- If one of the supplied strings is not a legal double or if NaN is compared to a double other than NaN.
-
compareCanonicalDoubles
public static int compareCanonicalDoubles(String double1, String double2)
Compares two canonical doubles to eachother.- Parameters:
double1-double2-- Returns:
- A negative number if double1 is smaller than double2, 0 if they are equal, or positive (>0) if double1 is larger than double2. The result is undefined when one or both of the arguments is not a canonical double.
- Throws:
IllegalArgumentException- If one of the supplied strings is not a legal double or if NaN is compared to a double other than NaN.
-
compareFPNumbers
public static int compareFPNumbers(String fp1, String fp2)
Compares two floating point numbers to eachother.- Parameters:
fp1-fp2-- Returns:
- A negative number if float1 is smaller than float2, 0 if they are equal, or positive (>0) if float1 is larger than float2. @throws IllegalArgumentException If one of the supplied strings is not a legal floating point number or if NaN is compared to a floating point number other than NaN.
-
compareCanonicalFPNumbers
public static int compareCanonicalFPNumbers(String float1, String float2)
Compares two canonical floating point numbers to each other.- Parameters:
float1-float2-- Returns:
- A negative number if float1 is smaller than float2, 0 if they are equal, or positive (>0) if float1 is larger than float2. The result is undefined when one or both of the arguments is not a canonical floating point number. @throws IllegalArgumentException If one of the supplied strings is not a legal floating point number or if NaN is compared to a floating point number other than NaN.
-
compareDateTime
public static int compareDateTime(String value1, String value2)
Compares two dateTime objects. Important: The comparison only works if both values have, or both values don't have specified a valid value for the timezone.- Parameters:
value1- An xsd:dateTime value.value2- An xsd:dateTime value.- Returns:
- -1 if value1 is before value2 (i.e. if the dateTime object represented
by value1 is before the dateTime object represented by value2), 0 if both are equal and
1 if value2 is before value1
.
-
parseBoolean
public static boolean parseBoolean(String s)
Parses the supplied xsd:boolean string and returns its value.- Parameters:
s- A string representation of an xsd:boolean value.- Returns:
- The boolean value represented by the supplied string argument.
- Throws:
NumberFormatException- If the supplied string is not a valid xsd:boolean value.
-
parseByte
public static byte parseByte(String s)
Parses the supplied xsd:byte string and returns its value.- Parameters:
s- A string representation of an xsd:byte value.- Returns:
- The byte value represented by the supplied string argument.
- Throws:
NumberFormatException- If the supplied string is not a valid xsd:byte value.
-
parseShort
public static short parseShort(String s)
Parses the supplied xsd:short string and returns its value.- Parameters:
s- A string representation of an xsd:short value.- Returns:
- The short value represented by the supplied string argument.
- Throws:
NumberFormatException- If the supplied string is not a valid xsd:short value.
-
parseInt
public static int parseInt(String s)
Parses the supplied xsd:int strings and returns its value.- Parameters:
s- A string representation of an xsd:int value.- Returns:
- The int value represented by the supplied string argument.
- Throws:
NumberFormatException- If the supplied string is not a valid xsd:int value.
-
parseLong
public static long parseLong(String s)
Parses the supplied xsd:long string and returns its value.- Parameters:
s- A string representation of an xsd:long value.- Returns:
- The long value represented by the supplied string argument.
- Throws:
NumberFormatException- If the supplied string is not a valid xsd:long value.
-
parseFloat
public static float parseFloat(String s)
Parses the supplied xsd:float string and returns its value.- Parameters:
s- A string representation of an xsd:float value.- Returns:
- The float value represented by the supplied string argument.
- Throws:
NumberFormatException- If the supplied string is not a valid xsd:float value.
-
parseDouble
public static double parseDouble(String s)
Parses the supplied xsd:double string and returns its value.- Parameters:
s- A string representation of an xsd:double value.- Returns:
- The double value represented by the supplied string argument.
- Throws:
NumberFormatException- If the supplied string is not a valid xsd:double value.
-
parseInteger
public static BigInteger parseInteger(String s)
Parses the supplied xsd:integer string and returns its value.- Parameters:
s- A string representation of an xsd:integer value.- Returns:
- The integer value represented by the supplied string argument.
- Throws:
NumberFormatException- If the supplied string is not a valid xsd:integer value.
-
parseDecimal
public static BigDecimal parseDecimal(String s)
Parses the supplied decimal/floating point string and returns its value.- Parameters:
s- A string representation of an xsd:decimal or xsd:double value.- Returns:
- The decimal/floating point value represented by the supplied string argument.
- Throws:
NumberFormatException- If the supplied string is not a valid xsd:decimal or xsd:double value.
-
parseCalendar
public static XMLGregorianCalendar parseCalendar(String s)
Parses the supplied calendar value string and returns its value.- Parameters:
s- A string representation of an xsd:dateTime, xsd:time, xsd:date, xsd:gYearMonth, xsd:gMonthDay, xsd:gYear, xsd:gMonth or xsd:gDay value.- Returns:
- The calendar value represented by the supplied string argument.
- Throws:
IllegalArgumentException- If the supplied string is not a valid calendar value.
-
parseDuration
public static Duration parseDuration(String s)
Parses the supplied xsd:duration value string and returns its value.- Parameters:
s- A string representation of an xsd:duration value.- Returns:
- The
Durationvalue represented by the supplied string argument. - Throws:
IllegalArgumentException- If the supplied string is not a valid xsd:duration value.UnsupportedOperationException- If implementation cannot support requested values. The XML Schema specification states that values can be of an arbitrary size. Implementations may chose not to or be incapable of supporting arbitrarily large and/or small values. An UnsupportedOperationException will be thrown with a message indicating implementation limits if implementation capacities are exceeded.
-
qnameToURI
public static IRI qnameToURI(QName qname)
Maps a datatype QName from the javax.xml.namespace package to an XML Schema 1.0 URI for the corresponding datatype. This method recognizes the XML Schema qname mentioned inDatatypeConstants. Note that Java 8 / 11 do not have constants for XML Schema 1.1 datatypes like xsd:dateTimeStamp.- Parameters:
qname- One of the XML Schema qnames fromDatatypeConstants.- Returns:
- A URI for the specified datatype.
- Throws:
IllegalArgumentException- If the supplied qname was not recognized by this method.- See Also:
DatatypeConstants
-
qnameToCoreDatatype
public static CoreDatatype.XSD qnameToCoreDatatype(QName qname)
-
-