Class ElementHelper
- java.lang.Object
- 
- org.apache.tinkerpop.gremlin.structure.util.ElementHelper
 
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanareEqual(Edge a, Edge b)static booleanareEqual(Element a, Object b)A standard method for determining if twoElementobjects are equal.static booleanareEqual(Property a, Object b)A standard method for determining if twoPropertyobjects are equal.static booleanareEqual(VertexProperty a, Object b)A standard method for determining if twoVertexPropertyobjects are equal.static booleanareEqual(VertexProperty a, VertexProperty b)static booleanareEqual(Vertex a, Vertex b)static Map<String,Object>asMap(Object... keyValues)Converts a set of key values to a Map.static List<org.javatuples.Pair<String,Object>>asPairs(Object... keyValues)Convert a set of key values to a list of Pair objects.static voidattachProperties(Element element, Object... propertyKeyValues)Assign key/value pairs as properties to anElement.static voidattachProperties(Vertex vertex, Object... propertyKeyValues)Assign key/value pairs as properties to anVertex.static voidattachProperties(Vertex vertex, VertexProperty.Cardinality cardinality, Object... propertyKeyValues)Assign key/value pairs as properties to aVertex.static Optional<Object>getIdValue(Object... keyValues)Extracts the value of theT.idkey from the list of arguments.static Set<String>getKeys(Object... keyValues)Gets the list of keys from the key values.static Optional<String>getLabelValue(Object... keyValues)Extracts the value of theT.labelkey from the list of arguments.static Object[]getProperties(Element element, boolean includeId, boolean includeLabel, Set<String> propertiesToCopy)Retrieve the properties associated with a particular element.static inthashCode(Element element)If twoElementinstances are equal, then they must have the same hash codes.static inthashCode(Property property)If twoPropertyinstances are equal, then they must have the same hash codes.static booleanhaveEqualIds(Element a, Element b)Simply tests if the value returned fromElement.id()areequal().static booleanidExists(Object id, Object... providedIds)static booleankeyExists(String key, String... providedKeys)Checks if a key exists within a list of provided keys.static voidlegalPropertyKeyValueArray(Object... propertyKeyValues)static Map<String,Property>propertyMap(Element element, String... propertyKeys)static Map<String,Object>propertyValueMap(Element element, String... propertyKeys)static Optional<Object[]>remove(String keyToRemove, Object... keyValues)Remove a key from the set of key/value pairs.static Optional<Object[]>remove(T accessor, Object... keyValues)Removes an accessor from the set of key/value pairs.static Object[]replaceKey(Object[] keyValues, Object oldKey, Object newKey)Replaces one key with a different key.static <V> Optional<VertexProperty<V>>stageVertexProperty(Vertex vertex, VertexProperty.Cardinality cardinality, String key, V value, Object... keyValues)This is a helper method for dealing with vertex property cardinality and typically used inVertex.property(VertexProperty.Cardinality, String, Object, Object...).static Object[]upsert(Object[] keyValues, Object key, Object val)Append a key/value pair to a list of existing key/values.static voidvalidateLabel(String label)Determine whether theElementlabel can be legally set.static voidvalidateProperty(String key, Object value)Determines whether the property key/value for the specified thing can be legally set.static Map<String,List<VertexProperty>>vertexPropertyMap(Vertex vertex, String... propertyKeys)static Map<String,List>vertexPropertyValueMap(Vertex vertex, String... propertyKeys)
 
- 
- 
- 
Method Detail- 
validateLabelpublic static void validateLabel(String label) throws IllegalArgumentException Determine whether theElementlabel can be legally set. This is typically used as a pre-condition check.- Parameters:
- label- the element label
- Throws:
- IllegalArgumentException- whether the label is legal and if not, a clear reason exception is provided
 
 - 
validatePropertypublic static void validateProperty(String key, Object value) throws IllegalArgumentException Determines whether the property key/value for the specified thing can be legally set. This is typically used as a pre-condition check prior to setting a property.- Parameters:
- key- the key of the property
- value- the value of the property\
- Throws:
- IllegalArgumentException- whether the key/value pair is legal and if not, a clear reason exception message is provided
 
 - 
