org.jrdf.parser.rdfxml
Class XmlDatatypeUtil

java.lang.Object
  extended by org.jrdf.parser.rdfxml.XmlDatatypeUtil

public class XmlDatatypeUtil
extends Object

Provides methods for handling the standard XML Schema datatypes.


Constructor Summary
XmlDatatypeUtil()
           
 
Method Summary
static int compare(String value1, String value2, String datatype)
           
static int compareBytes(String int1, String int2)
           
static int compareCanonicalDecimals(String dec1, String dec2)
          Compares two canonical decimals to eachother.
static int compareCanonicalDoubles(String double1, String double2)
          Compares two canonical doubles to eachother.
static int compareCanonicalFloats(String float1, String float2)
          Compares two canonical floats to eachother.
static int compareCanonicalFPNumbers(String float1, String float2)
          Compares two canonical floating point numbers to eachother.
static int compareCanonicalIntegers(String int1, String int2)
          Compares two canonical integers to eachother.
static int compareDecimals(String dec1, String dec2)
          Compares two decimals to eachother.
static int compareDoubles(String double1, String double2)
          Compares two doubles to eachother.
static int compareFloats(String float1, String float2)
          Compares two floats to eachother.
static int compareFPNumbers(String fp1, String fp2)
          Compares two floating point numbers to eachother.
static int compareIntegers(String int1, String int2)
          Compares two integers to eachother.
static int compareInts(String int1, String int2)
           
static int compareLongs(String int1, String int2)
           
static int compareNegativeIntegers(String int1, String int2)
           
static int compareNonNegativeIntegers(String int1, String int2)
           
static int compareNonPositiveIntegers(String int1, String int2)
           
static int comparePositiveIntegers(String int1, String int2)
           
static int compareShorts(String int1, String int2)
           
static int compareUnsignedBytes(String int1, String int2)
           
static int compareUnsignedInts(String int1, String int2)
           
static int compareUnsignedLongs(String int1, String int2)
           
static int compareUnsignedShorts(String int1, String int2)
           
static boolean isBuiltInDatatype(String datatype)
          Checks whether the supplied datatype is a built-in XML Schema datatype.
