Days ago, when I tried to set a property to a vertex by using:
vertex.property("colored", color);
It seems very straight forword, but actually I met this error:
Exception in thread “main” java.lang.AbstractMethodError: Method ….
Googled but no answers.
In the Javadoc:
default VertexProperty property(String key, V value, Object… keyValues)
//Set the provided key to the provided value using default VertexProperty.Cardinality for that key.
VertexProperty.Cardinality has three types: list, set and single.
If you want to set only one property, then use single only. I did not try in person about list and set.In my example, the first parameter can be eliminated. After the Cardinality, there is the key and value pair.
Well, make sure you are using:
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
Get properties and make changes:
//... if(graph.vertices(1).hasNext()){ Iterator<VertexProperty<Double>> properties = graph.vertices(1).next().properties(); while (properties.hasNext()) { VertexProperty<Double> vProperty = properties.next(); System.out.println(vProperty.toString()); } System.out.println("Get "+graph.vertices(1).next().property("colored")); graph.vertices(1).next().property(VertexProperty.Cardinality.single,"colored",true); System.out.println("After "+graph.vertices(1).next().property("colored")); }
OutPut:
vp[weight->234.26392670343824]
vp[colored->false]
Get vp[colored->false]
After vp[colored->true]
Use if statement to check the value of a given id property. Do not forget to use value( ).
if(graph.vertices(1).next().property("colored").value().equals(true)){ System.out.println("True"); }else{ System.out.println("False"); }
In the example, the datatype is boolean.