Class AttributeUtils


  • public class AttributeUtils
    extends Object
    Set of utility methods to manipulate supported attribute types.

    The attribute system is built with a set of supported column types. This class contains utilities to parse and convert supported types. It also contains utilities to manipulate primitive arrays (the preferred array type) and date/time types. Default time zone for parsing/printing dates is UTC.

    • Method Detail

      • print

        public static String print​(Object value)
        Returns the string representation of the given value.
        Parameters:
        value - value
        Returns:
        string representation
      • print

        public static String print​(Object value,
                                   TimeFormat timeFormat,
                                   org.joda.time.DateTimeZone timeZone)
        Returns the string representation of the given value.
        Parameters:
        value - value
        timeFormat - time format
        timeZone - time zone
        Returns:
        string representation
      • parse

        public static Object parse​(String str,
                                   Class typeClass,
                                   org.joda.time.DateTimeZone timeZone)
        Parses the given string using the type class provided and returns an instance.
        Parameters:
        str - string to parse
        typeClass - class of the desired type
        timeZone - time zone to use or null to use default time zone (UTC), for dynamic types only
        Returns:
        an instance of the type class, or null if str is null or empty
      • parse

        public static Object parse​(String str,
                                   Class typeClass)
        Parses the given string using the type class provided and returns an instance. Default time zone is used (UTC) for dynamic types (timestamps/intervals).
        Parameters:
        str - string to parse
        typeClass - class of the desired type
        Returns:
        an instance of the type class, or null if str is null or empty
      • getPrimitiveType

        public static Class getPrimitiveType​(Class type)
        Returns the primitive type for the given wrapped primitive.

        Example: Returns int.class given Integer.class

        Parameters:
        type - type to get the primitive type from
        Returns:
        primitive type
      • getPrimitiveArray

        public static Object getPrimitiveArray​(Object[] array)
        Returns the primitive array given a wrapped primitive array.

        Example: Returns int[] array given an Integer[] array

        Parameters:
        array - wrapped primitive array instance
        Returns:
        primitive array instance
        Throws:
        IllegalArgumentException - Thrown if any of the array values is null
      • getSupportedTypes

        public static Set<Class> getSupportedTypes()
        Returns the set of types supported.
        Returns:
        set of supported types
      • isSupported

        public static boolean isSupported​(Class type)
        Returns true if type is a supported type.
        Parameters:
        type - type to test support
        Returns:
        true if supported, false otherwise
      • getStandardizedType

        public static Class getStandardizedType​(Class type)
        Returns the standardized type for the given type class.

        For instance, getStandardizedType(int.class) would return Integer.class.

        Parameters:
        type - type to standardize
        Returns:
        standardized type
      • isStandardizedType

        public static boolean isStandardizedType​(Class type)
        Returns true if type is a standardized type.

        Non standardized types are transformed into standardized types using getStandardizedType(java.lang.Class).

        Parameters:
        type - the type to test
        Returns:
        true if type is standardized, false otherwise
      • getTimestampMapType

        public static Class<? extends TimestampMap> getTimestampMapType​(Class type)
        Returns the dynamic timestamp map value type for the given type.
        Parameters:
        type - static type
        Returns:
        timestamp map type
      • getIntervalMapType

        public static Class<? extends IntervalMap> getIntervalMapType​(Class type)
        Returns the dynamic timestamp map value type for the given type.
        Parameters:
        type - static type
        Returns:
        timestamp map type
      • getStaticType

        public static Class getStaticType​(Class<? extends TimeMap> type)
        Returns the static type for the given time map type.
        Parameters:
        type - time map type
        Returns:
        static type
      • standardizeValue

        public static Object standardizeValue​(Object value)
        Transform the given value instance in a standardized type if necessary.

        This function transforms wrapped primitive arrays in primitive arrays.

        Parameters:
        value - value to standardize
        Returns:
        standardized value, or value if already standardized
      • isNumberType

        public static boolean isNumberType​(Class type)
        Returns true if type is a number type.

        This can be true for static, arrays and dynamic types.

        Parameters:
        type - type to test
        Returns:
        true if type is a number type, false otherwise
      • isStringType

        public static boolean isStringType​(Class type)
        Returns true if type is a string type

        This can be true for static, arrays and dynamic types.

        Parameters:
        type - type to test
        Returns:
        true if type is a string type, false otherwise
      • isBooleanType

        public static boolean isBooleanType​(Class type)
        Returns true if type is a boolean type

        This can be true for static, arrays and dynamic types.

        Parameters:
        type - type to test
        Returns:
        true if type is a boolean type, false otherwise
      • isDynamicType

        public static boolean isDynamicType​(Class type)
        Returns true if type is a dynamic type.
        Parameters:
        type - type to test
        Returns:
        true if type is a dynamic type, false otherwise
      • isSimpleType

        public static boolean isSimpleType​(Class type)
        Returns true if type is a simple type.

        Simple types are primitives, String and wrapper types (e.g. Integer).

        Parameters:
        type - type to test
        Returns:
        true if type is a simple type, false otherwise
      • isArrayType

        public static boolean isArrayType​(Class type)
        Returns true if type is an array type.
        Parameters:
        type - type to test
        Returns:
        true if type is an array type, false otherwise
      • isCollectionType

        public static boolean isCollectionType​(Class type)
        Returns true if type is a collection type.

        Collection types are either List or Set.

        Parameters:
        type - type to test
        Returns:
        true if type is a collection type, false otherwise
      • isMapType

        public static boolean isMapType​(Class type)
        Returns true if type is a map type.

        Collection types implement the Map interface.

        Parameters:
        type - type to test
        Returns:
        true if type is a map type, false otherwise
      • getTypeName

        public static String getTypeName​(Class type)
        Returns the type name for the given type.
        Parameters:
        type - type to get its name
        Returns:
        type name
      • parseDateTime

        public static double parseDateTime​(String dateTime,
                                           org.joda.time.DateTimeZone timeZone)
        Parses the given time and returns its milliseconds representation.
        Parameters:
        dateTime - type to parse
        timeZone - time zone to use or null to use default time zone (UTC)
        Returns:
        milliseconds representation
      • parseDateTime

        public static double parseDateTime​(String dateTime)
        Parses the given time and returns its milliseconds representation. Default time zone is used (UTC).
        Parameters:
        dateTime - the type to parse
        Returns:
        milliseconds representation
      • parseDateTimeOrTimestamp

        public static double parseDateTimeOrTimestamp​(String timeStr,
                                                      org.joda.time.DateTimeZone timeZone)
        Parses an ISO date with or without time or a timestamp (in milliseconds). Returns the date or timestamp converted to a timestamp in milliseconds.
        Parameters:
        timeStr - Date or timestamp string
        timeZone - Time zone to use or null to use default time zone (UTC)
        Returns:
        Timestamp
      • parseDateTimeOrTimestamp

        public static double parseDateTimeOrTimestamp​(String timeStr)
        Parses an ISO date with or without time or a timestamp (in milliseconds). Returns the date or timestamp converted to a timestamp in milliseconds. Default time zone is used (UTC).
        Parameters:
        timeStr - Date or timestamp string
        Returns:
        Timestamp
      • printTimestamp

        public static String printTimestamp​(double timestamp)
        Returns the string representation of the given timestamp.
        Parameters:
        timestamp - the time, in milliseconds
        Returns:
        formatted timestamp
      • printDate

        public static String printDate​(double timestamp,
                                       org.joda.time.DateTimeZone timeZone)
        Returns the date's string representation of the given timestamp.
        Parameters:
        timestamp - time, in milliseconds
        timeZone - time zone to use or null to use default time zone (UTC)
        Returns:
        formatted date
      • printDate

        public static String printDate​(double timestamp)
        Returns the date's string representation of the given timestamp. Default time zone is used (UTC).
        Parameters:
        timestamp - time, in milliseconds
        Returns:
        formatted date
      • printDateTime

        public static String printDateTime​(double timestamp,
                                           org.joda.time.DateTimeZone timeZone)
        Returns the time's string representation of the given timestamp.
        Parameters:
        timestamp - time, in milliseconds
        timeZone - time zone to use or null to use default time zone (UTC)
        Returns:
        formatted time
      • printDateTime

        public static String printDateTime​(double timestamp)
        Returns the time's tring representation of the given timestamp. Default time zone is used (UTC).
        Parameters:
        timestamp - time, in milliseconds
        Returns:
        formatted time
      • printTimestampInFormat

        public static String printTimestampInFormat​(double timestamp,
                                                    TimeFormat timeFormat,
                                                    org.joda.time.DateTimeZone timeZone)
        Returns the string representation of the given timestamp in the given format.
        Parameters:
        timestamp - time, in milliseconds
        timeFormat - time format
        timeZone - time zone to use or null to use default time zone (UTC).
        Returns:
        formatted timestamp
      • printTimestampInFormat

        public static String printTimestampInFormat​(double timestamp,
                                                    TimeFormat timeFormat)
        Returns the string representation of the given timestamp in the given format. Default time zone is used (UTC).
        Parameters:
        timestamp - time, in milliseconds
        timeFormat - time format
        Returns:
        formatted timestamp
      • printArray

        public static String printArray​(Object arr)
        Returns the string representation of the given array. The used format is the same format supported by parse(java.lang.String, java.lang.Class) method
        Parameters:
        arr - Input array. Can be an array of objects or primitives.
        Returns:
        formatted array
      • isNodeColumn

        public static boolean isNodeColumn​(Column colum)
        Returns true if the given column is a node column.
        Parameters:
        colum - column to test
        Returns:
        true if the column is a node column, false otherwise
      • isEdgeColumn

        public static boolean isEdgeColumn​(Column colum)
        Returns true if the given column is an edge column.
        Parameters:
        colum - column to test
        Returns:
        true if the column is an edge column, false otherwise