Class AttributeUtility
java.lang.Object
org.gcube.informationsystem.utils.AttributeUtility
A utility class for handling attribute-related operations.
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static org.slf4j.LoggerThe logger for this class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LocalDateTimecheckDateTimeString(String dateTimeString) Checks if a string is a valid date-time string according to the standard pattern.static voidcheckRegex(String regex, String text) Checks if a given text matches a regular expression.static intcompareNumbers(Number first, Number second) Compares two numbers by their decimal value, whatever their Java types.static StringevaluateNullForDefaultValue(String defaultValueAsString) Evaluates a default value string, returningnullif the string is "null".static ObjectevaluateValueStringAccordingBaseType(PropertyTypeName.BaseType baseType, String valueAsString) Converts a string value to an object of the specified base type.static booleanisIntegral(Number number) Tells whether a number has no fractional part.static IntegertoIntegerBound(Number bound) Converts the bound of an attribute that only admits integer bounds.
-
Field Details
-
logger
protected static org.slf4j.Logger loggerThe logger for this class.
-
-
Constructor Details
-
AttributeUtility
public AttributeUtility()
-
-
Method Details
-
checkRegex
Checks if a given text matches a regular expression.- Parameters:
regex- The regular expression.text- The text to check.- Throws:
RuntimeException- if the text does not match the regex or if the regex is invalid.
-
compareNumbers
Compares two numbers by their decimal value, whatever their Java types.Each number is read from its shortest decimal representation, so that a
Floatcompares as the decimal it was written as (e.g.99.9fequals99.9).- Parameters:
first- The first number.second- The second number.- Returns:
- A negative integer, zero, or a positive integer as
firstis lower than, equal to, or greater thansecond.
-
isIntegral
Tells whether a number has no fractional part.- Parameters:
number- The number to check.- Returns:
trueifnumberis an integer value, e.g.3or3.0.
-
toIntegerBound
Converts the bound of an attribute that only admits integer bounds.- Parameters:
bound- The bound,nullfor none.- Returns:
- The bound as an
Integer,nullifboundisnull. - Throws:
IllegalArgumentException- ifboundis not an integer in the 32-bit range.
-
evaluateNullForDefaultValue
Evaluates a default value string, returningnullif the string is "null".- Parameters:
defaultValueAsString- The default value as a string.- Returns:
- The evaluated default value.
-
evaluateValueStringAccordingBaseType
public static Object evaluateValueStringAccordingBaseType(PropertyTypeName.BaseType baseType, String valueAsString) Converts a string value to an object of the specified base type.- Parameters:
baseType- The target base type.valueAsString- The string value to convert.- Returns:
- The converted object.
-
checkDateTimeString
public static LocalDateTime checkDateTimeString(String dateTimeString) throws DateTimeParseException Checks if a string is a valid date-time string according to the standard pattern.- Parameters:
dateTimeString- The date-time string to check.- Returns:
- The parsed
LocalDateTime. - Throws:
DateTimeParseException- if the string is not a valid date-time.
-