Package com.stardog.stark
Class XMLDatatypes
- java.lang.Object
-
- com.stardog.stark.XMLDatatypes
-
public final class XMLDatatypes extends java.lang.Object
Utility for XML schema datatypes
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Arjohn Kampman, Michael Grove
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.EnumSet<Datatype>
CALENDAR
static java.lang.String
DATE
static java.lang.String
DAY_TIME_DURATION
static java.util.EnumSet<Datatype>
DERIVED
static java.lang.String
DURATION
static java.util.EnumSet<Datatype>
DURATIONS
static java.util.EnumSet<Datatype>
FP
static java.lang.String
GDAY
static java.lang.String
GMONTH
static java.lang.String
GMONTHDAY
static java.lang.String
GYEAR
static java.lang.String
GYEARMONTH_REGEX
static java.util.EnumSet<Datatype>
INTEGERS
static java.util.EnumSet<Datatype>
PRIMITIVES
static java.lang.String
TIME
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
collapseWhiteSpace(java.lang.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 int
compareCanonicalDecimals(java.lang.String dec1, java.lang.String dec2)
Compares two canonical decimals to eachother.static int
compareCanonicalIntegers(java.lang.String int1, java.lang.String int2)
Compares two canonical integers to eachother.static boolean
isBuiltInDatatype(Datatype theDatatype)
Return whether or not theDatatype
is a built-in XML schema type.static boolean
isBuiltInDatatype(IRI theIRI)
Return whether or not theIRI
is a built-in XML schema type.static boolean
isCalendarDatatype(Datatype theDatatype)
Return whether or not theDatatype
is an XML datatype calendar typestatic boolean
isDecimalDatatype(Datatype theDatatype)
Return whether or not theDatatype
is `xsd:decimal` or derived from itstatic boolean
isDurationDatatype(Datatype theDatatype)
static boolean
isFloatingPointDatatype(Datatype theDatatype)
static boolean
isIntegerDatatype(Datatype theDatatype)
Return whether or not theDatatype
is `xsd:integer` or derived from itstatic boolean
isNumericDatatype(Datatype theDatatype)
Return whether or not theDatatype
is a numeric datatype such as `xsd:long` or `xsd:decimal`.static boolean
isPrimitiveDatatype(Datatype theDatatype)
Return whether or not theDatatype
is a primitive XML schema type.static boolean
isValidBoolean(java.lang.String value)
static boolean
isValidByte(java.lang.String value)
static boolean
isValidDate(java.lang.String value)
Determines if the supplied value is a valid xsd:date string.static boolean
isValidDateTime(java.lang.String value)
static boolean
isValidDayTimeDuration(java.lang.String value)
static boolean
isValidDecimal(java.lang.String value)
static boolean
isValidDouble(java.lang.String value)
static boolean
isValidDuration(java.lang.String value)
static boolean
isValidFloat(java.lang.String value)
static boolean
isValidGDay(java.lang.String value)
Determines if the supplied value is a valid xsd:gDay string.static boolean
isValidGMonth(java.lang.String value)
Determines if the supplied value is a valid xsd:gMonth string.static boolean
isValidGMonthDay(java.lang.String value)
Determines if the supplied value is a valid xsd:gMonthDay string.static boolean
isValidGYear(java.lang.String value)
Determines if the supplied value is a valid xsd:gYear string.static boolean
isValidGYearMonth(java.lang.String value)
Determines if the supplied value is a valid xsd:gYearMonth string.static boolean
isValidInt(java.lang.String value)
static boolean
isValidInteger(java.lang.String value)
static boolean
isValidLong(java.lang.String value)
static boolean
isValidNegativeInteger(java.lang.String value)
static boolean
isValidNonNegativeInteger(java.lang.String value)
static boolean
isValidNonPositiveInteger(java.lang.String value)
static boolean
isValidPositiveInteger(java.lang.String value)
static boolean
isValidQName(java.lang.String value)
Determines if the supplied value is a valid xsd:QName string.static boolean
isValidShort(java.lang.String value)
static boolean
isValidTime(java.lang.String value)
Determines if the supplied value is a valid xsd:time string.static boolean
isValidUnsignedByte(java.lang.String value)
static boolean
isValidUnsignedInt(java.lang.String value)
static boolean
isValidUnsignedLong(java.lang.String value)
static boolean
isValidUnsignedShort(java.lang.String value)
static boolean
isValidValue(Literal theLiteral)
Verifies if the supplied lexical value is valid for the given literal.static boolean
isValidValue(java.lang.String theValue, Datatype theDatatype)
Verifies if the supplied lexical value is valid for the given datatype.static java.lang.String
normalize(java.lang.String value, Datatype datatype)
Normalizes the supplied value according to the normalization rules for the supplied datatype.static java.lang.String
normalizeBoolean(java.lang.String theValue)
Normalizes a boolean value to its canonical representation.static java.lang.String
normalizeByte(java.lang.String value)
Normalizes an xsd:byte.static java.lang.String
normalizeDateTime(java.lang.String value)
Normalizes an xsd:dateTime.static java.lang.String
normalizeDecimal(java.lang.String decimal)
Normalizes a decimal to its canonical representation.static java.lang.String
normalizeDouble(java.lang.String value)
Normalizes a double to its canonical representation.static java.lang.String
normalizeFloat(java.lang.String value)
Normalizes a float to its canonical representation.static java.lang.String
normalizeInt(java.lang.String value)
Normalizes an xsd:int.static java.lang.String
normalizeInteger(java.lang.String value)
Normalizes an integer to its canonical representation.static java.lang.String
normalizeLong(java.lang.String value)
Normalizes an xsd:long.static java.lang.String
normalizeNegativeInteger(java.lang.String value)
Normalizes an xsd:negativeInteger.static java.lang.String
normalizeNonNegativeInteger(java.lang.String value)
Normalizes an xsd:nonNegativeInteger.static java.lang.String
normalizeNonPositiveInteger(java.lang.String value)
Normalizes an xsd:nonPositiveInteger.static java.lang.String
normalizePositiveInteger(java.lang.String value)
Normalizes an xsd:positiveInteger.static java.lang.String
normalizeShort(java.lang.String value)
Normalizes an xsd:short.static java.lang.String
normalizeUnsignedByte(java.lang.String value)
Normalizes an xsd:unsignedByte.static java.lang.String
normalizeUnsignedInt(java.lang.String value)
Normalizes an xsd:unsignedInt.static java.lang.String
normalizeUnsignedLong(java.lang.String value)
Normalizes an xsd:unsignedLong.static java.lang.String
normalizeUnsignedShort(java.lang.String value)
Normalizes an xsd:unsignedShort.static javax.xml.datatype.XMLGregorianCalendar
parseCalendar(java.lang.String s)
Parses the supplied calendar value string and returns its value.
-
-
-
Field Detail
-
PRIMITIVES
public static final java.util.EnumSet<Datatype> PRIMITIVES
-
DERIVED
public static final java.util.EnumSet<Datatype> DERIVED
-
INTEGERS
public static final java.util.EnumSet<Datatype> INTEGERS
-
FP
public static final java.util.EnumSet<Datatype> FP
-
CALENDAR
public static final java.util.EnumSet<Datatype> CALENDAR
-
DURATIONS
public static final java.util.EnumSet<Datatype> DURATIONS
-
GYEARMONTH_REGEX
public static final java.lang.String GYEARMONTH_REGEX
- See Also:
- Constant Field Values
-
GYEAR
public static final java.lang.String GYEAR
- See Also:
- Constant Field Values
-
GMONTHDAY
public static final java.lang.String GMONTHDAY
- See Also:
- Constant Field Values
-
GMONTH
public static final java.lang.String GMONTH
- See Also:
- Constant Field Values
-
GDAY
public static final java.lang.String GDAY
- See Also:
- Constant Field Values
-
TIME
public static final java.lang.String TIME
- See Also:
- Constant Field Values
-
DATE
public static final java.lang.String DATE
- See Also:
- Constant Field Values
-
DAY_TIME_DURATION
public static final java.lang.String DAY_TIME_DURATION
- See Also:
- Constant Field Values
-
DURATION
public static final java.lang.String DURATION
- See Also:
- Constant Field Values
-
-
Method Detail
-
isPrimitiveDatatype
public static boolean isPrimitiveDatatype(@Nonnull Datatype theDatatype)
Return whether or not theDatatype
is a primitive XML schema type.- Parameters:
theDatatype
- the datatype- Returns:
- `true` if a built-in type, `false` otherwise
-
isCalendarDatatype
public static boolean isCalendarDatatype(@Nonnull Datatype theDatatype)
Return whether or not theDatatype
is an XML datatype calendar type- Parameters:
theDatatype
- the datatype- Returns:
- `true` if a calendar type, `false` otherwise
-
isBuiltInDatatype
public static boolean isBuiltInDatatype(@Nonnull IRI theIRI)
Return whether or not theIRI
is a built-in XML schema type.- Parameters:
theIRI
- the datatype theIRI- Returns:
- `true` if a built-in type, `false` otherwise
-
isBuiltInDatatype
public static boolean isBuiltInDatatype(@Nonnull Datatype theDatatype)
Return whether or not theDatatype
is a built-in XML schema type.- Parameters:
theDatatype
- the datatype- Returns:
- `true` if a built-in type, `false` otherwise
-
isNumericDatatype
public static boolean isNumericDatatype(@Nonnull Datatype theDatatype)
Return whether or not theDatatype
is a numeric datatype such as `xsd:long` or `xsd:decimal`.- Parameters:
theDatatype
- the datatype- Returns:
- `true` if a numeric type, `false` otherwise
-
isDecimalDatatype
public static boolean isDecimalDatatype(@Nonnull Datatype theDatatype)
Return whether or not theDatatype
is `xsd:decimal` or derived from it- Parameters:
theDatatype
- the datatype- Returns:
- `true` if a decimal type, `false` otherwise
-
isDurationDatatype
public static boolean isDurationDatatype(@Nonnull Datatype theDatatype)
-
isIntegerDatatype
public static boolean isIntegerDatatype(@Nonnull Datatype theDatatype)
Return whether or not theDatatype
is `xsd:integer` or derived from it- Parameters:
theDatatype
- the datatype- Returns:
- `true` if a integer type, `false` otherwise
-
isFloatingPointDatatype
public static boolean isFloatingPointDatatype(@Nonnull Datatype theDatatype)
-
isValidValue
public static boolean isValidValue(@Nonnull Literal theLiteral)
Verifies if the supplied lexical value is valid for the given literal.- Parameters:
theLiteral
- the literal- Returns:
- `true` if the supplied lexical value is valid, `false` otherwise.
-
isValidValue
public static boolean isValidValue(@Nonnull java.lang.String theValue, @Nonnull Datatype theDatatype)
Verifies if the supplied lexical value is valid for the given datatype.- Parameters:
theValue
- a lexical valuetheDatatype
- an XML Schema datatatype.- Returns:
- `true` if the supplied lexical value is valid, `false` otherwise.
-
isValidDecimal
public static boolean isValidDecimal(java.lang.String value)
-
isValidInteger
public static boolean isValidInteger(java.lang.String value)
-
isValidNegativeInteger
public static boolean isValidNegativeInteger(java.lang.String value)
-
isValidNonPositiveInteger
public static boolean isValidNonPositiveInteger(java.lang.String value)
-
isValidNonNegativeInteger
public static boolean isValidNonNegativeInteger(java.lang.String value)
-
isValidPositiveInteger
public static boolean isValidPositiveInteger(java.lang.String value)
-
isValidLong
public static boolean isValidLong(java.lang.String value)
-
isValidInt
public static boolean isValidInt(java.lang.String value)
-
isValidShort
public static boolean isValidShort(java.lang.String value)
-
isValidByte
public static boolean isValidByte(java.lang.String value)
-
isValidUnsignedLong
public static boolean isValidUnsignedLong(java.lang.String value)
-
isValidUnsignedInt
public static boolean isValidUnsignedInt(java.lang.String value)
-
isValidUnsignedShort
public static boolean isValidUnsignedShort(java.lang.String value)
-
isValidUnsignedByte
public static boolean isValidUnsignedByte(java.lang.String value)
-
isValidFloat
public static boolean isValidFloat(java.lang.String value)
-
isValidDouble
public static boolean isValidDouble(java.lang.String value)
-
isValidBoolean
public static boolean isValidBoolean(java.lang.String value)
-
isValidDuration
public static boolean isValidDuration(java.lang.String value)
-
isValidDayTimeDuration
public static boolean isValidDayTimeDuration(java.lang.String value)
-
isValidDateTime
public static boolean isValidDateTime(java.lang.String value)
-
isValidDate
public static boolean isValidDate(java.lang.String value)
Determines if the supplied value is a valid xsd:date string.- Parameters:
value
- the date- Returns:
- `true` if valid, `false` otherwise
-
isValidTime
public static boolean isValidTime(java.lang.String value)
Determines if the supplied value is a valid xsd:time string.- Parameters:
value
- the time- Returns:
- `true` if valid, `false` otherwise
-
isValidGDay
public static boolean isValidGDay(java.lang.String value)
Determines if the supplied value is a valid xsd:gDay string.- Parameters:
value
- the gday- Returns:
- `true` if valid, `false` otherwise
-
isValidGMonth
public static boolean isValidGMonth(java.lang.String value)
Determines if the supplied value is a valid xsd:gMonth string.- Parameters:
value
- the gmonth- Returns:
- `true` if valid, `false` otherwise
-
isValidGMonthDay
public static boolean isValidGMonthDay(java.lang.String value)
Determines if the supplied value is a valid xsd:gMonthDay string.- Parameters:
value
- the gmonthday- Returns:
- `true` if valid, `false` otherwise
-
isValidGYear
public static boolean isValidGYear(java.lang.String value)
Determines if the supplied value is a valid xsd:gYear string.- Parameters:
value
- the value- Returns:
- `true` if valid, `false` otherwise
-
isValidGYearMonth
public static boolean isValidGYearMonth(java.lang.String value)
Determines if the supplied value is a valid xsd:gYearMonth string.- Parameters:
value
- the value- Returns:
- `true` if valid, `false` otherwise
-
isValidQName
public static boolean isValidQName(java.lang.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
- the qname- Returns:
- `true` if valid, `false` otherwise
-
normalize
public static java.lang.String normalize(java.lang.String value, Datatype 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:
java.lang.IllegalArgumentException
- If the supplied value is illegal considering the supplied datatype.
-
normalizeBoolean
public static java.lang.String normalizeBoolean(java.lang.String theValue)
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:
theValue
- The boolean value to normalize.- Returns:
- The normalized value.
- Throws:
java.lang.IllegalArgumentException
- If the supplied value is not a legal boolean.
-
normalizeDecimal
public static java.lang.String normalizeDecimal(java.lang.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:
java.lang.IllegalArgumentException
- If one of the supplied strings is not a legal decimal.
-
normalizeInteger
public static java.lang.String normalizeInteger(java.lang.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:
java.lang.IllegalArgumentException
- If the supplied value is not a legal integer.
-
normalizeNegativeInteger
public static java.lang.String normalizeNegativeInteger(java.lang.String value)
Normalizes an xsd:negativeInteger.
-
normalizeNonPositiveInteger
public static java.lang.String normalizeNonPositiveInteger(java.lang.String value)
Normalizes an xsd:nonPositiveInteger.
-
normalizeNonNegativeInteger
public static java.lang.String normalizeNonNegativeInteger(java.lang.String value)
Normalizes an xsd:nonNegativeInteger.
-
normalizePositiveInteger
public static java.lang.String normalizePositiveInteger(java.lang.String value)
Normalizes an xsd:positiveInteger.
-
normalizeLong
public static java.lang.String normalizeLong(java.lang.String value)
Normalizes an xsd:long.
-
normalizeInt
public static java.lang.String normalizeInt(java.lang.String value)
Normalizes an xsd:int.
-
normalizeShort
public static java.lang.String normalizeShort(java.lang.String value)
Normalizes an xsd:short.
-
normalizeByte
public static java.lang.String normalizeByte(java.lang.String value)
Normalizes an xsd:byte.
-
normalizeUnsignedLong
public static java.lang.String normalizeUnsignedLong(java.lang.String value)
Normalizes an xsd:unsignedLong.
-
normalizeUnsignedInt
public static java.lang.String normalizeUnsignedInt(java.lang.String value)
Normalizes an xsd:unsignedInt.
-
normalizeUnsignedShort
public static java.lang.String normalizeUnsignedShort(java.lang.String value)
Normalizes an xsd:unsignedShort.
-
normalizeUnsignedByte
public static java.lang.String normalizeUnsignedByte(java.lang.String value)
Normalizes an xsd:unsignedByte.
-
normalizeFloat
public static java.lang.String normalizeFloat(java.lang.String value)
Normalizes a float to its canonical representation.- Parameters:
value
- The value to normalize.- Returns:
- The canonical representation of value.
- Throws:
java.lang.IllegalArgumentException
- If the supplied value is not a legal float.
-
normalizeDouble
public static java.lang.String normalizeDouble(java.lang.String value)
Normalizes a double to its canonical representation.- Parameters:
value
- The value to normalize.- Returns:
- The canonical representation of value.
- Throws:
java.lang.IllegalArgumentException
- If the supplied value is not a legal double.
-
normalizeDateTime
public static java.lang.String normalizeDateTime(java.lang.String value)
Normalizes an xsd:dateTime.- Parameters:
value
- The value to normalize.- Returns:
- The normalized value.
- Throws:
java.lang.IllegalArgumentException
- If the supplied value is not a legal xsd:dateTime value.
-
collapseWhiteSpace
public static java.lang.String collapseWhiteSpace(java.lang.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.
-
compareCanonicalDecimals
public static int compareCanonicalDecimals(java.lang.String dec1, java.lang.String dec2)
Compares two canonical decimals to eachother.- 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:
java.lang.IllegalArgumentException
- If one of the supplied strings is not a legal decimal.
-
compareCanonicalIntegers
public static int compareCanonicalIntegers(java.lang.String int1, java.lang.String int2)
Compares two canonical integers to eachother.- 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:
java.lang.IllegalArgumentException
- If one of the supplied strings is not a legal integer.
-
parseCalendar
public static javax.xml.datatype.XMLGregorianCalendar parseCalendar(java.lang.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:
java.lang.NumberFormatException
- If the supplied string is not a valid calendar value.
-
-