legalPropertyKeyValueArraypublic static void legalPropertyKeyValueArray(Object... propertyKeyValues) throws IllegalArgumentException Determines whether a list of key/values are legal, ensuring that there are an even number of values submitted and that the keys in the list of arguments areStringorTobjects.- Parameters:
- propertyKeyValues- a list of key/value pairs
- Throws:
- IllegalArgumentException- if something in the pairs is illegal
 
 - 
getIdValuepublic static Optional<Object> getIdValue(Object... keyValues) Extracts the value of theT.idkey from the list of arguments.- Parameters:
- keyValues- a list of key/value pairs
- Returns:
- the value associated with T.id
 
 - 
removepublic static Optional<Object[]> remove(String keyToRemove, Object... keyValues) Remove a key from the set of key/value pairs. Assumes that validations have already taken place to assure that key positions contain strings and that there are an even number of elements. If after removal there are no values left, the key value list is returned as empty.- Parameters:
- keyToRemove- the key to remove
- keyValues- the list to remove the accessor from
- Returns:
- the key/values without the specified accessor or an empty array if no values remain after removal
 
 - 
removepublic static Optional<Object[]> remove(T accessor, Object... keyValues) Removes an accessor from the set of key/value pairs. Assumes that validations have already taken place to assure that key positions contain strings and that there are an even number of elements. If after removal there are no values left, the key value list is returned as empty.- Parameters:
- accessor- to remove
- keyValues- the list to remove the accessor from
- Returns:
- the key/values without the specified accessor or an empty array if no values remain after removal
 
 - 
upsertpublic static Object[] upsert(Object[] keyValues, Object key, Object val) Append a key/value pair to a list of existing key/values. If the key already exists in the keyValues then that value is overwritten with the provided value.
 - 
replaceKeypublic static Object[] replaceKey(Object[] keyValues, Object oldKey, Object newKey) Replaces one key with a different key.- Parameters:
- keyValues- the list of key/values to alter
- oldKey- the key to replace
- newKey- the new key
 
 - 
asMappublic static Map<String,Object> asMap(Object... keyValues) Converts a set of key values to a Map. Assumes that validations have already taken place to assure that key positions contain strings and that there are an even number of elements.
 - 
asPairspublic static List<org.javatuples.Pair<String,Object>> asPairs(Object... keyValues) Convert a set of key values to a list of Pair objects. Assumes that validations have already taken place to assure that key positions contain strings and that there are an even number of elements.
 - 
getKeyspublic static Set<String> getKeys(Object... keyValues) Gets the list of keys from the key values.- Parameters:
- keyValues- a list of key/values pairs
 
 - 
getLabelValuepublic static Optional<String> getLabelValue(Object... keyValues) Extracts the value of theT.labelkey from the list of arguments.- Parameters:
- keyValues- a list of key/value pairs
- Returns:
- the value associated with T.label
- Throws:
- ClassCastException- if the value of the label is not a- String
- NullPointerException- if the value for the- T.labelkey is- null
 
 - 
attachPropertiespublic static void attachProperties(Element element, Object... propertyKeyValues) Assign key/value pairs as properties to anElement. If the value ofT.idorT.labelis in the set of pairs, then they are ignored.- Parameters:
- element- the graph element to assign the- propertyKeyValues
- propertyKeyValues- the key/value pairs to assign to the- element
- Throws:
- ClassCastException- if the value of the key is not a- String
- IllegalArgumentException- if the value of- elementis null
 
 - 
attachPropertiespublic static void attachProperties(Vertex vertex, Object... propertyKeyValues) Assign key/value pairs as properties to anVertex. If the value ofT.idorT.labelis in the set of pairs, then they are ignored. TheVertexProperty.Cardinalityof the key is determined from theGraph.Features.VertexFeatures.- Parameters:
- vertex- the graph vertex to assign the- propertyKeyValues
- propertyKeyValues- the key/value pairs to assign to the- element
- Throws:
- ClassCastException- if the value of the key is not a- String
- IllegalArgumentException- if the value of- elementis null
 
 - 
