Skip to content

Commit

Permalink
Restored other elements of the example schema; added more usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
laughedelic committed Apr 4, 2016
1 parent 74d326f commit f53992d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 52 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/bio4j/angulillos/GraphSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public abstract class Edge<
> {

protected Edge(RE raw, EdgeType<S,E,T> type) { super(raw, type); }
// @Override public E self() { return this; }
}

public abstract class EdgeType<
Expand All @@ -118,7 +117,7 @@ protected EdgeType(VertexType<S> sourceType, VertexType<T> targetType) {
this.targetType = targetType;
}

// @Override public E fromRaw(RE raw) { return new Edge<ST,ET,TT>(raw, self()); }
@Override public EdgeType<S,E,T> self() { return this; }
}

}
98 changes: 51 additions & 47 deletions src/test/java/com/bio4j/angulillos/Twitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,71 @@ public abstract class Twitter<RV,RE>

/* ### Vertices and their types */

public final UserT user = new UserT();
public final class UserT extends VertexType<User> {
@Override public User fromRaw(RV raw) { return new User(raw); }

public final Property<String> name = property("name", String.class);
public final Property<Integer> age = property("age", Integer.class);
}

public final class User extends Vertex<User> {
@Override public User self() { return this; }
protected User(RV raw) { super(raw, user); }
@Override public final User self() { return this; } private User(RV raw) { super(raw, user); }

// public class Type extends Vertex<User>.Type {
// // @Override public User fromRaw(RV raw) { return new User().withRaw(raw); }
// @Override public User fromRaw(RV raw) { return new User(raw); }
// // @Override public User fromRaw(RV raw) { return new User().withRaw(raw); } // @Override public User fromRaw(RV raw) { return new User(raw); }
//
// public final Property<String> name = property("name", String.class);
// public final Property<Integer> age = property("age", Integer.class);
// }
}
// public final User.Type user = new User(null).new Type();

public final UserType user = new UserType();
public final class UserType extends VertexType<User> {
@Override public final User fromRaw(RV raw) { return new User(raw); }

public final Property<String> name = property("name", String.class);
public final Property<Integer> age = property("age", Integer.class);
}


public final class Tweet extends Vertex<Tweet> {
@Override public final Tweet self() { return this; }
private Tweet(RV raw) { super(raw, tweet); }
}

public final TweetType tweet = new TweetType();
public final class TweetType extends VertexType<Tweet> {
@Override public final Tweet fromRaw(RV raw) { return new Tweet(raw); }

// public final Tweet tweet = new Tweet();
// public final class Tweet extends VertexType<Tweet> {
// @Override public Tweet self() { return this; }
//
// public Property<Tweet, String> text = property("text", String.class);
// public Property<Tweet, URL> url = property("url", URL.class);
// }
public final Property<String> text = property("text", String.class);
public final Property<URL> url = property("url", URL.class);
}


/* ### Edges and their types */

// public final Follows follows = new Follows();
// public final class Follows extends EdgeType<UserT, Follows, UserT>
// implements AnyToAny {
// @Override public Follows self() { return this; }
// Follows() { super(user, user); }
//
// public Property<Follows, Date> since = property("since", Date.class);
// }
//
// // Any tweet is posted by exactly one user, but user may post any number of tweets (incl. 0)
// public final Posted posted = new Posted();
// public final class Posted extends EdgeType<UserT, Posted, Tweet>
// implements OneToAny {
// @Override public Posted self() { return this; }
// Posted() { super(user, tweet); }
//
// public Property<Posted, Date> date = property("date", Date.class);
// }

// // A reply addresses exactly one tweet, but a tweet may not have any replies
// public final Replies replies = new Replies();
// public final class Replies extends EdgeType<Tweet, Replies, Tweet>
// implements AnyToOne {
// @Override public Replies self() { return this; }
// Replies() { super(tweet, tweet); }
//
// public Property<Replies, Date> date = property("date", Date.class);
// }
public final class Follows extends Edge<User, Follows, User> {
@Override public final Follows self() { return this; }
private Follows(RE raw) { super(raw, follows); }
}

public final FollowsType follows = new FollowsType();
public final class FollowsType extends EdgeType<User, Follows, User>
implements AnyToAny {
@Override public final Follows fromRaw(RE raw) { return new Follows(raw); }
private FollowsType() { super(user, user); }

public final Property<Date> since = property("since", Date.class);
}


public final class Posted extends Edge<User, Posted, Tweet> {
@Override public final Posted self() { return this; }
private Posted(RE raw) { super(raw, posted); }
}

// Any tweet is posted by exactly one user, but user may post any number of tweets (incl. 0)
public final PostedType posted = new PostedType();
public final class PostedType extends EdgeType<User, Posted, Tweet>
implements OneToAny {
@Override public final Posted fromRaw(RE raw) { return new Posted(raw); }
private PostedType() { super(user, tweet); }

public final Property<Date> date = property("date", Date.class);
}

}
28 changes: 25 additions & 3 deletions src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,33 @@ public abstract class TwitterGraphTestSuite<RV,RE> {

protected Twitter<RV,RE> g;

Twitter<RV,RE>.User u = g.addVertex(g.user);
//////////////////////////////////////////

Twitter<RV,RE>.User u2 = u.set(g.user.name, "bob");
// Trying to use some API and see that it returns correct type without any conversions:
Twitter<RV,RE>.User u =
g.user.fromRaw(null)
.set(g.user.name, "Bob")
.set(g.user.age, 42);

String name = u2.get(g.user.name);
String name = u.get(g.user.name);

Twitter<RV,RE>.Tweet t =
g.tweet.fromRaw(null)
.set(g.tweet.text, "blah-bluh");

//////////////////////////////////////////

// Examples with edges:

Twitter<RV,RE>.Posted p =
g.posted.fromRaw(null)
.set(g.posted.date, null);

Twitter<RV,RE>.User poster = p.source();

Stream<Twitter<RV,RE>.Follows> fe = u.outE(g.follows);

Stream<Twitter<RV,RE>.Tweet> ts = u.outV(g.posted);

// public void doSomething(Twitter<RV,RE>.User user) {
//
Expand Down

0 comments on commit f53992d

Please sign in to comment.