Class AttributeUtils
- java.lang.Object
-
- org.gephi.graph.api.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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Objectcopy(Object obj)Returns a copy of the provided object.static Class<? extends IntervalMap>getIntervalMapType(Class type)Returns the dynamic timestamp map value type for the given type.static ObjectgetPrimitiveArray(Object[] array)Returns the primitive array given a wrapped primitive array.static ClassgetPrimitiveType(Class type)Returns the primitive type for the given wrapped primitive.static ClassgetStandardizedType(Class type)Returns the standardized type for the given type class.static ClassgetStaticType(Class<? extends TimeMap> type)Returns the static type for the given time map type.static Set<Class>getSupportedTypes()Returns the set of types supported.static Class<? extends TimestampMap>getTimestampMapType(Class type)Returns the dynamic timestamp map value type for the given type.static StringgetTypeName(Class type)Returns the type name for the given type.static booleanisArrayType(Class type)Returns true if type is an array type.static booleanisBooleanType(Class type)Returns true if type is a boolean typestatic booleanisCollectionType(Class type)Returns true if type is a collection type.static booleanisDynamicType(Class type)Returns true if type is a dynamic type.static booleanisEdgeColumn(Column colum)Returns true if the given column is an edge column.static booleanisMapType(Class type)Returns true if type is a map type.static booleanisNodeColumn(Column colum)Returns true if the given column is a node column.static booleanisNumberType(Class type)Returns true if type is a number type.static booleanisSimpleType(Class type)Returns true if type is a simple type.static booleanisStandardizedType(Class type)Returns true if type is a standardized type.static booleanisStringType(Class type)Returns true if type is a string typestatic booleanisSupported(Class type)Returns true if type is a supported type.static Objectparse(String str, Class typeClass)Parses the given string using the type class provided and returns an instance.static Objectparse(String str, Class typeClass, ZoneId zoneId)Parses the given string using the type class provided and returns an instance.static doubleparseDateTime(String dateTime)Parses the given time and returns its milliseconds representation.static doubleparseDateTime(String dateTime, ZoneId zoneId)Parses the given time and returns its milliseconds representation.static doubleparseDateTimeOrTimestamp(String timeStr)Parses an ISO date with or without time or a timestamp (in milliseconds).static doubleparseDateTimeOrTimestamp(String timeStr, ZoneId zoneId)Parses an ISO date with or without time or a timestamp (in milliseconds).static Stringprint(Object value)Returns the string representation of the given value.static Stringprint(Object value, TimeFormat timeFormat, ZoneId zoneId)Returns the string representation of the given value.static StringprintArray(Object arr)Returns the string representation of the given array.static StringprintDate(double timestamp)Returns the date's string representation of the given timestamp.static StringprintDate(double timestamp, ZoneId zoneId)Returns the date's string representation of the given timestamp.static StringprintDate(Instant instant, ZoneId zoneId)Returns the date's string representation of the given instant.static StringprintDateTime(double timestamp)Returns the time's string representation of the given timestamp.static StringprintDateTime(double timestamp, ZoneId zoneId)Returns the time's string representation of the given timestamp.static StringprintDateTime(Instant instant, ZoneId zoneId)Returns the time's string representation of the given instant.static StringprintTimestamp(double timestamp)Returns the string representation of the given timestamp.static StringprintTimestampInFormat(double timestamp, TimeFormat timeFormat)Returns the string representation of the given timestamp in the given format.static StringprintTimestampInFormat(double timestamp, TimeFormat timeFormat, ZoneId zoneId)Returns the string representation of the given timestamp in the given format.static ObjectstandardizeValue(Object value)Transform the given value instance in a standardized type if necessary.
-
-
-
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, ZoneId zoneId)
Returns the string representation of the given value.- Parameters:
value- valuetimeFormat- time formatzoneId- time zone- Returns:
- string representation
-
parse
public static Object parse(String str, Class typeClass, ZoneId zoneId)
Parses the given string using the type class provided and returns an instance.- Parameters:
str- string to parsetypeClass- class of the desired typezoneId- time zone to use or null to use default time zone (UTC), for dynamic types andInstantonly- 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 parsetypeClass- 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 returnInteger.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 typeThis 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 typeThis 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, ZoneId zoneId) throws DateTimeParseException
Parses the given time and returns its milliseconds representation.- Parameters:
dateTime- type to parsezoneId- time zone to use or null to use default time zone (UTC)- Returns:
- milliseconds representation
- Throws:
DateTimeParseException- if the time cannot be parsed
-
parseDateTime
public static double parseDateTime(String dateTime) throws DateTimeParseException
Parses the given time and returns its milliseconds representation. Default time zone is used (UTC).- Parameters:
dateTime- the type to parse- Returns:
- milliseconds representation
- Throws:
DateTimeParseException- if the time cannot be parsed
-
parseDateTimeOrTimestamp
public static double parseDateTimeOrTimestamp(String timeStr, ZoneId zoneId) throws DateTimeParseException
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 stringzoneId- Time zone to use or null to use default time zone (UTC)- Returns:
- Timestamp
- Throws:
DateTimeParseException- if the time cannot be parsed
-
parseDateTimeOrTimestamp
public static double parseDateTimeOrTimestamp(String timeStr) throws DateTimeParseException
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
- Throws:
DateTimeParseException- if the time cannot be parsed
-
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, ZoneId zoneId)
Returns the date's string representation of the given timestamp.- Parameters:
timestamp- time, in millisecondszoneId- time zone to use or null to use default time zone (UTC)- Returns:
- formatted date
-
printDate
public static String printDate(Instant instant, ZoneId zoneId)
Returns the date's string representation of the given instant.- Parameters:
instant- instant to formatzoneId- 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, ZoneId zoneId)
Returns the time's string representation of the given timestamp.- Parameters:
timestamp- time, in millisecondszoneId- time zone to use or null to use default time zone (UTC)- Returns:
- formatted time
-
printDateTime
public static String printDateTime(Instant instant, ZoneId zoneId)
Returns the time's string representation of the given instant.- Parameters:
instant- instant to formatzoneId- 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 string 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, ZoneId zoneId)
Returns the string representation of the given timestamp in the given format.- Parameters:
timestamp- time, in millisecondstimeFormat- time formatzoneId- 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 millisecondstimeFormat- 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 byparse(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
-
copy
public static Object copy(Object obj)
Returns a copy of the provided object.The copy is a deep copy for arrays,
IntervalSet,TimestampSet, sets and lists- Parameters:
obj- object to copy- Returns:
- copy of the provided object
-
-