attachPropertiespublic static void attachProperties(Vertex vertex, VertexProperty.Cardinality cardinality, Object... propertyKeyValues) Assign key/value pairs as properties to aVertex. If the value ofT.idorT.labelis in the set of pairs, then they are ignored.- Parameters:
- vertex- the vertex to attach the properties to
- cardinality- the cardinality of the key value pair settings
- propertyKeyValues- the key/value pairs to assign to the- element
- Throws:
- ClassCastException- if the value of the key is not a- String
- IllegalArgumentException- if the value of- elementis null
 
 - 
stageVertexPropertypublic static <V> Optional<VertexProperty<V>> stageVertexProperty(Vertex vertex, VertexProperty.Cardinality cardinality, String key, V value, Object... keyValues) This is a helper method for dealing with vertex property cardinality and typically used inVertex.property(VertexProperty.Cardinality, String, Object, Object...). If the cardinality is list, simply returnOptional.empty(). If the cardinality is single, delete all existing properties of the provided key and returnOptional.empty(). If the cardinality is set, find one that has the same key/value and attached the properties to it and return it. Else, if no equal value is found, returnOptional.empty().- Type Parameters:
- V- the type of the vertex property value
- Parameters:
- vertex- the vertex to stage a vertex property for
- cardinality- the cardinality of the vertex property
- key- the key of the vertex property
- value- the value of the vertex property
- keyValues- the properties of vertex property
- Returns:
- a vertex property if it has been found in set with equal value
 
 - 
getPropertiespublic static Object[] getProperties(Element element, boolean includeId, boolean includeLabel, Set<String> propertiesToCopy) Retrieve the properties associated with a particular element. The result is a Object[] where odd indices are String keys and even indices are the values.- Parameters:
- element- the element to retrieve properties from
- includeId- include Element.ID in the key/value list
- includeLabel- include Element.LABEL in the key/value list
- propertiesToCopy- the properties to include with an empty list meaning copy all properties
- Returns:
- a key/value array of properties where odd indices are String keys and even indices are the values.
 
 - 
areEqualpublic static boolean areEqual(Element a, Object b) A standard method for determining if twoElementobjects are equal. This method should be used by anyObject.equals(Object)implementation to ensure consistent behavior. This method is used for Vertex, Edge, and VertexProperty.
 - 
areEqualpublic static boolean areEqual(VertexProperty a, VertexProperty b) 
 - 
areEqualpublic static boolean areEqual(VertexProperty a, Object b) A standard method for determining if twoVertexPropertyobjects are equal. This method should be used by anyObject.equals(Object)implementation to ensure consistent behavior.- Parameters:
- a- the first- VertexProperty
- b- the second- VertexProperty
- Returns:
- true if equal and false otherwise
 
 - 
haveEqualIdspublic static boolean haveEqualIds(Element a, Element b) Simply tests if the value returned fromElement.id()areequal().
 - 
hashCodepublic static int hashCode(Element element) If twoElementinstances are equal, then they must have the same hash codes. This methods ensures consistent hashCode values.- Parameters:
- element- the element to get the hashCode for
- Returns:
- the hash code of the element
 
 - 
hashCodepublic static int hashCode(Property property) If twoPropertyinstances are equal, then they must have the same hash codes. This methods ensures consistent hashCode values. ForVertexPropertyusehashCode(Element).- Parameters:
- property- the property to get the hashCode for
- Returns:
- the hash code of the property
 
 - 
areEqualpublic static boolean areEqual(Property a, Object b) A standard method for determining if twoPropertyobjects are equal. This method should be used by anyObject.equals(Object)implementation to ensure consistent behavior.
 - 
propertyValueMappublic static Map<String,Object> propertyValueMap(Element element, String... propertyKeys) 
 - 
propertyMappublic static Map<String,Property> propertyMap(Element element, String... propertyKeys) 
 - 
vertexPropertyValueMappublic static Map<String,List> vertexPropertyValueMap(Vertex vertex, String... propertyKeys) 
 - 
vertexPropertyMappublic static Map<String,List<VertexProperty>> vertexPropertyMap(Vertex vertex, String... propertyKeys) 
 - 
keyExistspublic static boolean keyExists(String key, String... providedKeys) Checks if a key exists within a list of provided keys. Returnsfalseif the key isnullor if theGraph.Hidden. Returnstrueif noprovidedKeysare supplied.- Parameters:
- key- must not be- null
 
 
- 
 
-