TinkerpopGraph 02: Gremlin TinkerGraph: Set Properties Examples

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:

			Iterator<VertexProperty<Double>> properties = graph.vertices(1).next().properties();
			while (properties.hasNext()) {
				VertexProperty<Double> vProperty = properties.next();
			System.out.println("Get "+graph.vertices(1).next().property("colored"));
			System.out.println("After "+graph.vertices(1).next().property("colored"));



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( ).


In the example, the datatype is boolean.

Published by Irene

Keep calm and update blog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: