Skip to content

Instantly share code, notes, and snippets.

@okram
Created February 5, 2014 17:03
Show Gist options
  • Save okram/8828362 to your computer and use it in GitHub Desktop.
Save okram/8828362 to your computer and use it in GitHub Desktop.
//////////////////////////////////
///////// BLUEPRINTS ////////////
/////////////////////////////////
public interface Graph {
public <S, A extends Flow<A, S, Vertex>> A V();
...
}
public interface Flow<A extends Flow, S, E> {
public A has(String key, Object value);
public A out();
public A value(String key);
}
public class GremlinFlow<S, E> implements Flow<GremlinFlow, S, E> {
public GremlinFlow has(String key, Object value) {
return this;
}
public GremlinFlow out() {
return this;
}
public GremlinFlow value(String key) {
return this;
}
}
//////////////////////////////////
///////// TINKERGRAPH ////////////
//////////////////////////////////
public class TinkerGraph {
public <S, A extends Flow<A, S, Vertex>> A V() {
return (A) new GremlinFlow<S, Vertex>();
}
...
}
/// EXAMPLE TEST -- RETURNS NOTHING, BUT DEMONSTRATES THE FUNCTION CHAINING OFF g.V()
@Test
public void shouldFlow() {
Graph g = TinkerFactory.createClassic();
g.V().has("name","marko").out();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment