Class XMLDatatypes

java.lang.Object
com.stardog.stark.XMLDatatypes

public final class XMLDatatypes extends Object

Utility for XML schema datatypes

Since:
1.0
Version:
1.0
Author:
Arjohn Kampman, Michael Grove
  • Field Details

  • Method Details

    • isPrimitiveDatatype

      public static boolean isPrimitiveDatatype(@Nonnull Datatype theDatatype)
      Return whether or not the Datatype 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 the Datatype 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 the IRI 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 the Datatype 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 the Datatype 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 the Datatype 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 the Datatype 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 String theValue, @Nonnull Datatype theDatatype)
      Verifies if the supplied lexical value is valid for the given datatype.
      Parameters:
      theValue - a lexical value
      theDatatype - an XML Schema datatatype.
      Returns:
      `true` if the supplied lexical value is valid, `false` otherwise.
    • isValidDecimal

      public static boolean isValidDecimal(String value)
    • isValidInteger

      public static boolean isValidInteger(String value)
    • isValidNegativeInteger

      public static boolean isValidNegativeInteger(String value)
    • isValidNonPositiveInteger

      public static boolean isValidNonPositiveInteger(String value)
    • isValidNonNegativeInteger

      public static boolean isValidNonNegativeInteger(String value)
    • isValidPositiveInteger

      public static boolean isValidPositiveInteger(String value)
    • isValidLong

      public static boolean isValidLong(String value)
    • isValidInt

      public static boolean isValidInt(String value)
    • isValidShort

      public static boolean isValidShort(String value)
    • isValidByte

      public static boolean isValidByte(String value)
    • isValidUnsignedLong

      public static boolean isValidUnsignedLong(String value)
    • isValidUnsignedInt

      public static boolean isValidUnsignedInt(String value)
    • isValidUnsignedShort

      public static boolean isValidUnsignedShort(String value)
    • isValidUnsignedByte

      public static boolean isValidUnsignedByte(String value)
    • isValidFloat

      public static boolean isValidFloat(String value)
    • isValidDouble

      public static boolean isValidDouble(String value)
    • isValidBoolean

      public static boolean isValidBoolean(String value)
    • isValidDuration

      public static boolean isValidDuration(String value)
    • isValidDayTimeDuration

      public static boolean isValidDayTimeDuration(String value)
    • isValidDateTime

      public static boolean isValidDateTime(String value)
    • isValidDate

      public static boolean isValidDate(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(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(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(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(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(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(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(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 String normalize(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:
      IllegalArgumentException - If the supplied value is illegal considering the supplied datatype.
    • normalizeBoolean

      public static String normalizeBoolean(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:
      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.
    • normalizeLong

      public static String normalizeLong(String value)
      Normalizes an xsd:long.
    • normalizeInt

      public static String normalizeInt(String value)
      Normalizes an xsd:int.
    • normalizeShort

      public static String normalizeShort(String value)
      Normalizes an xsd:short.
    • normalizeByte

      public static String normalizeByte(String value)
      Normalizes an xsd:byte.
    • 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.
    • 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.
    • compareCanonicalDecimals

      public static int compareCanonicalDecimals(String dec1, 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:
      IllegalArgumentException - If one of the supplied strings is not a legal decimal.
    • compareCanonicalIntegers

      public static int compareCanonicalIntegers(String int1, 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:
      IllegalArgumentException - If one of the supplied strings is not a legal integer.
    • 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:
      NumberFormatException - If the supplied string is not a valid calendar value.