Class FunctionUtils
- java.lang.Object
-
- gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils
-
public final class FunctionUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static MathContext
MATH_CONTEXT
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
asInteger(INumericItem value)
Converts aINumericItem
value to an integer value.static int
asInteger(BigInteger value)
Converts aBigInteger
value to an integer value.static long
asLong(INumericItem value)
Converts aINumericItem
value to a long value.static long
asLong(BigInteger value)
Converts aBigInteger
value to a long value.static <TYPE extends IItem>
ISequence<TYPE>asType(ISequence<?> sequence)
static <TYPE extends IItem>
TYPEasType(IItem item)
static <TYPE extends IItem>
TYPEasTypeOrNull(IItem item)
static <ITEM extends IItem>
ITEMgetFirstItem(ISequence<ITEM> sequence, boolean requireSingleton)
Retrieves the first item in a sequence.static <ITEM extends IItem>
ITEMrequireFirstItem(ISequence<ITEM> sequence, boolean requireSingleton)
Retrieves the first item in a sequence.static <TYPE extends IItem>
TYPErequireType(Class<TYPE> clazz, IItem item)
static <TYPE extends IItem>
TYPErequireTypeOrNull(Class<TYPE> clazz, IItem item)
static INumericItem
toNumeric(ISequence<?> sequence, boolean requireSingleton)
Gets the first item of the provided sequence as aINumericItem
value.static INumericItem
toNumeric(IAnyAtomicItem item)
Gets the provided item value as aINumericItem
value.static INumericItem
toNumeric(IItem item)
Gets the provided item value as aINumericItem
value.static INumericItem
toNumericOrNull(IAnyAtomicItem item)
Gets the provided item value as aINumericItem
value.
-
-
-
Field Detail
-
MATH_CONTEXT
public static final MathContext MATH_CONTEXT
-
-
Method Detail
-
asInteger
public static int asInteger(@NonNull INumericItem value)
Converts aINumericItem
value to an integer value.- Parameters:
value
- the value to convert- Returns:
- the integer value
- Throws:
ArithmeticException
- if the provided value will not exactly fit in anint
-
asInteger
public static int asInteger(@NonNull BigInteger value)
Converts aBigInteger
value to an integer value.- Parameters:
value
- the value to convert- Returns:
- the integer value
- Throws:
ArithmeticException
- if the provided value will not exactly fit in anint
-
asLong
public static long asLong(@NonNull INumericItem value)
Converts aINumericItem
value to a long value.- Parameters:
value
- the value to convert- Returns:
- the long value
- Throws:
ArithmeticException
- if the provided value will not exactly fit in anlong
-
asLong
public static long asLong(@NonNull BigInteger value)
Converts aBigInteger
value to a long value.- Parameters:
value
- the value to convert- Returns:
- the long value
- Throws:
ArithmeticException
- if the provided value will not exactly fit in anlong
-
requireFirstItem
@NonNull public static <ITEM extends IItem> ITEM requireFirstItem(@NonNull ISequence<ITEM> sequence, boolean requireSingleton)
Retrieves the first item in a sequence. If the sequence is empty, aTypeMetapathException
exception is thrown. If requireSingleton istrue
and the sequence contains more than one item, aTypeMetapathException
is thrown.- Type Parameters:
ITEM
- the item type to return derived from the provided sequence- Parameters:
sequence
- the sequence to retrieve the first item fromrequireSingleton
- iftrue
then aTypeMetapathException
is thrown if the sequence contains more than one item- Returns:
null
if the sequence is empty, or the item otherwise- Throws:
TypeMetapathException
- if the sequence is empty, or contains more than one item and requireSingleton istrue
-
getFirstItem
@Nullable public static <ITEM extends IItem> ITEM getFirstItem(@NonNull ISequence<ITEM> sequence, boolean requireSingleton)
Retrieves the first item in a sequence. If the sequence is empty, anull
result is returned. If requireSingleton istrue
and the sequence contains more than one item, aTypeMetapathException
is thrown.- Type Parameters:
ITEM
- the item type to return derived from the provided sequence- Parameters:
sequence
- the sequence to retrieve the first item fromrequireSingleton
- iftrue
then aTypeMetapathException
is thrown if the sequence contains more than one item- Returns:
null
if the sequence is empty, or the item otherwise- Throws:
TypeMetapathException
- if the sequence contains more than one item and requireSingleton istrue
-
toNumeric
@Nullable public static INumericItem toNumeric(@NonNull ISequence<?> sequence, boolean requireSingleton)
Gets the first item of the provided sequence as aINumericItem
value. If the sequence is empty, then anull
value is returned.- Parameters:
sequence
- a Metapath sequence containing the value to convertrequireSingleton
- iftrue
then aTypeMetapathException
is thrown if the sequence contains more than one item- Returns:
- the numeric item value, or
null
if the result is an empty sequence - Throws:
TypeMetapathException
- if the sequence contains more than one item, or the item cannot be cast to a numeric value
-
toNumeric
@NonNull public static INumericItem toNumeric(@NonNull IItem item)
Gets the provided item value as aINumericItem
value.- Parameters:
item
- the value to convert- Returns:
- the numeric item value
- Throws:
TypeMetapathException
- if the sequence contains more than one item, or the item cannot be cast to a numeric value
-
toNumeric
@NonNull public static INumericItem toNumeric(@NonNull IAnyAtomicItem item)
Gets the provided item value as aINumericItem
value.- Parameters:
item
- the value to convert- Returns:
- the numeric item value
- Throws:
TypeMetapathException
- if the item cannot be cast to a numeric value
-
toNumericOrNull
@Nullable public static INumericItem toNumericOrNull(@Nullable IAnyAtomicItem item)
Gets the provided item value as aINumericItem
value. If the item isnull
, then anull
value is returned.- Parameters:
item
- the value to convert- Returns:
- the numeric item value
- Throws:
TypeMetapathException
- if the item cannot be cast to a numeric value
-
asType
@NonNull public static <TYPE extends IItem> ISequence<TYPE> asType(@NonNull ISequence<?> sequence)
-
asTypeOrNull
@Nullable public static <TYPE extends IItem> TYPE asTypeOrNull(@Nullable IItem item)
-
requireType
@NonNull public static <TYPE extends IItem> TYPE requireType(Class<TYPE> clazz, IItem item)
-
requireTypeOrNull
@Nullable public static <TYPE extends IItem> TYPE requireTypeOrNull(Class<TYPE> clazz, @Nullable IItem item)
-
-