[Java] Creating a copy of a Vertex

442 views
Skip to first unread message

Mark McKnight

unread,
Mar 13, 2013, 12:14:32 PM3/13/13
to gremli...@googlegroups.com
Hi all,

At a point in my application I need to send a copy of a Vertex with some properties excluded to another method.  

I haven't found a way to clone a Vertex or create a copy without creating a new graph first which seems wasteful.

Is there a better way to do this that I am missing?

Here's some code:

if (hasPrivate) {
TinkerGraph copyGraph = new TinkerGraph();
Vertex vertexCopy = copyGraph.addVertex(v.getId());
for (String key : v.getPropertyKeys()) {
if (! key.startsWith("private")) {
vertexCopy.setProperty(key, v.getProperty(key));
}
}
vertices.add(vertexCopy);
} else {
vertices.add(v);
}

Thanks,

Mark.

Alfredo Serafini

unread,
Mar 13, 2013, 2:08:30 PM3/13/13
to gremli...@googlegroups.com
sorry i don't think i correctly understand the question: why can't you do the same on your real graph?

Mark McKnight

unread,
Mar 13, 2013, 2:19:11 PM3/13/13
to gremli...@googlegroups.com
Well, one reason is that would trigger an unwanted onVertexAdded event.

I've thought it over and think I may be going about the whole process wrong.  I need to present different views of the graph to different users: hiding certain elements or element properties based on the user's privileges.

I think I should be using pipes to send a filtered graph on to the client.  Can anyone point me in the right direction?

Mark.

pShah

unread,
Mar 13, 2013, 4:12:06 PM3/13/13
to gremli...@googlegroups.com
Does it have to be a Vertex??

If not you can create your class.
To copy the the properties use com.tinkerpop.blueprints.util.ElementHelper.getProperties

Using Guava filter the keys:
Maps.filterKeys(properties, Predicates.not(Predicates.in(reservedProperties)))

Stephen Mallette

unread,
Mar 13, 2013, 9:18:42 PM3/13/13
to gremli...@googlegroups.com
Not completely sure what you are trying to accomplish, but it sounds
like you want to create a subgraph of some sort. Not sure if you need
to drop down to the Pipes level for what you are doing, but I
typically write some Gremlin to write graph elements to an in-memory
TinkerGraph. From there, there are lots of options: dump the whole
subgraph to GraphML, execute localized Gremlin against the
TinkerGraph, etc.

Stephen
> --
> You received this message because you are subscribed to the Google Groups
> "Gremlin-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to gremlin-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages