Package com.graphaware.common.util
Class EntityUtils
- java.lang.Object
-
- com.graphaware.common.util.EntityUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
deleteNodeAndRelationships(Node toDelete)
Delete a node, but delete all its relationships first.static <T extends Entity>
Map<Long,T>entitiesToMap(Collection<T> entities)
static float
getFloat(Entity Entity, String key)
Get a property from the given entity as float.static float
getFloat(Entity Entity, String key, float defaultValue)
Get a property from the given entity as float.static int
getInt(Entity Entity, String key)
Get a property from the given entity as int.static int
getInt(Entity Entity, String key, int defaultValue)
Get a property from the given entity as int.static long
getLong(Entity Entity, String key)
Get a property from the given entity as long.static long
getLong(Entity Entity, String key, long defaultValue)
Get a property from the given entity as long.static Long[]
ids(Iterable<? extends Entity> entities)
static String
nodeToString(Node node)
Convert aNode
to a human-readable String.static Map<String,Object>
propertiesToMap(Entity Entity)
static Map<String,Object>
propertiesToMap(Entity Entity, ObjectInclusionPolicy<String> propertyInclusionPolicy)
static String
propertiesToString(Entity Entity)
Convert aEntity
to a human-readable String.static String
relationshipToString(Relationship relationship)
Convert aRelationship
to a human-readable String.static String
valueToString(Object value)
Convert a property value to String.
-
-
-
Method Detail
-
entitiesToMap
public static <T extends Entity> Map<Long,T> entitiesToMap(Collection<T> entities)
-
ids
public static Long[] ids(Iterable<? extends Entity> entities)
- Parameters:
entities
- to get ID from. Must be anIterable
ofNode
s orRelationship
s.- Returns:
- IDs
- Throws:
IllegalStateException
- in case one of the entities is not aNode
or aRelationship
.
-
valueToString
public static String valueToString(Object value)
Convert a property value to String. If the value isnull
, then it will be converted to an empty String.- Parameters:
value
- to convert.- Returns:
- property value as String.
-
propertiesToMap
public static Map<String,Object> propertiesToMap(Entity Entity)
Convert all properties from aEntity
to aMap
, where the key is the property key and value is the property value. Keys must not benull
or empty.Null
values are fine.- Parameters:
Entity
- to convert properties from.- Returns:
- converted properties.
-
propertiesToMap
public static Map<String,Object> propertiesToMap(Entity Entity, ObjectInclusionPolicy<String> propertyInclusionPolicy)
Convert selected properties from aEntity
to aMap
, where the key is the property key and value is the property value. Keys must not benull
or empty.Null
values are fine.- Parameters:
Entity
- to convert properties from.propertyInclusionPolicy
- policy to select which properties to include. Decides based on the property key.- Returns:
- converted properties.
-
deleteNodeAndRelationships
public static int deleteNodeAndRelationships(Node toDelete)
Delete a node, but delete all its relationships first. This method assumes a transaction is in progress.- Parameters:
toDelete
- node to delete along with its relationships.- Returns:
- number of deleted relationships.
-
nodeToString
public static String nodeToString(Node node)
Convert aNode
to a human-readable String.- Parameters:
node
- to convert.- Returns:
- node as String.
-
relationshipToString
public static String relationshipToString(Relationship relationship)
Convert aRelationship
to a human-readable String.- Parameters:
relationship
- to convert.- Returns:
- relationship as String.
-
propertiesToString
public static String propertiesToString(Entity Entity)
Convert aEntity
to a human-readable String.- Parameters:
Entity
- to convert.- Returns:
- entity as String.
-
getInt
public static int getInt(Entity Entity, String key)
Get a property from the given entity as int.- Parameters:
Entity
- to get property from.key
- key of the property.- Returns:
- value.
- Throws:
ClassCastException
- if value isn't a number.NotFoundException
- if the property doesn't exist.
-
getInt
public static int getInt(Entity Entity, String key, int defaultValue)
Get a property from the given entity as int.- Parameters:
Entity
- to get property from.key
- key of the property.defaultValue
- value returned if property does not exist.- Returns:
- value.
- Throws:
ClassCastException
- if value isn't a number.
-
getLong
public static long getLong(Entity Entity, String key)
Get a property from the given entity as long.- Parameters:
Entity
- to get property from.key
- key of the property.- Returns:
- value.
- Throws:
ClassCastException
- if value isn't a number.NotFoundException
- if the property doesn't exist.
-
getLong
public static long getLong(Entity Entity, String key, long defaultValue)
Get a property from the given entity as long.- Parameters:
Entity
- to get property from.key
- key of the property.defaultValue
- value returned if property does not exist.- Returns:
- value.
- Throws:
ClassCastException
- if value isn't a number.
-
getFloat
public static float getFloat(Entity Entity, String key)
Get a property from the given entity as float.- Parameters:
Entity
- to get property from.key
- key of the property.- Returns:
- value.
- Throws:
ClassCastException
- if value isn't a number.NotFoundException
- if the property doesn't exist.
-
getFloat
public static float getFloat(Entity Entity, String key, float defaultValue)
Get a property from the given entity as float.- Parameters:
Entity
- to get property from.key
- key of the property.defaultValue
- value returned if property does not exist.- Returns:
- value.
- Throws:
ClassCastException
- if value isn't a number.
-
-