Class EntityUtils


  • public final class EntityUtils
    extends Object
    Utility methods for dealing with Entitys.
    • Method Detail

      • entitiesToMap

        public static <T extends EntityMap<Long,​T> entitiesToMap​(Collection<T> entities)
        Convert a collection of Entitys to a map of Entitys keyed by their ID.
        Type Parameters:
        T - type of the Entity.
        Parameters:
        entities - to convert.
        Returns:
        map keyed by Entity ID with the actual Entitys as values.
      • valueToString

        public static String valueToString​(Object value)
        Convert a property value to String. If the value is null, 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 a Entity to a Map, where the key is the property key and value is the property value. Keys must not be null 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 a Entity to a Map, where the key is the property key and value is the property value. Keys must not be null 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 a Node to a human-readable String.
        Parameters:
        node - to convert.
        Returns:
        node as String.
      • relationshipToString

        public static String relationshipToString​(Relationship relationship)
        Convert a Relationship to a human-readable String.
        Parameters:
        relationship - to convert.
        Returns:
        relationship as String.
      • propertiesToString

        public static String propertiesToString​(Entity Entity)
        Convert a Entity 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.