static boolean isDecimalDatatype(String 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 boolean isDerivedDatatype(String datatype)
          Checks whether the supplied datatype is a derived XML Schema datatype.
static boolean isFloatingPointDatatype(String datatype)
          Checks whether the supplied datatype is equal to xsd:float or xsd:double.
static boolean isIntegerDatatype(String 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 boolean isOrderedDatatype(String datatype)
          Checks whether the supplied datatype is ordered.
static boolean isPrimitiveDatatype(String datatype)
          Checks whether the supplied datatype is a primitive XML Schema datatype.
static boolean isValidBoolean(String value)
           
static boolean isValidByte(String value)
           
static boolean isValidDecimal(String value)
           
static boolean isValidDouble(String value)
           
static boolean isValidFloat(String value)
           
static boolean isValidInt(String value)
           
static boolean isValidInteger(String value)
           
static boolean isValidLong(String value)
           
static boolean isValidNegativeInteger(String value)
           
static boolean isValidNonNegativeInteger(String value)
           
static boolean isValidNonPositiveInteger(String value)
           
static boolean isValidPositiveInteger(String value)
           
static boolean isValidShort(String value)
           
static boolean isValidUnsignedByte(String value)
           
static boolean isValidUnsignedInt(String value)
           
static boolean isValidUnsignedLong(String value)
           
static boolean isValidUnsignedShort(String value)
           
static boolean isValidValue(String value, String datatype)
           
static String normalize(String value, String datatype)
          Normalizes the supplied value according to the normalization rules for the supplied datatype.
static String normalizeBoolean(String value)
          Normalizes a boolean value to its canonical representation.
static String normalizeByte(String value)
          Normalizes an xsd:byte.
static String normalizeDecimal(String decimal)
          Normalizes a decimal to its canonical representation.
static String normalizeDouble(String value)
          Normalizes a double to its canonical representation.
static String normalizeFloat(String value)
          Normalizes a float to its canonical representation.
static String normalizeFPNumber(String value)
          Normalizes a floating point number to its canonical representation.
static String normalizeInt(String value)
          Normalizes an xsd:int.
static String normalizeInteger(String value)
          Normalizes an integer to its canonical representation.
static String normalizeLong(String value)
          Normalizes an xsd:long.
static String normalizeNegativeInteger(String value)
          Normalizes an xsd:negativeInteger.
static String normalizeNonNegativeInteger(String value)
          Normalizes an xsd:nonNegativeInteger.
static String normalizeNonPositiveInteger(String value)
          Normalizes an xsd:nonPositiveInteger.
static String normalizePositiveInteger(String value)
          Normalizes an xsd:positiveInteger.
static String normalizeShort(String value)
          Normalizes an xsd:short.
static String normalizeUnsignedByte(String value)
          Normalizes an xsd:unsignedByte.
static String normalizeUnsignedInt(String value)
          Normalizes an xsd:unsignedInt.
static String normalizeUnsignedLong(String value)
          Normalizes an xsd:unsignedLong.
static String normalizeUnsignedShort(String value)
          Normalizes an xsd:unsignedShort.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlDatatypeUtil

public XmlDatatypeUtil()
Method Detail

isPrimitiveDatatype

public static boolean isPrimitiveDatatype(String datatype)
Checks whether the supplied datatype is a primitive XML Schema datatype.


isDerivedDatatype

public static boolean isDerivedDatatype(String datatype)
Checks whether the supplied datatype is a derived XML Schema datatype.


isBuiltInDatatype

public static boolean isBuiltInDatatype(String datatype)
Checks whether the supplied datatype is a built-in XML Schema datatype.


isDecimalDatatype

public static boolean isDecimalDatatype(String datatype)
Checks whether the supplied datatype is equal to xsd:decimal or one of the built-in datatypes that is derived from xsd:decimal.


isIntegerDatatype

public static boolean isIntegerDatatype(String datatype)
Checks whether the supplied datatype is equal to xsd:integer or one of the built-in datatypes that is derived from xsd:integer.


isFloatingPointDatatype

public static boolean isFloatingPointDatatype(String datatype)
Checks whether the supplied datatype is equal to xsd:float or xsd:double.


isOrderedDatatype

public static boolean isOrderedDatatype(String datatype)
Checks whether the supplied datatype is ordered. The values of an ordered datatype can be compared to eachother using operators like < and >.


isValidValue

public static boolean isValidValue(String value,
                                   String datatype)

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)

normalize

public static String normalize(String value,
                               String 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 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.


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.

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.

compare

public static int compare(String value1,
                          String value2,
                          String datatype)

compareDecimals

public static int compareDecimals(String dec1,
                                  String dec2)
Compares two 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.
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 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.

compareIntegers

public static int compareIntegers(String int1,
                                  String int2)
Compares two 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.
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 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.

compareNegativeIntegers

public static int compareNegativeIntegers(String int1,
                                          String int2)

compareNonPositiveIntegers

public static int compareNonPositiveIntegers(String int1,
                                             String int2)

compareNonNegativeIntegers

public static int compareNonNegativeIntegers(String int1,
                                             String int2)

comparePositiveIntegers

public static int comparePositiveIntegers(String int1,
                                          String int2)

compareLongs

public static int compareLongs(String int1,
                               String int2)

compareInts

public static int compareInts(String int1,
                              String int2)

compareShorts

public static int compareShorts(String int1,
                                String int2)

compareBytes

public static int compareBytes(String int1,
                               String int2)

compareUnsignedLongs

public static int compareUnsignedLongs(String int1,
                                       String int2)

compareUnsignedInts

public static int compareUnsignedInts(String int1,
                                      String int2)

compareUnsignedShorts

public static int compareUnsignedShorts(String int1,
                                        String int2)

compareUnsignedBytes

public static int compareUnsignedBytes(String int1,
                                       String int2)

compareFloats

public static int compareFloats(String float1,
                                String float2)
Compares two floats to eachother.

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 eachother.

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 eachother.

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.

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.

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 eachother.

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.