Class AttributeUtility


  • public class AttributeUtility
    extends Object
    A utility class for handling attribute-related operations.
    Author:
    Luca Frosini (ISTI - CNR)
    • Field Detail

      • logger

        protected static org.slf4j.Logger logger
        The logger for this class.
    • Constructor Detail

      • AttributeUtility

        public AttributeUtility()
    • Method Detail

      • checkRegex

        public static void checkRegex​(String regex,
                                      String text)
        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

        public static int compareNumbers​(Number first,
                                         Number second)
        Compares two numbers by their decimal value, whatever their Java types.

        Each number is read from its shortest decimal representation, so that a Float compares as the decimal it was written as (e.g. 99.9f equals 99.9).

        Parameters:
        first - The first number.
        second - The second number.
        Returns:
        A negative integer, zero, or a positive integer as first is lower than, equal to, or greater than second.
      • isIntegral

        public static boolean isIntegral​(Number number)
        Tells whether a number has no fractional part.
        Parameters:
        number - The number to check.
        Returns:
        true if number is an integer value, e.g. 3 or 3.0.
      • toIntegerBound

        public static Integer toIntegerBound​(Number bound)
        Converts the bound of an attribute that only admits integer bounds.
        Parameters:
        bound - The bound, null for none.
        Returns:
        The bound as an Integer, null if bound is null.
        Throws:
        IllegalArgumentException - if bound is not an integer in the 32-bit range.
      • evaluateNullForDefaultValue

        public static String evaluateNullForDefaultValue​(String defaultValueAsString)
        Evaluates a default value string, returning null if 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.