Skip to content

Instantly share code, notes, and snippets.

@okram
Created May 12, 2012 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okram/2668575 to your computer and use it in GitHub Desktop.
Save okram/2668575 to your computer and use it in GitHub Desktop.
public class ReadOnlyVertex extends ReadOnlyElement implements Vertex {
public ReadOnlyVertex(final Vertex rawVertex) {
super(rawVertex);
}
public Iterable<Edge> getInEdges(final String... labels) {
return new ReadOnlyEdgeIterable(((Vertex) this.rawElement).getInEdges(labels));
}
public Iterable<Edge> getOutEdges(final String... labels) {
return new ReadOnlyEdgeIterable(((Vertex) this.rawElement).getOutEdges(labels));
}
public Query query() {
return new WrapperQuery(((Vertex) this.rawElement).query(), new IterableFactory() {
@Override
public Iterable<Vertex> wrapVertexIterable(Iterable<Vertex> vertices) {
return new ReadOnlyVertexIterable(vertices);
}
@Override
public Iterable<Edge> wrapEdgeIterable(Iterable<Edge> edges) {
return new ReadOnlyEdgeIterable(edges);
}
});
}
}
//////////////////////////////////
public class WrapperQuery implements Query {
private final Query query;
private final IterableFactory factory;
public WrapperQuery(final Query query, final IterableFactory factory) {
this.query = query;
this.factory = factory;
}
public Query has(final String key, final Object value) {
return this.query.has(key, value);
}
public Query has(final String key, final Object value, final Compare compare) {
return this.query.has(key, value, compare);
}
public Query interval(final String key, final Object startValue, final Object endValue) {
return this.query.interval(key, startValue, endValue);
}
public Query direction(final Direction direction) {
return this.query.direction(direction);
}
public Query limit(final long limit) {
return this.query.limit(limit);
}
public Query labels(final String... labels) {
return this.query.labels(labels);
}
public long count() {
return this.query.count();
}
public Object vertexIds() {
return this.query.vertexIds();
}
public Iterable<Edge> edges() {
return factory.wrapEdgeIterable(this.query.edges());
}
public Iterable<Vertex> vertices() {
return factory.wrapVertexIterable(this.query.vertices());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment