From df02607978d536b891b1511ac9d9d4d6ab380589 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 4 Apr 2016 17:55:24 +0200 Subject: [PATCH 01/28] Moved properties from types to the elements; now types don't need to be unique and can take advantage of the lambda syntax for fromRaw override --- .../com/bio4j/angulillos/GraphSchema.java | 53 ++++++++++++++----- .../java/com/bio4j/angulillos/Twitter.java | 48 +++++------------ .../angulillos/TwitterGraphTestSuite.java | 19 ++++--- 3 files changed, 67 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/GraphSchema.java b/src/main/java/com/bio4j/angulillos/GraphSchema.java index b3bb0fb..849c738 100644 --- a/src/main/java/com/bio4j/angulillos/GraphSchema.java +++ b/src/main/java/com/bio4j/angulillos/GraphSchema.java @@ -1,5 +1,7 @@ package com.bio4j.angulillos; +import java.util.function.*; + public abstract class GraphSchema< SG extends GraphSchema, @@ -38,27 +40,31 @@ protected Element(RF raw, FT type) { this.raw = raw; this.type = type; } - } - - public abstract class ElementType< - F extends Element, - FT extends ElementType, - RF - > implements TypedElement.Type { - - public abstract FT self(); public Property property(String nameSuffix, Class valueClass) { return new Property(nameSuffix, valueClass); } public class Property extends com.bio4j.angulillos.Property { + private Property(String nameSuffix, Class valueClass) { - super(self(), nameSuffix, valueClass); + super(type(), nameSuffix, valueClass); } + + X get() { return self().get(this); } + F set(X value) { return self().set(this, value); } } } + public abstract class ElementType< + F extends Element, + FT extends ElementType, + RF + > implements TypedElement.Type { + + public abstract FT self(); + } + public abstract class Vertex< V extends Vertex @@ -70,11 +76,16 @@ public abstract class Vertex< // protected abstract class Type extends VertexType {} } - public abstract class VertexType< + public class VertexType< V extends Vertex > extends ElementType, RV> implements TypedVertex.Type, SG,RV,RE> { + private final Function fromRaw; + @Override public final V fromRaw(RV raw) { return fromRaw.apply(raw); } + + public VertexType(Function fromRaw) { this.fromRaw = fromRaw; } + @Override public VertexType self() { return this; } } @@ -108,16 +119,34 @@ public abstract class EdgeType< private final VertexType sourceType; private final VertexType targetType; + private final Function fromRaw; @Override public final VertexType sourceType() { return this.sourceType; } @Override public final VertexType targetType() { return this.targetType; } - protected EdgeType(VertexType sourceType, VertexType targetType) { + protected EdgeType(VertexType sourceType, Function fromRaw, VertexType targetType) { this.sourceType = sourceType; this.targetType = targetType; + this.fromRaw = fromRaw; } @Override public EdgeType self() { return this; } + @Override public final E fromRaw(RE raw) { return fromRaw.apply(raw); } + } + public class AnyToAny< + S extends Vertex, + E extends Edge, + T extends Vertex + > extends EdgeType + implements TypedEdge.Type.AnyToAny { + + protected AnyToAny(VertexType sourceType, Function fromRaw, VertexType targetType) { + super(sourceType, fromRaw, targetType); + } + } + + // etc... + } diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index 8096579..e5d3b41 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -1,6 +1,5 @@ package com.bio4j.angulillos; -import com.bio4j.angulillos.TypedEdge.Type.*; import java.net.URL; import java.util.Date; @@ -15,70 +14,49 @@ public abstract class Twitter /* ### Vertices and their types */ public final class User extends Vertex { - @Override public final User self() { return this; } private User(RV raw) { super(raw, user); } - - // public class Type extends Vertex.Type { - // // @Override public User fromRaw(RV raw) { return new User().withRaw(raw); } // @Override public User fromRaw(RV raw) { return new User(raw); } - // - // public final Property name = property("name", String.class); - // public final Property 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 { - @Override public final User fromRaw(RV raw) { return new User(raw); } + @Override public final User self() { return this; } + private User(RV raw) { super(raw, user); } public final Property name = property("name", String.class); public final Property age = property("age", Integer.class); } + public final VertexType user = new VertexType<>(User::new); + public final class Tweet extends Vertex { @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 { - @Override public final Tweet fromRaw(RV raw) { return new Tweet(raw); } public final Property text = property("text", String.class); public final Property url = property("url", URL.class); } + public final VertexType tweet = new VertexType<>(Tweet::new); + /* ### Edges and their types */ public final class Follows extends Edge { @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 - implements AnyToAny { - @Override public final Follows fromRaw(RE raw) { return new Follows(raw); } - private FollowsType() { super(user, user); } public final Property since = property("since", Date.class); } + public final AnyToAny follows = + new AnyToAny<>(user, Follows::new, user); + public final class Posted extends Edge { @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 - implements OneToAny { - @Override public final Posted fromRaw(RE raw) { return new Posted(raw); } - private PostedType() { super(user, tweet); } public final Property date = property("date", Date.class); } + // Any tweet is posted by exactly one user, but user may post any number of tweets (incl. 0) + public final AnyToAny posted = + new AnyToAny<>(user, Posted::new, tweet); + } diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java index 3222ac8..652e9fb 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java @@ -1,7 +1,8 @@ package com.bio4j.angulillos; import java.util.stream.Stream; - +import java.net.URL; +import java.util.Date; public abstract class TwitterGraphTestSuite { @@ -12,14 +13,14 @@ public abstract class TwitterGraphTestSuite { // Trying to use some API and see that it returns correct type without any conversions: Twitter.User u = g.user.fromRaw(null) - .set(g.user.name, "Bob") - .set(g.user.age, 42); + .name.set("Bob") + .age.set(42); - String name = u.get(g.user.name); + String name = u.name.get(); Twitter.Tweet t = g.tweet.fromRaw(null) - .set(g.tweet.text, "blah-bluh"); + .text.set("blah-bluh"); ////////////////////////////////////////// @@ -27,14 +28,20 @@ public abstract class TwitterGraphTestSuite { Twitter.Posted p = g.posted.fromRaw(null) - .set(g.posted.date, null); + .date.set(null); Twitter.User poster = p.source(); + Stream.Follows> fe = u.outE(g.follows); + Stream dates = fe.map(edge -> edge.since.get()); + + Stream.Tweet> ts = u.outV(g.posted); + Stream texts = ts.map(tweet -> tweet.text.get()); + // public void doSomething(Twitter.User user) { // // Stream.Tweet> tweets = user.outV(g.posted); From b77da701c7805bb6e60eb3a425dab7587f675247 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 4 Apr 2016 19:28:56 +0200 Subject: [PATCH 02/28] Experimenting with the overrides on the level of a particular graph schema --- .../java/com/bio4j/angulillos/GraphSchema.java | 6 +++--- src/test/java/com/bio4j/angulillos/Twitter.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/GraphSchema.java b/src/main/java/com/bio4j/angulillos/GraphSchema.java index 849c738..bdfb6f5 100644 --- a/src/main/java/com/bio4j/angulillos/GraphSchema.java +++ b/src/main/java/com/bio4j/angulillos/GraphSchema.java @@ -47,12 +47,12 @@ public Property property(String nameSuffix, Class valueClass) { public class Property extends com.bio4j.angulillos.Property { - private Property(String nameSuffix, Class valueClass) { + protected Property(String nameSuffix, Class valueClass) { super(type(), nameSuffix, valueClass); } - X get() { return self().get(this); } - F set(X value) { return self().set(this, value); } + public X get() { return self().get(this); } + public F set(X value) { return self().set(this, value); } } } diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index e5d3b41..f9dac34 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -2,6 +2,7 @@ import java.net.URL; import java.util.Date; +import java.util.stream.Stream; public abstract class Twitter extends @@ -10,6 +11,20 @@ public abstract class Twitter public Twitter(UntypedGraph raw) { super(raw); } + public abstract class Vertex< + V extends Vertex + > extends GraphSchema, RV,RE>.Vertex { + + protected Vertex(RV raw, VertexType type) { super(raw, type); } + + // experimenting with override: + @Override public < + E extends TypedEdge, E,ET, ?,?, ?,RV,RE>, + ET extends TypedEdge.Type, E,ET, ?,?, ?,RV,RE> + > + Stream outE(ET edgeType) { return graph().outE(self(), edgeType); } + } + /* ### Vertices and their types */ From f598a89d40d871671c23308ea9fe6b0190604e5a Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Tue, 29 Mar 2016 01:17:15 +0200 Subject: [PATCH 03/28] Added arity-specific methods in/out-E/V methods with default implementations --- .../java/com/bio4j/angulillos/UntypedGraph.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/bio4j/angulillos/UntypedGraph.java b/src/main/java/com/bio4j/angulillos/UntypedGraph.java index 600445a..c16970e 100644 --- a/src/main/java/com/bio4j/angulillos/UntypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/UntypedGraph.java @@ -1,6 +1,7 @@ package com.bio4j.angulillos; import java.util.stream.Stream; +import java.util.Optional; /* @@ -26,13 +27,28 @@ interface UntypedGraph { /* - Get the edges of type `edgeType` _out_ of `vertex` */ Stream outE(RV vertex, String edgeLabel); + default Stream outAtLeastOneE(RV vertex, String edgeLabel) { return outE(vertex, edgeLabel); } + default Optional outAtMostOneE(RV vertex, String edgeLabel) { return outE(vertex, edgeLabel).findFirst(); } + default RE outOneE(RV vertex, String edgeLabel) { return outE(vertex, edgeLabel).findFirst().get(); } + /* - Get the _target_ vertices of the edges of type `edgeType` _out_ of `vertex` */ Stream outV(RV vertex, String edgeLabel); + default Stream outAtLeastOneV(RV vertex, String edgeLabel) { return outV(vertex, edgeLabel); } + default Optional outAtMostOneV(RV vertex, String edgeLabel) { return outV(vertex, edgeLabel).findFirst(); } + default RV outOneV(RV vertex, String edgeLabel) { return outV(vertex, edgeLabel).findFirst().get(); } + /* - Get the edges of type `edgeType` _into_ `vertex` */ Stream inE(RV vertex, String edgeLabel); + default Stream inAtLeastOneE(RV vertex, String edgeLabel) { return inE(vertex, edgeLabel); } + default Optional inAtMostOneE(RV vertex, String edgeLabel) { return inE(vertex, edgeLabel).findFirst(); } + default RE inOneE(RV vertex, String edgeLabel) { return inE(vertex, edgeLabel).findFirst().get(); } + /* - Get the _source_ vertices of the edges of type `edgeType` _into_ `vertex` */ Stream inV(RV vertex, String edgeLabel); + default Stream inAtLeastOneV(RV vertex, String edgeLabel) { return inV(vertex, edgeLabel); } + default Optional inAtMostOneV(RV vertex, String edgeLabel) { return inV(vertex, edgeLabel).findFirst(); } + default RV inOneV(RV vertex, String edgeLabel) { return inV(vertex, edgeLabel).findFirst().get(); } /* #### Methods on edges */ From c296eda27521588c6fdd84868fc7c62701bb6753 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 4 Apr 2016 19:38:05 +0200 Subject: [PATCH 04/28] Made top-level interfaces/classes public; put the test in another package to see what needs to be public --- src/main/java/com/bio4j/angulillos/GraphSchema.java | 2 +- src/main/java/com/bio4j/angulillos/QueryPredicate.java | 2 +- src/main/java/com/bio4j/angulillos/TypedEdge.java | 2 +- src/main/java/com/bio4j/angulillos/TypedEdgeIndex.java | 2 +- src/main/java/com/bio4j/angulillos/TypedElement.java | 2 +- src/main/java/com/bio4j/angulillos/TypedElementIndex.java | 2 +- src/main/java/com/bio4j/angulillos/TypedGraph.java | 2 +- src/main/java/com/bio4j/angulillos/TypedVertex.java | 2 +- src/main/java/com/bio4j/angulillos/TypedVertexIndex.java | 2 +- src/main/java/com/bio4j/angulillos/TypedVertexQuery.java | 2 +- src/main/java/com/bio4j/angulillos/UntypedGraph.java | 2 +- src/test/java/com/bio4j/angulillos/Twitter.java | 3 ++- src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java | 2 +- 13 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/GraphSchema.java b/src/main/java/com/bio4j/angulillos/GraphSchema.java index bdfb6f5..7bb4be3 100644 --- a/src/main/java/com/bio4j/angulillos/GraphSchema.java +++ b/src/main/java/com/bio4j/angulillos/GraphSchema.java @@ -142,7 +142,7 @@ public class AnyToAny< > extends EdgeType implements TypedEdge.Type.AnyToAny { - protected AnyToAny(VertexType sourceType, Function fromRaw, VertexType targetType) { + public AnyToAny(VertexType sourceType, Function fromRaw, VertexType targetType) { super(sourceType, fromRaw, targetType); } } diff --git a/src/main/java/com/bio4j/angulillos/QueryPredicate.java b/src/main/java/com/bio4j/angulillos/QueryPredicate.java index 68c7f45..2bfa1ee 100644 --- a/src/main/java/com/bio4j/angulillos/QueryPredicate.java +++ b/src/main/java/com/bio4j/angulillos/QueryPredicate.java @@ -1,6 +1,6 @@ package com.bio4j.angulillos; -interface QueryPredicate { +public interface QueryPredicate { /* This is the same as - http://thinkaurelius.github.io/titan/javadoc/current/com/thinkaurelius/titan/core/attribute/Cmp.html diff --git a/src/main/java/com/bio4j/angulillos/TypedEdge.java b/src/main/java/com/bio4j/angulillos/TypedEdge.java index 15ea3f8..1bb2aff 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdge.java +++ b/src/main/java/com/bio4j/angulillos/TypedEdge.java @@ -9,7 +9,7 @@ - `E` the edge, `ET` the edge type - `T` the target TypedVertex, `TT` the target TypedVertex type */ -interface TypedEdge < +public interface TypedEdge < // source vertex S extends TypedVertex, ST extends TypedVertex.Type, diff --git a/src/main/java/com/bio4j/angulillos/TypedEdgeIndex.java b/src/main/java/com/bio4j/angulillos/TypedEdgeIndex.java index e37a1a7..2cc49da 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdgeIndex.java +++ b/src/main/java/com/bio4j/angulillos/TypedEdgeIndex.java @@ -3,7 +3,7 @@ import java.util.Optional; import java.util.stream.Stream; -interface TypedEdgeIndex < +public interface TypedEdgeIndex < E extends TypedEdge, ET extends TypedEdge.Type, P extends Property, diff --git a/src/main/java/com/bio4j/angulillos/TypedElement.java b/src/main/java/com/bio4j/angulillos/TypedElement.java index 001705c..e23e742 100644 --- a/src/main/java/com/bio4j/angulillos/TypedElement.java +++ b/src/main/java/com/bio4j/angulillos/TypedElement.java @@ -13,7 +13,7 @@ `E` refers to the element itself, and `ET` its type. You cannot define one without defining the other. */ -interface TypedElement < +public interface TypedElement < F extends TypedElement, FT extends TypedElement.Type, G extends TypedGraph, diff --git a/src/main/java/com/bio4j/angulillos/TypedElementIndex.java b/src/main/java/com/bio4j/angulillos/TypedElementIndex.java index 6714223..de8e229 100644 --- a/src/main/java/com/bio4j/angulillos/TypedElementIndex.java +++ b/src/main/java/com/bio4j/angulillos/TypedElementIndex.java @@ -4,7 +4,7 @@ import java.util.Optional; import java.util.Collection; -interface TypedElementIndex < +public interface TypedElementIndex < // element F extends TypedElement, FT extends TypedElement.Type, diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index a0341b7..8f2b080 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -11,7 +11,7 @@ A `TypedGraph` is, unsurprisingly, the typed version of [UntypedGraph](UntypedGraph.java.md). */ -interface TypedGraph < +public interface TypedGraph < G extends TypedGraph, RV,RE > diff --git a/src/main/java/com/bio4j/angulillos/TypedVertex.java b/src/main/java/com/bio4j/angulillos/TypedVertex.java index aaee2b2..bce3dc4 100644 --- a/src/main/java/com/bio4j/angulillos/TypedVertex.java +++ b/src/main/java/com/bio4j/angulillos/TypedVertex.java @@ -9,7 +9,7 @@ A typed vertex. A vertex and its type need to be defined at the same time. The vertex keeps a reference of its type, while the type works as a factory for creating vertices with that type. */ -interface TypedVertex < +public interface TypedVertex < V extends TypedVertex, VT extends TypedVertex.Type, G extends TypedGraph, diff --git a/src/main/java/com/bio4j/angulillos/TypedVertexIndex.java b/src/main/java/com/bio4j/angulillos/TypedVertexIndex.java index c5dd256..34517cf 100644 --- a/src/main/java/com/bio4j/angulillos/TypedVertexIndex.java +++ b/src/main/java/com/bio4j/angulillos/TypedVertexIndex.java @@ -8,7 +8,7 @@ A vertex index indexes vertices of a given type through values of one of its properties. This just adds a bound on the indexed type to be a TypedVertex; see `TypedElementIndex` */ -interface TypedVertexIndex < +public interface TypedVertexIndex < V extends TypedVertex, VT extends TypedVertex.Type, P extends Property, diff --git a/src/main/java/com/bio4j/angulillos/TypedVertexQuery.java b/src/main/java/com/bio4j/angulillos/TypedVertexQuery.java index c666ee5..fe6092f 100644 --- a/src/main/java/com/bio4j/angulillos/TypedVertexQuery.java +++ b/src/main/java/com/bio4j/angulillos/TypedVertexQuery.java @@ -7,7 +7,7 @@ This two interfaces are the typed version of Blueprints `VertexQuery`. Given a node, we can use this for querying relationships of a given type in or out of that node. */ -interface VertexQueryOut < +public interface VertexQueryOut < // vertex N extends TypedVertex, NT extends TypedVertex.Type, diff --git a/src/main/java/com/bio4j/angulillos/UntypedGraph.java b/src/main/java/com/bio4j/angulillos/UntypedGraph.java index c16970e..f4733ea 100644 --- a/src/main/java/com/bio4j/angulillos/UntypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/UntypedGraph.java @@ -16,7 +16,7 @@ Properties are represented using `String`s. What the methods are supposed to do is I think pretty obvious from their names; there is anyway a short explanation for each. */ -interface UntypedGraph { +public interface UntypedGraph { /* #### Methods on vertices */ diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index f9dac34..1b77611 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -1,5 +1,6 @@ -package com.bio4j.angulillos; +package com.bio4j.angulillos.test; +import com.bio4j.angulillos.*; import java.net.URL; import java.util.Date; import java.util.stream.Stream; diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java index 652e9fb..91c822b 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java @@ -1,4 +1,4 @@ -package com.bio4j.angulillos; +package com.bio4j.angulillos.test; import java.util.stream.Stream; import java.net.URL; From 3b58628c7b67f90a735f0062f45ea534cc6c37a9 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 4 Apr 2016 19:48:11 +0200 Subject: [PATCH 05/28] Put Arity outside of the edge type --- src/main/java/com/bio4j/angulillos/Arity.java | 78 ++++++++++++++++++ .../com/bio4j/angulillos/GraphSchema.java | 2 +- .../java/com/bio4j/angulillos/TypedEdge.java | 82 +------------------ .../java/com/bio4j/angulillos/TypedGraph.java | 24 +++--- .../com/bio4j/angulillos/TypedVertex.java | 24 +++--- 5 files changed, 104 insertions(+), 106 deletions(-) create mode 100644 src/main/java/com/bio4j/angulillos/Arity.java diff --git a/src/main/java/com/bio4j/angulillos/Arity.java b/src/main/java/com/bio4j/angulillos/Arity.java new file mode 100644 index 0000000..f2d33d3 --- /dev/null +++ b/src/main/java/com/bio4j/angulillos/Arity.java @@ -0,0 +1,78 @@ +package com.bio4j.angulillos; + +interface HasArity { + + /* the arity for this edge. This corresponds to the edge between the two vertex types. */ + Arity arity(); +} + +/* + ### Arities + We have six basic arities: three for in, three for out. +*/ +public enum Arity { + + oneToOne, + oneToAtMostOne, + oneToAtLeastOne, + oneToAny, + + atMostOneToOne, + atMostOneToAtMostOne, + atMostOneToAtLeastOne, + atMostOneToAny, + + atLeastOneToOne, + atLeastOneToAtMostOne, + atLeastOneToAtLeastOne, + atLeastOneToAny, + + anyToOne, + anyToAtMostOne, + anyToAtLeastOne, + anyToAny; + + /* #### In-arities */ + + /* An edge type `e` being _surjective_ implies that calling `inV(e)` will always return some, possibly several, vertices */ + interface FromAtLeastOne extends HasArity {} + /* An edge type `e` being _from many_ implies that calling `inV(e)` will in general return more than one vertex */ + interface FromOne extends HasArity {} + /* An edge type `e` being _from one_ implies that calling `inV(e)` will return at most one vertex */ + interface FromAtMostOne extends HasArity {} + + /* #### Out-arities */ + + /* That an edge type `e` being _always defined_ implies that calling `outV(e)` will always return some, possibly several, vertices */ + interface ToAtLeastOne extends HasArity {} + /* An edge type `e` being _to many_ implies that calling `outV(e)` will in general return more than one vertex */ + interface ToOne extends HasArity {} + /* An edge type `e` being _to one_ implies that calling `outV(e)` will return at most one vertex */ + interface ToAtMostOne extends HasArity {} + + + /* + #### Arity combinations + These are all the possible combinations of the different arities. In the first line under `extends` you see those that correspond to `in`, and in the second one those that correspond to `out` + */ + interface OneToOne extends FromOne, ToOne { default Arity arity() { return Arity.oneToOne; } } + interface OneToAtMostOne extends FromOne, ToAtMostOne { default Arity arity() { return Arity.oneToAtMostOne; } } + interface OneToAtLeastOne extends FromOne, ToAtLeastOne { default Arity arity() { return Arity.oneToAtLeastOne; } } + interface OneToAny extends FromOne { default Arity arity() { return Arity.oneToAny; } } + + interface AtMostOneToOne extends FromAtMostOne, ToOne { default Arity arity() { return Arity.atMostOneToOne; } } + interface AtMostOneToAtMostOne extends FromAtMostOne, ToAtMostOne { default Arity arity() { return Arity.atMostOneToAtMostOne; } } + interface AtMostOneToAtLeastOne extends FromAtMostOne, ToAtLeastOne { default Arity arity() { return Arity.atMostOneToAtLeastOne; } } + interface AtMostOneToAny extends FromAtMostOne { default Arity arity() { return Arity.atMostOneToAny; } } + + interface AtLeastOneToOne extends FromAtLeastOne, ToOne { default Arity arity() { return Arity.atLeastOneToOne; } } + interface AtLeastOneToAtMostOne extends FromAtLeastOne, ToAtMostOne { default Arity arity() { return Arity.atLeastOneToAtMostOne; } } + interface AtLeastOneToAtLeastOne extends FromAtLeastOne, ToAtLeastOne { default Arity arity() { return Arity.atLeastOneToAtLeastOne; } } + interface AtLeastOneToAny extends FromAtLeastOne { default Arity arity() { return Arity.atLeastOneToAny; } } + + interface AnyToOne extends ToOne { default Arity arity() { return Arity.anyToOne; } } + interface AnyToAtMostOne extends ToAtMostOne { default Arity arity() { return Arity.anyToAtMostOne; } } + interface AnyToAtLeastOne extends ToAtLeastOne { default Arity arity() { return Arity.anyToAtLeastOne; } } + interface AnyToAny extends HasArity { default Arity arity() { return Arity.anyToAny; } } + +} diff --git a/src/main/java/com/bio4j/angulillos/GraphSchema.java b/src/main/java/com/bio4j/angulillos/GraphSchema.java index 7bb4be3..c993345 100644 --- a/src/main/java/com/bio4j/angulillos/GraphSchema.java +++ b/src/main/java/com/bio4j/angulillos/GraphSchema.java @@ -140,7 +140,7 @@ public class AnyToAny< E extends Edge, T extends Vertex > extends EdgeType - implements TypedEdge.Type.AnyToAny { + implements Arity.AnyToAny { public AnyToAny(VertexType sourceType, Function fromRaw, VertexType targetType) { super(sourceType, fromRaw, targetType); diff --git a/src/main/java/com/bio4j/angulillos/TypedEdge.java b/src/main/java/com/bio4j/angulillos/TypedEdge.java index 1bb2aff..ef9a629 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdge.java +++ b/src/main/java/com/bio4j/angulillos/TypedEdge.java @@ -44,12 +44,6 @@ E set(Property property, X value) { } - interface HasArity { - - /* the arity for this edge. This corresponds to the edge between the two vertex types. */ - Type.Arity arity(); - } - interface Type < // source vertex S extends TypedVertex, @@ -67,82 +61,8 @@ interface Type < TypedElement.Type, HasArity { - ST sourceType(); TT targetType(); - - - /* - ### Arities - - We have six basic arities: three for in, three for out. - */ - public enum Arity { - - oneToOne, - oneToAtMostOne, - oneToAtLeastOne, - oneToAny, - - atMostOneToOne, - atMostOneToAtMostOne, - atMostOneToAtLeastOne, - atMostOneToAny, - - atLeastOneToOne, - atLeastOneToAtMostOne, - atLeastOneToAtLeastOne, - atLeastOneToAny, - - anyToOne, - anyToAtMostOne, - anyToAtLeastOne, - anyToAny; - } - - /* #### In-arities */ - - /* An edge type `e` being _surjective_ implies that calling `inV(e)` will always return some, possibly several, vertices */ - interface FromAtLeastOne extends HasArity {} - /* An edge type `e` being _from many_ implies that calling `inV(e)` will in general return more than one vertex */ - interface FromOne extends HasArity {} - /* An edge type `e` being _from one_ implies that calling `inV(e)` will return at most one vertex */ - interface FromAtMostOne extends HasArity {} - - /* #### Out-arities */ - - /* That an edge type `e` being _always defined_ implies that calling `outV(e)` will always return some, possibly several, vertices */ - interface ToAtLeastOne extends HasArity {} - /* An edge type `e` being _to many_ implies that calling `outV(e)` will in general return more than one vertex */ - interface ToOne extends HasArity {} - /* An edge type `e` being _to one_ implies that calling `outV(e)` will return at most one vertex */ - interface ToAtMostOne extends HasArity {} - - - /* - #### Arity combinations - - These are all the possible combinations of the different arities. In the first line under `extends` you see those that correspond to `in`, and in the second one those that correspond to `out` - */ - interface OneToOne extends FromOne, ToOne { default Arity arity() { return Arity.oneToOne; } } - interface OneToAtMostOne extends FromOne, ToAtMostOne { default Arity arity() { return Arity.oneToAtMostOne; } } - interface OneToAtLeastOne extends FromOne, ToAtLeastOne { default Arity arity() { return Arity.oneToAtLeastOne; } } - interface OneToAny extends FromOne { default Arity arity() { return Arity.oneToAny; } } - - interface AtMostOneToOne extends FromAtMostOne, ToOne { default Arity arity() { return Arity.atMostOneToOne; } } - interface AtMostOneToAtMostOne extends FromAtMostOne, ToAtMostOne { default Arity arity() { return Arity.atMostOneToAtMostOne; } } - interface AtMostOneToAtLeastOne extends FromAtMostOne, ToAtLeastOne { default Arity arity() { return Arity.atMostOneToAtLeastOne; } } - interface AtMostOneToAny extends FromAtMostOne { default Arity arity() { return Arity.atMostOneToAny; } } - - interface AtLeastOneToOne extends FromAtLeastOne, ToOne { default Arity arity() { return Arity.atLeastOneToOne; } } - interface AtLeastOneToAtMostOne extends FromAtLeastOne, ToAtMostOne { default Arity arity() { return Arity.atLeastOneToAtMostOne; } } - interface AtLeastOneToAtLeastOne extends FromAtLeastOne, ToAtLeastOne { default Arity arity() { return Arity.atLeastOneToAtLeastOne; } } - interface AtLeastOneToAny extends FromAtLeastOne { default Arity arity() { return Arity.atLeastOneToAny; } } - - interface AnyToOne extends ToOne { default Arity arity() { return Arity.anyToOne; } } - interface AnyToAtMostOne extends ToAtMostOne { default Arity arity() { return Arity.anyToAtMostOne; } } - interface AnyToAtLeastOne extends ToAtLeastOne { default Arity arity() { return Arity.anyToAtLeastOne; } } - interface AnyToAny extends HasArity { default Arity arity() { return Arity.anyToAny; } } - } + } diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 8f2b080..8befca2 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -150,7 +150,7 @@ Stream outE(S source, ET edgeType) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToAtLeastOne + & Arity.ToAtLeastOne > Stream outAtLeastOneE(S source, ET edgeType) { @@ -162,7 +162,7 @@ Stream outAtLeastOneE(S source, ET edgeType) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToAtMostOne + & Arity.ToAtMostOne > Optional outAtMostOneE(S source, ET edgeType) { @@ -174,7 +174,7 @@ Optional outAtMostOneE(S source, ET edgeType) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToOne + & Arity.ToOne > E outOneE(S source, ET edgeType) { @@ -201,7 +201,7 @@ Stream inE(T vertex, ET edgeType) { default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromAtLeastOne, + & Arity.FromAtLeastOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -210,7 +210,7 @@ Stream inE(T vertex, ET edgeType) { default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromAtMostOne, + & Arity.FromAtMostOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -219,7 +219,7 @@ Stream inE(T vertex, ET edgeType) { default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromOne, + & Arity.FromOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -250,7 +250,7 @@ Stream outV(S source, ET edgeType) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToAtLeastOne, + & Arity.ToAtLeastOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -261,7 +261,7 @@ Stream outV(S source, ET edgeType) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToAtMostOne, + & Arity.ToAtMostOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -272,7 +272,7 @@ Stream outV(S source, ET edgeType) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToOne, + & Arity.ToOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -303,7 +303,7 @@ Stream inV(T target, ET edgeType) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromAtLeastOne, + & Arity.FromAtLeastOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -314,7 +314,7 @@ Stream inV(T target, ET edgeType) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromAtMostOne, + & Arity.FromAtMostOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -325,7 +325,7 @@ Stream inV(T target, ET edgeType) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromOne, + & Arity.FromOne, T extends TypedVertex, TT extends TypedVertex.Type > diff --git a/src/main/java/com/bio4j/angulillos/TypedVertex.java b/src/main/java/com/bio4j/angulillos/TypedVertex.java index bce3dc4..df1f411 100644 --- a/src/main/java/com/bio4j/angulillos/TypedVertex.java +++ b/src/main/java/com/bio4j/angulillos/TypedVertex.java @@ -76,21 +76,21 @@ V set(Property property, X value) { default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToAtLeastOne + & Arity.ToAtLeastOne > Stream outAtLeastOneE(ET edgeType) { return graph().outAtLeastOneE(self(), edgeType); } default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToAtMostOne + & Arity.ToAtMostOne > Optional outAtMostOneE(ET edgeType) { return graph().outAtMostOneE(self(), edgeType); } default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToOne + & Arity.ToOne > E outOneE(ET edgeType) { return graph().outOneE(self(), edgeType); } @@ -105,21 +105,21 @@ V set(Property property, X value) { default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromAtLeastOne + & Arity.FromAtLeastOne > Stream inAtLeastOneE(ET edgeType) { return graph().inAtLeastOneE(self(), edgeType); } default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromAtMostOne + & Arity.FromAtMostOne > Optional inAtMostOneE(ET edgeType) { return graph().inAtMostOneE(self(), edgeType); } default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromOne + & Arity.FromOne > E inOneE(ET edgeType) { return graph().inOneE(self(), edgeType); } @@ -138,7 +138,7 @@ V set(Property property, X value) { default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToAtLeastOne, + & Arity.ToAtLeastOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -147,7 +147,7 @@ V set(Property property, X value) { default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToAtMostOne, + & Arity.ToAtMostOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -156,7 +156,7 @@ V set(Property property, X value) { default < E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.ToOne, + & Arity.ToOne, T extends TypedVertex, TT extends TypedVertex.Type > @@ -177,7 +177,7 @@ V set(Property property, X value) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromAtLeastOne + & Arity.FromAtLeastOne > Stream inAtLeastOneV(ET edgeType) { return graph().inAtLeastOneV(self(), edgeType); } @@ -186,7 +186,7 @@ V set(Property property, X value) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromAtMostOne + & Arity.FromAtMostOne > Optional inAtMostOneV(ET edgeType) { return graph().inAtMostOneV(self(), edgeType); } @@ -195,7 +195,7 @@ V set(Property property, X value) { ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type - & TypedEdge.Type.FromOne + & Arity.FromOne > S inOneV(ET edgeType) { return graph().inOneV(self(), edgeType); } From 536c3de5bd2d88a65cdce57be4c7523cc4348fbb Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 4 Apr 2016 20:11:46 +0200 Subject: [PATCH 06/28] Moved all the methods from TypedGraph to the elements interfaces --- .../com/bio4j/angulillos/GraphSchema.java | 4 +- .../java/com/bio4j/angulillos/TypedEdge.java | 55 ++- .../com/bio4j/angulillos/TypedElement.java | 4 +- .../java/com/bio4j/angulillos/TypedGraph.java | 313 ------------------ .../com/bio4j/angulillos/TypedVertex.java | 204 +++++++++--- 5 files changed, 202 insertions(+), 378 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/GraphSchema.java b/src/main/java/com/bio4j/angulillos/GraphSchema.java index c993345..b8108dc 100644 --- a/src/main/java/com/bio4j/angulillos/GraphSchema.java +++ b/src/main/java/com/bio4j/angulillos/GraphSchema.java @@ -27,8 +27,6 @@ private abstract class Element< RF > implements TypedElement { - @Override public final SG graph() { return GraphSchema.this.self(); } - private final RF raw; private final FT type; @@ -62,6 +60,8 @@ public abstract class ElementType< RF > implements TypedElement.Type { + @Override public final SG graph() { return GraphSchema.this.self(); } + public abstract FT self(); } diff --git a/src/main/java/com/bio4j/angulillos/TypedEdge.java b/src/main/java/com/bio4j/angulillos/TypedEdge.java index ef9a629..d653e7d 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdge.java +++ b/src/main/java/com/bio4j/angulillos/TypedEdge.java @@ -26,24 +26,6 @@ public interface TypedEdge < extends TypedElement { - /* the source vertex of this edge */ - default S source() { return graph().source( self() ); } - - /* the target vertex of this edge */ - default T target() { return graph().target( self() ); } - - - @Override default - X get(Property property) { return graph().getProperty(self(), property); } - - @Override default - E set(Property property, X value) { - - graph().setProperty(self(), property, value); - return self(); - } - - interface Type < // source vertex S extends TypedVertex, @@ -63,6 +45,43 @@ interface Type < { ST sourceType(); TT targetType(); + + /* adds an edge; note that this method does not set any properties. As it needs to be called by vertices in possibly different graphs, all the graph bounds are free with respect to G. */ + default E addEdge(S from, T to) { + + return this.fromRaw( + graph().raw().addEdge( from.raw(), this._label(), to.raw() ) + ); + } + + } + + + /* the source vertex of this edge */ + default S source() { + return type().sourceType().fromRaw( + graph().raw().source( raw() ) + ); + } + + /* the target vertex of this edge */ + default T target() { + return type().targetType().fromRaw( + graph().raw().target( raw() ) + ); + } + + + @Override default + X get(Property property) { + return graph().raw().getPropertyE(raw(), property._label); + } + + @Override default + E set(Property property, X value) { + + graph().raw().setPropertyE(raw(), property._label, value); + return self(); } } diff --git a/src/main/java/com/bio4j/angulillos/TypedElement.java b/src/main/java/com/bio4j/angulillos/TypedElement.java index e23e742..35452e0 100644 --- a/src/main/java/com/bio4j/angulillos/TypedElement.java +++ b/src/main/java/com/bio4j/angulillos/TypedElement.java @@ -32,6 +32,8 @@ interface Type < G extends TypedGraph, RF > { + G graph(); + /* Constructs a value of the typed element of this type */ F fromRaw(RF rawElem); @@ -50,7 +52,7 @@ interface Type < RF raw(); /* The graph in which this element lives. */ - G graph(); + default G graph() { return type().graph(); } /* The `get` method lets you get the value of a `property` which this element has. For that, you pass as an argument the [property](Property.java.md). Note that the type bounds only allow properties of this element. */ X get(Property property); diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 8befca2..5f8d67d 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -16,319 +16,6 @@ public interface TypedGraph < RV,RE > { - UntypedGraph raw(); - default < - V extends TypedVertex, - VT extends TypedVertex.Type - > - V addVertex(VT vertexType) { - - return vertexType.fromRaw( - raw().addVertex( vertexType._label() ) - ); - } - - /* adds an edge; note that this method does not set any properties. As it needs to be called by vertices in possibly different graphs, all the graph bounds are free with respect to G. */ - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type, - T extends TypedVertex, - TT extends TypedVertex.Type - > - E addEdge(S from, ET edgeType, T to) { - - return edgeType.fromRaw( - raw().addEdge( from.raw(), edgeType._label(), to.raw() ) - ); - } - - /* - ### properties - foobarbuh - These methods are used for setting and getting properties on vertices and edges. - */ - default < - V extends TypedVertex, - VT extends TypedVertex.Type, - X - > - X getProperty(V vertex, Property property) { - - return raw().getPropertyV(vertex.raw(), property._label); - } - - /* Get the value of a property from an edge of G. */ - default < - E extends TypedEdge, - ET extends TypedEdge.Type, - X - > - X getProperty(E edge, Property property) { - - return raw().getPropertyE(edge.raw(), property._label); - } - - /* Sets the value of a property for a vertex of G. */ - default < - V extends TypedVertex, - VT extends TypedVertex.Type, - X - > - G setProperty(V vertex, Property property, X value) { - - raw().setPropertyV(vertex.raw(), property._label, value); - return vertex.graph(); - } - - /* Sets the value of a property for an edge of G. */ - default < - E extends TypedEdge, - ET extends TypedEdge.Type, - X - > - G setProperty(E edge, Property property, X value) { - - raw().setPropertyE(edge.raw(), property._label, value); - return edge.graph(); - } - - /* - ### source and target - - gets the source of an edge of G, which could be of a different graph. - */ - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - > - S source(E edge) { - - return edge.type().sourceType().fromRaw( - raw().source(edge.raw()) - ); - } - - default < - E extends TypedEdge, - ET extends TypedEdge.Type, - T extends TypedVertex, - TT extends TypedVertex.Type - > - T target(E edge) { - - return edge.type().targetType().fromRaw( - raw().target(edge.raw()) - ); - } - - - /* #### Outgoing edges */ - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - > - Stream outE(S source, ET edgeType) { - - return raw().outE( - source.raw(), - edgeType._label() - ).map( - edgeType::fromRaw - ); - } - - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.ToAtLeastOne - > - Stream outAtLeastOneE(S source, ET edgeType) { - - return outE(source, edgeType); - } - - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.ToAtMostOne - > - Optional outAtMostOneE(S source, ET edgeType) { - - return outE(source, edgeType).findFirst(); - } - - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.ToOne - > - E outOneE(S source, ET edgeType) { - - return outE(source, edgeType).findFirst().get(); - } - - /* #### Incoming edges */ - default < - E extends TypedEdge, - ET extends TypedEdge.Type, - T extends TypedVertex, - TT extends TypedVertex.Type - > - Stream inE(T vertex, ET edgeType) { - - return raw().inE( - vertex.raw(), - edgeType._label() - ).map( - edgeType::fromRaw - ); - } - - default < - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.FromAtLeastOne, - T extends TypedVertex, - TT extends TypedVertex.Type - > - Stream inAtLeastOneE(T target, ET edgeType) { return inE(target, edgeType); } - - default < - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.FromAtMostOne, - T extends TypedVertex, - TT extends TypedVertex.Type - > - Optional inAtMostOneE(T target, ET edgeType) { return inE(target, edgeType).findFirst(); } - - default < - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.FromOne, - T extends TypedVertex, - TT extends TypedVertex.Type - > - E inOneE(T target, ET edgeType) { return inE(target, edgeType).findFirst().get(); } - - - /* #### Outgoing vertices */ - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type, - T extends TypedVertex, - TT extends TypedVertex.Type - > - Stream outV(S source, ET edgeType) { - - return raw().outV( - source.raw(), - edgeType._label() - ).map( - edgeType.targetType()::fromRaw - ); - } - - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.ToAtLeastOne, - T extends TypedVertex, - TT extends TypedVertex.Type - > - Stream outAtLeastOneV(S source, ET edgeType) { return outV(source, edgeType); } - - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.ToAtMostOne, - T extends TypedVertex, - TT extends TypedVertex.Type - > - Optional outAtMostOneV(S source, ET edgeType) { return outV(source, edgeType).findFirst(); } - - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.ToOne, - T extends TypedVertex, - TT extends TypedVertex.Type - > - T outOneV(S source, ET edgeType) { return outV(source, edgeType).findFirst().get(); } - - - /* #### Incoming vertices */ - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type, - T extends TypedVertex, - TT extends TypedVertex.Type - > - Stream inV(T target, ET edgeType) { - - return raw().inV( - target.raw(), - edgeType._label() - ).map( - edgeType.sourceType()::fromRaw - ); - } - - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.FromAtLeastOne, - T extends TypedVertex, - TT extends TypedVertex.Type - > - Stream inAtLeastOneV(T target, ET edgeType) { return inV(target, edgeType); } - - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.FromAtMostOne, - T extends TypedVertex, - TT extends TypedVertex.Type - > - Optional inAtMostOneV(T target, ET edgeType) { return inV(target, edgeType).findFirst(); } - - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - & Arity.FromOne, - T extends TypedVertex, - TT extends TypedVertex.Type - > - S inOneV(T target, ET edgeType) { return inV(target, edgeType).findFirst().get(); } - } diff --git a/src/main/java/com/bio4j/angulillos/TypedVertex.java b/src/main/java/com/bio4j/angulillos/TypedVertex.java index df1f411..cb525bb 100644 --- a/src/main/java/com/bio4j/angulillos/TypedVertex.java +++ b/src/main/java/com/bio4j/angulillos/TypedVertex.java @@ -23,41 +23,29 @@ interface Type < VT extends TypedVertex.Type, G extends TypedGraph, RV,RE - > extends TypedElement.Type {} + > extends TypedElement.Type { + default V addVertex() { - /* - ### Create edges in/out of this vertex - - There are two methods for creating new edges, into and out of this vertex respectively. Their implementation delegates to the typed graph methods. Note that all graphs are in principle different. - */ - default < - S extends TypedVertex, - ST extends TypedVertex.Type, - E extends TypedEdge, - ET extends TypedEdge.Type - > - E addInEdge(S from, ET edgeType) { return graph().addEdge( from, edgeType, self() ); } - - default < - E extends TypedEdge, - ET extends TypedEdge.Type, - T extends TypedVertex, - TT extends TypedVertex.Type - > - E addOutEdge(ET edgeType, T to) { return graph().addEdge( self(), edgeType, to ); } + return this.fromRaw( + graph().raw().addVertex( this._label() ) + ); + } + } /* ### Properties */ @Override default - X get(Property property) { return graph().getProperty(self(), property); } + X get(Property property) { + return graph().raw().getPropertyV(this.raw(), property._label); + } @Override default V set(Property property, X value) { - graph().setProperty(self(), property, value); - return self(); + graph().raw().setPropertyV(this.raw(), property._label, value); + return this.self(); } /* @@ -66,74 +54,146 @@ V set(Property property, X value) { For when you don't know anything about the arity, we have unbounded in/out methods which return `Stream`s */ - /* #### outE */ + /* #### Outgoing edges */ default < E extends TypedEdge, ET extends TypedEdge.Type > - Stream outE(ET edgeType) { return graph().outE(self(), edgeType); } + Stream outE(ET edgeType) { + + return graph().raw().outE( + this.raw(), + edgeType._label() + ).map( + edgeType::fromRaw + ); + } default < E extends TypedEdge, ET extends TypedEdge.Type & Arity.ToAtLeastOne > - Stream outAtLeastOneE(ET edgeType) { return graph().outAtLeastOneE(self(), edgeType); } + Stream outAtLeastOneE(ET edgeType) { + + return graph().raw().outAtLeastOneE( + this.raw(), + edgeType._label() + ).map( + edgeType::fromRaw + ); + } default < E extends TypedEdge, ET extends TypedEdge.Type & Arity.ToAtMostOne > - Optional outAtMostOneE(ET edgeType) { return graph().outAtMostOneE(self(), edgeType); } + Optional outAtMostOneE(ET edgeType) { + + return graph().raw().outAtMostOneE( + this.raw(), + edgeType._label() + ).map( + edgeType::fromRaw + ); + } default < E extends TypedEdge, ET extends TypedEdge.Type & Arity.ToOne > - E outOneE(ET edgeType) { return graph().outOneE(self(), edgeType); } + E outOneE(ET edgeType) { + + return edgeType.fromRaw( + graph().raw().outOneE( + this.raw(), + edgeType._label() + ) + ); + } - /* #### inE */ + /* #### Incoming edges */ default < E extends TypedEdge, ET extends TypedEdge.Type > - Stream inE(ET edgeType) { return graph().inE(self(), edgeType); } + Stream inE(ET edgeType) { + + return graph().raw().inE( + this.raw(), + edgeType._label() + ).map( + edgeType::fromRaw + ); + } default < E extends TypedEdge, ET extends TypedEdge.Type & Arity.FromAtLeastOne > - Stream inAtLeastOneE(ET edgeType) { return graph().inAtLeastOneE(self(), edgeType); } + Stream inAtLeastOneE(ET edgeType) { + + return graph().raw().inAtLeastOneE( + this.raw(), + edgeType._label() + ).map( + edgeType::fromRaw + ); + } default < E extends TypedEdge, ET extends TypedEdge.Type & Arity.FromAtMostOne > - Optional inAtMostOneE(ET edgeType) { return graph().inAtMostOneE(self(), edgeType); } + Optional inAtMostOneE(ET edgeType) { + + return graph().raw().inAtMostOneE( + this.raw(), + edgeType._label() + ).map( + edgeType::fromRaw + ); + } default < E extends TypedEdge, ET extends TypedEdge.Type & Arity.FromOne > - E inOneE(ET edgeType) { return graph().inOneE(self(), edgeType); } + E inOneE(ET edgeType) { + + return edgeType.fromRaw( + graph().raw().inOneE( + this.raw(), + edgeType._label() + ) + ); + } ///////////////////////////////////////////////////////////////////////////////////////////////////// - /* #### outV */ + /* #### Outgoing vertices */ default < E extends TypedEdge, ET extends TypedEdge.Type, T extends TypedVertex, TT extends TypedVertex.Type > - Stream outV(ET edgeType) { return graph().outV(self(), edgeType); } + Stream outV(ET edgeType) { + + return graph().raw().outV( + this.raw(), + edgeType._label() + ).map( + edgeType.targetType()::fromRaw + ); + } default < E extends TypedEdge, @@ -142,7 +202,15 @@ V set(Property property, X value) { T extends TypedVertex, TT extends TypedVertex.Type > - Stream outAtLeastOneV(ET edgeType) { return graph().outAtLeastOneV(self(), edgeType); } + Stream outAtLeastOneV(ET edgeType) { + + return graph().raw().outAtLeastOneV( + this.raw(), + edgeType._label() + ).map( + edgeType.targetType()::fromRaw + ); + } default < E extends TypedEdge, @@ -151,7 +219,15 @@ V set(Property property, X value) { T extends TypedVertex, TT extends TypedVertex.Type > - Optional outAtMostOneV(ET edgeType) { return graph().outAtMostOneV(self(), edgeType); } + Optional outAtMostOneV(ET edgeType) { + + return graph().raw().outAtMostOneV( + this.raw(), + edgeType._label() + ).map( + edgeType.targetType()::fromRaw + ); + } default < E extends TypedEdge, @@ -160,17 +236,33 @@ V set(Property property, X value) { T extends TypedVertex, TT extends TypedVertex.Type > - T outOneV(ET edgeType) { return graph().outOneV(self(), edgeType); } + T outOneV(ET edgeType) { + + return edgeType.targetType().fromRaw( + graph().raw().outOneV( + this.raw(), + edgeType._label() + ) + ); + } - /* #### inV */ + /* #### Incoming vertices */ default < S extends TypedVertex, ST extends TypedVertex.Type, E extends TypedEdge, ET extends TypedEdge.Type > - Stream inV(ET edgeType) { return graph().inV(self(), edgeType); } + Stream inV(ET edgeType) { + + return graph().raw().inV( + this.raw(), + edgeType._label() + ).map( + edgeType.sourceType()::fromRaw + ); + } default < S extends TypedVertex, @@ -179,7 +271,15 @@ V set(Property property, X value) { ET extends TypedEdge.Type & Arity.FromAtLeastOne > - Stream inAtLeastOneV(ET edgeType) { return graph().inAtLeastOneV(self(), edgeType); } + Stream inAtLeastOneV(ET edgeType) { + + return graph().raw().inAtLeastOneV( + this.raw(), + edgeType._label() + ).map( + edgeType.sourceType()::fromRaw + ); + } default < S extends TypedVertex, @@ -188,7 +288,15 @@ V set(Property property, X value) { ET extends TypedEdge.Type & Arity.FromAtMostOne > - Optional inAtMostOneV(ET edgeType) { return graph().inAtMostOneV(self(), edgeType); } + Optional inAtMostOneV(ET edgeType) { + + return graph().raw().inAtMostOneV( + this.raw(), + edgeType._label() + ).map( + edgeType.sourceType()::fromRaw + ); + } default < S extends TypedVertex, @@ -197,6 +305,14 @@ V set(Property property, X value) { ET extends TypedEdge.Type & Arity.FromOne > - S inOneV(ET edgeType) { return graph().inOneV(self(), edgeType); } + S inOneV(ET edgeType) { + + return edgeType.sourceType().fromRaw( + graph().raw().inOneV( + this.raw(), + edgeType._label() + ) + ); + } } From 15e47fab6e4cb4147ba742c4897a80cd8ceef508 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 4 Apr 2016 20:16:37 +0200 Subject: [PATCH 07/28] Moved things from GraphSchema to the TypedGraph, made it a class --- .../com/bio4j/angulillos/GraphSchema.java | 152 ------------------ .../java/com/bio4j/angulillos/TypedGraph.java | 148 ++++++++++++++++- .../java/com/bio4j/angulillos/Twitter.java | 9 +- 3 files changed, 150 insertions(+), 159 deletions(-) delete mode 100644 src/main/java/com/bio4j/angulillos/GraphSchema.java diff --git a/src/main/java/com/bio4j/angulillos/GraphSchema.java b/src/main/java/com/bio4j/angulillos/GraphSchema.java deleted file mode 100644 index b8108dc..0000000 --- a/src/main/java/com/bio4j/angulillos/GraphSchema.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.bio4j.angulillos; - -import java.util.function.*; - - -public abstract class GraphSchema< - SG extends GraphSchema, - RV,RE -> implements TypedGraph { - - public abstract SG self(); - - private final UntypedGraph raw; - @Override public final UntypedGraph raw() { return this.raw; } - - protected GraphSchema(UntypedGraph raw) { this.raw = raw; } - - /* ### Abstract helper classes - - These inner classes are implementations of the corresponding Typed* interfaces. - They bound raw vertex/edge types that the graph is parametrized by. - */ - - private abstract class Element< - F extends Element, - FT extends ElementType, - RF - > implements TypedElement { - - private final RF raw; - private final FT type; - - @Override public final RF raw() { return this.raw; } - @Override public final FT type() { return this.type; } - - // NOTE: we cannot do the same to `self`, because `super()` constructor cannot refer to `this` - protected Element(RF raw, FT type) { - this.raw = raw; - this.type = type; - } - - public Property property(String nameSuffix, Class valueClass) { - return new Property(nameSuffix, valueClass); - } - - public class Property extends com.bio4j.angulillos.Property { - - protected Property(String nameSuffix, Class valueClass) { - super(type(), nameSuffix, valueClass); - } - - public X get() { return self().get(this); } - public F set(X value) { return self().set(this, value); } - } - } - - public abstract class ElementType< - F extends Element, - FT extends ElementType, - RF - > implements TypedElement.Type { - - @Override public final SG graph() { return GraphSchema.this.self(); } - - public abstract FT self(); - } - - - public abstract class Vertex< - V extends Vertex - > extends Element, RV> - implements TypedVertex, SG,RV,RE> { - - protected Vertex(RV raw, VertexType type) { super(raw, type); } - - // protected abstract class Type extends VertexType {} - } - - public class VertexType< - V extends Vertex - > extends ElementType, RV> - implements TypedVertex.Type, SG,RV,RE> { - - private final Function fromRaw; - @Override public final V fromRaw(RV raw) { return fromRaw.apply(raw); } - - public VertexType(Function fromRaw) { this.fromRaw = fromRaw; } - - @Override public VertexType self() { return this; } - } - - - public abstract class Edge< - S extends Vertex, - E extends Edge, - T extends Vertex - > extends Element, RE> - implements TypedEdge< - S, VertexType, - E, EdgeType, - T, VertexType, - SG,RV,RE - > { - - protected Edge(RE raw, EdgeType type) { super(raw, type); } - } - - public abstract class EdgeType< - S extends Vertex, - E extends Edge, - T extends Vertex - > extends ElementType, RE> - implements TypedEdge.Type< - S, VertexType, - E, EdgeType, - T, VertexType, - SG,RV,RE - > { - - private final VertexType sourceType; - private final VertexType targetType; - private final Function fromRaw; - - @Override public final VertexType sourceType() { return this.sourceType; } - @Override public final VertexType targetType() { return this.targetType; } - - protected EdgeType(VertexType sourceType, Function fromRaw, VertexType targetType) { - this.sourceType = sourceType; - this.targetType = targetType; - this.fromRaw = fromRaw; - } - - @Override public EdgeType self() { return this; } - @Override public final E fromRaw(RE raw) { return fromRaw.apply(raw); } - - } - - public class AnyToAny< - S extends Vertex, - E extends Edge, - T extends Vertex - > extends EdgeType - implements Arity.AnyToAny { - - public AnyToAny(VertexType sourceType, Function fromRaw, VertexType targetType) { - super(sourceType, fromRaw, targetType); - } - } - - // etc... - -} diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 5f8d67d..955af5a 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -4,6 +4,7 @@ import java.util.stream.Stream; import java.util.Optional; +import java.util.function.*; /* @@ -11,11 +12,150 @@ A `TypedGraph` is, unsurprisingly, the typed version of [UntypedGraph](UntypedGraph.java.md). */ -public interface TypedGraph < +public abstract class TypedGraph< G extends TypedGraph, RV,RE -> -{ - UntypedGraph raw(); +> { + + public abstract G self(); + + private final UntypedGraph raw; + public final UntypedGraph raw() { return this.raw; } + + protected TypedGraph(UntypedGraph raw) { this.raw = raw; } + + + /* ### Abstract helper classes + + These inner classes are implementations of the corresponding Typed* interfaces. + They bound raw vertex/edge types that the graph is parametrized by. + */ + private abstract class Element< + F extends Element, + FT extends ElementType, + RF + > implements TypedElement { + + private final RF raw; + private final FT type; + + @Override public final RF raw() { return this.raw; } + @Override public final FT type() { return this.type; } + + // NOTE: we cannot do the same to `self`, because `super()` constructor cannot refer to `this` + protected Element(RF raw, FT type) { + this.raw = raw; + this.type = type; + } + + public Property property(String nameSuffix, Class valueClass) { + return new Property(nameSuffix, valueClass); + } + + public class Property extends com.bio4j.angulillos.Property { + + protected Property(String nameSuffix, Class valueClass) { + super(type(), nameSuffix, valueClass); + } + + public X get() { return self().get(this); } + public F set(X value) { return self().set(this, value); } + } + } + + public abstract class ElementType< + F extends Element, + FT extends ElementType, + RF + > implements TypedElement.Type { + + @Override public final G graph() { return TypedGraph.this.self(); } + + public abstract FT self(); + } + + + public abstract class Vertex< + V extends Vertex + > extends Element, RV> + implements TypedVertex, G,RV,RE> { + + protected Vertex(RV raw, VertexType type) { super(raw, type); } + + // protected abstract class Type extends VertexType {} + } + + public class VertexType< + V extends Vertex + > extends ElementType, RV> + implements TypedVertex.Type, G,RV,RE> { + + private final Function fromRaw; + @Override public final V fromRaw(RV raw) { return fromRaw.apply(raw); } + + public VertexType(Function fromRaw) { this.fromRaw = fromRaw; } + + @Override public VertexType self() { return this; } + } + + + public abstract class Edge< + S extends Vertex, + E extends Edge, + T extends Vertex + > extends Element, RE> + implements TypedEdge< + S, VertexType, + E, EdgeType, + T, VertexType, + G,RV,RE + > { + + protected Edge(RE raw, EdgeType type) { super(raw, type); } + } + + public abstract class EdgeType< + S extends Vertex, + E extends Edge, + T extends Vertex + > extends ElementType, RE> + implements TypedEdge.Type< + S, VertexType, + E, EdgeType, + T, VertexType, + G,RV,RE + > { + + private final VertexType sourceType; + private final VertexType targetType; + private final Function fromRaw; + + @Override public final VertexType sourceType() { return this.sourceType; } + @Override public final VertexType targetType() { return this.targetType; } + + protected EdgeType(VertexType sourceType, Function fromRaw, VertexType targetType) { + this.sourceType = sourceType; + this.targetType = targetType; + this.fromRaw = fromRaw; + } + + @Override public EdgeType self() { return this; } + @Override public final E fromRaw(RE raw) { return fromRaw.apply(raw); } + + } + + public class AnyToAny< + S extends Vertex, + E extends Edge, + T extends Vertex + > extends EdgeType + implements Arity.AnyToAny { + + public AnyToAny(VertexType sourceType, Function fromRaw, VertexType targetType) { + super(sourceType, fromRaw, targetType); + } + } + + // etc... } diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index 1b77611..84c7296 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -7,14 +7,14 @@ public abstract class Twitter extends - GraphSchema, RV,RE> + TypedGraph, RV,RE> { public Twitter(UntypedGraph raw) { super(raw); } public abstract class Vertex< V extends Vertex - > extends GraphSchema, RV,RE>.Vertex { + > extends TypedGraph, RV,RE>.Vertex { protected Vertex(RV raw, VertexType type) { super(raw, type); } @@ -23,7 +23,10 @@ public abstract class Vertex< E extends TypedEdge, E,ET, ?,?, ?,RV,RE>, ET extends TypedEdge.Type, E,ET, ?,?, ?,RV,RE> > - Stream outE(ET edgeType) { return graph().outE(self(), edgeType); } + Stream outE(ET edgeType) { + System.out.println("This is overriden Twitter-graph specific outE"); + return outE(edgeType); + } } From 69ee46d420c57bcc8abb8fe9a63120e1e1f1b4a2 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 4 Apr 2016 20:21:28 +0200 Subject: [PATCH 08/28] Removed unused imports --- src/main/java/com/bio4j/angulillos/TypedGraph.java | 6 +----- src/test/java/com/bio4j/angulillos/Twitter.java | 2 ++ .../java/com/bio4j/angulillos/TwitterGraphTestSuite.java | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 955af5a..be413ec 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -1,10 +1,6 @@ package com.bio4j.angulillos; -import static com.bio4j.angulillos.conversions.*; - -import java.util.stream.Stream; -import java.util.Optional; -import java.util.function.*; +import java.util.function.Function; /* diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index 84c7296..a31f572 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -1,10 +1,12 @@ package com.bio4j.angulillos.test; import com.bio4j.angulillos.*; + import java.net.URL; import java.util.Date; import java.util.stream.Stream; + public abstract class Twitter extends TypedGraph, RV,RE> diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java index 91c822b..13a97ad 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java @@ -1,7 +1,6 @@ package com.bio4j.angulillos.test; import java.util.stream.Stream; -import java.net.URL; import java.util.Date; public abstract class TwitterGraphTestSuite { From 2d50894e8925e0b0c8b01ee93815398c03595d3e Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Mon, 4 Apr 2016 20:25:10 +0200 Subject: [PATCH 09/28] Removed unused self() from the ElementType, other minor cleanups --- src/main/java/com/bio4j/angulillos/TypedGraph.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index be413ec..c78bd41 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -66,8 +66,6 @@ public abstract class ElementType< > implements TypedElement.Type { @Override public final G graph() { return TypedGraph.this.self(); } - - public abstract FT self(); } @@ -77,8 +75,6 @@ public abstract class Vertex< implements TypedVertex, G,RV,RE> { protected Vertex(RV raw, VertexType type) { super(raw, type); } - - // protected abstract class Type extends VertexType {} } public class VertexType< @@ -90,8 +86,6 @@ public class VertexType< @Override public final V fromRaw(RV raw) { return fromRaw.apply(raw); } public VertexType(Function fromRaw) { this.fromRaw = fromRaw; } - - @Override public VertexType self() { return this; } } @@ -124,20 +118,18 @@ public abstract class EdgeType< private final VertexType sourceType; private final VertexType targetType; - private final Function fromRaw; @Override public final VertexType sourceType() { return this.sourceType; } @Override public final VertexType targetType() { return this.targetType; } + private final Function fromRaw; + @Override public final E fromRaw(RE raw) { return fromRaw.apply(raw); } + protected EdgeType(VertexType sourceType, Function fromRaw, VertexType targetType) { this.sourceType = sourceType; this.targetType = targetType; this.fromRaw = fromRaw; } - - @Override public EdgeType self() { return this; } - @Override public final E fromRaw(RE raw) { return fromRaw.apply(raw); } - } public class AnyToAny< From b3171a42bb4771f18d46b211ca6ed34765c4ad8b Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Thu, 7 Apr 2016 13:09:10 +0200 Subject: [PATCH 10/28] general code review From e7f016860759144253340769cc218ce8a0a11cf7 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 23 Apr 2016 20:20:36 +0200 Subject: [PATCH 11/28] Changed everything to have moar tasty boilerplate, bringing more uniformity than ever; now you vertex/edge/property have to have their own type and a corresponding val; properties are declared in the vertex/edge types --- src/main/java/com/bio4j/angulillos/Arity.java | 38 +++++------ .../java/com/bio4j/angulillos/Property.java | 8 ++- .../java/com/bio4j/angulillos/TypedEdge.java | 4 +- .../java/com/bio4j/angulillos/TypedGraph.java | 54 +++++---------- .../com/bio4j/angulillos/TypedVertex.java | 4 +- .../java/com/bio4j/angulillos/Twitter.java | 65 ++++++++++++++----- .../angulillos/TwitterGraphTestSuite.java | 14 ++-- 7 files changed, 99 insertions(+), 88 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/Arity.java b/src/main/java/com/bio4j/angulillos/Arity.java index f2d33d3..570740b 100644 --- a/src/main/java/com/bio4j/angulillos/Arity.java +++ b/src/main/java/com/bio4j/angulillos/Arity.java @@ -55,24 +55,24 @@ interface ToAtMostOne extends HasArity {} #### Arity combinations These are all the possible combinations of the different arities. In the first line under `extends` you see those that correspond to `in`, and in the second one those that correspond to `out` */ - interface OneToOne extends FromOne, ToOne { default Arity arity() { return Arity.oneToOne; } } - interface OneToAtMostOne extends FromOne, ToAtMostOne { default Arity arity() { return Arity.oneToAtMostOne; } } - interface OneToAtLeastOne extends FromOne, ToAtLeastOne { default Arity arity() { return Arity.oneToAtLeastOne; } } - interface OneToAny extends FromOne { default Arity arity() { return Arity.oneToAny; } } - - interface AtMostOneToOne extends FromAtMostOne, ToOne { default Arity arity() { return Arity.atMostOneToOne; } } - interface AtMostOneToAtMostOne extends FromAtMostOne, ToAtMostOne { default Arity arity() { return Arity.atMostOneToAtMostOne; } } - interface AtMostOneToAtLeastOne extends FromAtMostOne, ToAtLeastOne { default Arity arity() { return Arity.atMostOneToAtLeastOne; } } - interface AtMostOneToAny extends FromAtMostOne { default Arity arity() { return Arity.atMostOneToAny; } } - - interface AtLeastOneToOne extends FromAtLeastOne, ToOne { default Arity arity() { return Arity.atLeastOneToOne; } } - interface AtLeastOneToAtMostOne extends FromAtLeastOne, ToAtMostOne { default Arity arity() { return Arity.atLeastOneToAtMostOne; } } - interface AtLeastOneToAtLeastOne extends FromAtLeastOne, ToAtLeastOne { default Arity arity() { return Arity.atLeastOneToAtLeastOne; } } - interface AtLeastOneToAny extends FromAtLeastOne { default Arity arity() { return Arity.atLeastOneToAny; } } - - interface AnyToOne extends ToOne { default Arity arity() { return Arity.anyToOne; } } - interface AnyToAtMostOne extends ToAtMostOne { default Arity arity() { return Arity.anyToAtMostOne; } } - interface AnyToAtLeastOne extends ToAtLeastOne { default Arity arity() { return Arity.anyToAtLeastOne; } } - interface AnyToAny extends HasArity { default Arity arity() { return Arity.anyToAny; } } + public interface OneToOne extends FromOne, ToOne { default Arity arity() { return Arity.oneToOne; } } + public interface OneToAtMostOne extends FromOne, ToAtMostOne { default Arity arity() { return Arity.oneToAtMostOne; } } + public interface OneToAtLeastOne extends FromOne, ToAtLeastOne { default Arity arity() { return Arity.oneToAtLeastOne; } } + public interface OneToAny extends FromOne { default Arity arity() { return Arity.oneToAny; } } + + public interface AtMostOneToOne extends FromAtMostOne, ToOne { default Arity arity() { return Arity.atMostOneToOne; } } + public interface AtMostOneToAtMostOne extends FromAtMostOne, ToAtMostOne { default Arity arity() { return Arity.atMostOneToAtMostOne; } } + public interface AtMostOneToAtLeastOne extends FromAtMostOne, ToAtLeastOne { default Arity arity() { return Arity.atMostOneToAtLeastOne; } } + public interface AtMostOneToAny extends FromAtMostOne { default Arity arity() { return Arity.atMostOneToAny; } } + + public interface AtLeastOneToOne extends FromAtLeastOne, ToOne { default Arity arity() { return Arity.atLeastOneToOne; } } + public interface AtLeastOneToAtMostOne extends FromAtLeastOne, ToAtMostOne { default Arity arity() { return Arity.atLeastOneToAtMostOne; } } + public interface AtLeastOneToAtLeastOne extends FromAtLeastOne, ToAtLeastOne { default Arity arity() { return Arity.atLeastOneToAtLeastOne; } } + public interface AtLeastOneToAny extends FromAtLeastOne { default Arity arity() { return Arity.atLeastOneToAny; } } + + public interface AnyToOne extends ToOne { default Arity arity() { return Arity.anyToOne; } } + public interface AnyToAtMostOne extends ToAtMostOne { default Arity arity() { return Arity.anyToAtMostOne; } } + public interface AnyToAtLeastOne extends ToAtLeastOne { default Arity arity() { return Arity.anyToAtLeastOne; } } + public interface AnyToAny extends HasArity { default Arity arity() { return Arity.anyToAny; } } } diff --git a/src/main/java/com/bio4j/angulillos/Property.java b/src/main/java/com/bio4j/angulillos/Property.java index e03f6c4..e00c924 100644 --- a/src/main/java/com/bio4j/angulillos/Property.java +++ b/src/main/java/com/bio4j/angulillos/Property.java @@ -26,16 +26,18 @@ public class Property< X > { //implements com.bio4j.angulillos.Property { - public final String _label; + // public final String _label; + public String _label() { return getClass().getCanonicalName(); } + private final FT elementType; private final Class valueClass; public final FT elementType() { return this.elementType; } public final Class valueClass() { return this.valueClass; } - protected Property(FT elementType, String nameSuffix, Class valueClass) { + protected Property(FT elementType, Class valueClass) { this.elementType = elementType; this.valueClass = valueClass; - this._label = elementType()._label() + "." + nameSuffix; + // this._label = elementType()._label() + "." + nameSuffix; } } diff --git a/src/main/java/com/bio4j/angulillos/TypedEdge.java b/src/main/java/com/bio4j/angulillos/TypedEdge.java index d653e7d..d29ab0c 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdge.java +++ b/src/main/java/com/bio4j/angulillos/TypedEdge.java @@ -74,13 +74,13 @@ default T target() { @Override default X get(Property property) { - return graph().raw().getPropertyE(raw(), property._label); + return graph().raw().getPropertyE(raw(), property._label()); } @Override default E set(Property property, X value) { - graph().raw().setPropertyE(raw(), property._label, value); + graph().raw().setPropertyE(raw(), property._label(), value); return self(); } diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index c78bd41..4827b63 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -43,20 +43,6 @@ protected Element(RF raw, FT type) { this.raw = raw; this.type = type; } - - public Property property(String nameSuffix, Class valueClass) { - return new Property(nameSuffix, valueClass); - } - - public class Property extends com.bio4j.angulillos.Property { - - protected Property(String nameSuffix, Class valueClass) { - super(type(), nameSuffix, valueClass); - } - - public X get() { return self().get(this); } - public F set(X value) { return self().set(this, value); } - } } public abstract class ElementType< @@ -66,6 +52,18 @@ public abstract class ElementType< > implements TypedElement.Type { @Override public final G graph() { return TypedGraph.this.self(); } + + public abstract F fromRaw(RF raw); + + protected abstract FT self(); + + public abstract class Property extends com.bio4j.angulillos.Property { + + protected Property(Class valueClass) { super(self(), valueClass); } + + // public X get() { return self().get(this); } + // public F set(X value) { return self().set(this, value); } + } } @@ -77,15 +75,12 @@ public abstract class Vertex< protected Vertex(RV raw, VertexType type) { super(raw, type); } } - public class VertexType< + public abstract class VertexType< V extends Vertex > extends ElementType, RV> implements TypedVertex.Type, G,RV,RE> { - private final Function fromRaw; - @Override public final V fromRaw(RV raw) { return fromRaw.apply(raw); } - - public VertexType(Function fromRaw) { this.fromRaw = fromRaw; } + protected VertexType self() { return this; } } @@ -115,6 +110,7 @@ public abstract class EdgeType< T, VertexType, G,RV,RE > { + protected EdgeType self() { return this; } private final VertexType sourceType; private final VertexType targetType; @@ -122,28 +118,10 @@ public abstract class EdgeType< @Override public final VertexType sourceType() { return this.sourceType; } @Override public final VertexType targetType() { return this.targetType; } - private final Function fromRaw; - @Override public final E fromRaw(RE raw) { return fromRaw.apply(raw); } - - protected EdgeType(VertexType sourceType, Function fromRaw, VertexType targetType) { + protected EdgeType(VertexType sourceType, VertexType targetType) { this.sourceType = sourceType; this.targetType = targetType; - this.fromRaw = fromRaw; } } - public class AnyToAny< - S extends Vertex, - E extends Edge, - T extends Vertex - > extends EdgeType - implements Arity.AnyToAny { - - public AnyToAny(VertexType sourceType, Function fromRaw, VertexType targetType) { - super(sourceType, fromRaw, targetType); - } - } - - // etc... - } diff --git a/src/main/java/com/bio4j/angulillos/TypedVertex.java b/src/main/java/com/bio4j/angulillos/TypedVertex.java index cb525bb..a40b0e0 100644 --- a/src/main/java/com/bio4j/angulillos/TypedVertex.java +++ b/src/main/java/com/bio4j/angulillos/TypedVertex.java @@ -37,14 +37,14 @@ default V addVertex() { /* ### Properties */ @Override default X get(Property property) { - return graph().raw().getPropertyV(this.raw(), property._label); + return graph().raw().getPropertyV(this.raw(), property._label()); } @Override default V set(Property property, X value) { - graph().raw().setPropertyV(this.raw(), property._label, value); + graph().raw().setPropertyV(this.raw(), property._label(), value); return this.self(); } diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index a31f572..75a714c 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -37,23 +37,43 @@ Stream outE(ET edgeType) { public final class User extends Vertex { @Override public final User self() { return this; } private User(RV raw) { super(raw, user); } - - public final Property name = property("name", String.class); - public final Property age = property("age", Integer.class); } - public final VertexType user = new VertexType<>(User::new); + public final UserType user = new UserType(); + public final class UserType extends VertexType { + public final User fromRaw(RV raw) { return new User(raw); } + + public final name name = new name(); + public final class name extends Property { + private name() { super(String.class); } + } + + public final age age = new age(); + public final class age extends Property { + private age() { super(Integer.class); } + } + } public final class Tweet extends Vertex { @Override public final Tweet self() { return this; } private Tweet(RV raw) { super(raw, tweet); } - - public final Property text = property("text", String.class); - public final Property url = property("url", URL.class); } - public final VertexType tweet = new VertexType<>(Tweet::new); + public final TweetType tweet = new TweetType(); + public final class TweetType extends VertexType { + public final Tweet fromRaw(RV raw) { return new Tweet(raw); } + + public final text text = new text(); + public final class text extends Property { + private text() { super(String.class); } + } + + public final url url = new url(); + public final class url extends Property { + private url() { super(URL.class); } + } + } /* ### Edges and their types */ @@ -61,23 +81,34 @@ public final class Tweet extends Vertex { public final class Follows extends Edge { @Override public final Follows self() { return this; } private Follows(RE raw) { super(raw, follows); } - - public final Property since = property("since", Date.class); } - public final AnyToAny follows = - new AnyToAny<>(user, Follows::new, user); + public final FollowsType follows = new FollowsType(); + public final class FollowsType extends EdgeType implements Arity.AnyToAny { + private FollowsType() { super(user, user); } + public final Follows fromRaw(RE raw) { return new Follows(raw); } + + public final since since = new since(); + public final class since extends Property { + private since() { super(Date.class); } + } + } public final class Posted extends Edge { @Override public final Posted self() { return this; } private Posted(RE raw) { super(raw, posted); } - - public final Property date = property("date", Date.class); } - // Any tweet is posted by exactly one user, but user may post any number of tweets (incl. 0) - public final AnyToAny posted = - new AnyToAny<>(user, Posted::new, tweet); + public final PostedType posted = new PostedType(); + public final class PostedType extends EdgeType implements Arity.AnyToAny { + private PostedType() { super(user, tweet); } + public final Posted fromRaw(RE raw) { return new Posted(raw); } + + public final when when = new when(); + public final class when extends Property { + private when() { super(Date.class); } + } + } } diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java index 13a97ad..fefad35 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java @@ -12,14 +12,14 @@ public abstract class TwitterGraphTestSuite { // Trying to use some API and see that it returns correct type without any conversions: Twitter.User u = g.user.fromRaw(null) - .name.set("Bob") - .age.set(42); + .set(g.user.name, "Bob") + .set(g.user.age, 42); - String name = u.name.get(); + String name = u.get(g.user.name); Twitter.Tweet t = g.tweet.fromRaw(null) - .text.set("blah-bluh"); + .set(g.tweet.text, "blah-bluh"); ////////////////////////////////////////// @@ -27,19 +27,19 @@ public abstract class TwitterGraphTestSuite { Twitter.Posted p = g.posted.fromRaw(null) - .date.set(null); + .set(g.posted.when, null); Twitter.User poster = p.source(); Stream.Follows> fe = u.outE(g.follows); - Stream dates = fe.map(edge -> edge.since.get()); + Stream dates = fe.map(edge -> edge.get(g.follows.since)); Stream.Tweet> ts = u.outV(g.posted); - Stream texts = ts.map(tweet -> tweet.text.get()); + Stream texts = ts.map(tweet -> tweet.get(g.tweet.text)); // public void doSomething(Twitter.User user) { // From 53a70cdfa6cdda4c2f7d56858a37b26327981fcd Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sun, 24 Apr 2016 00:14:56 +0200 Subject: [PATCH 12/28] Made Property an interface which the inner class implements --- .../java/com/bio4j/angulillos/Property.java | 38 +++---------------- .../java/com/bio4j/angulillos/TypedGraph.java | 13 +++++-- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/Property.java b/src/main/java/com/bio4j/angulillos/Property.java index e00c924..6135c64 100644 --- a/src/main/java/com/bio4j/angulillos/Property.java +++ b/src/main/java/com/bio4j/angulillos/Property.java @@ -3,41 +3,15 @@ /* ## Properties - A property of the [Element](TypedElement.java.md) of type `ET`, with value type `X`. + A property of the [Element](TypedElement.java.md) of type `FT`, with value type `X`. */ -// interface Property < -// ElemType extends TypedElement.Type, -// X -// > -// { -// -// /* the element type which has this property */ -// ElemType elementType(); -// -// /* the class of the property value, so that implementing classes can create values of it */ -// Class valueClass(); -// -// /* the name of the property. By default this is the canonical name of the implementing class */ -// default String _label() { return getClass().getCanonicalName(); } -// } - -public class Property< +interface Property< FT extends TypedElement.Type, X -> { //implements com.bio4j.angulillos.Property { - - // public final String _label; - public String _label() { return getClass().getCanonicalName(); } - - private final FT elementType; - private final Class valueClass; +> { - public final FT elementType() { return this.elementType; } - public final Class valueClass() { return this.valueClass; } + default public String _label() { return getClass().getCanonicalName(); } - protected Property(FT elementType, Class valueClass) { - this.elementType = elementType; - this.valueClass = valueClass; - // this._label = elementType()._label() + "." + nameSuffix; - } + public abstract FT elementType(); + public abstract Class valueClass(); } diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 4827b63..844fc91 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -57,12 +57,17 @@ public abstract class ElementType< protected abstract FT self(); - public abstract class Property extends com.bio4j.angulillos.Property { + public abstract class Property + implements com.bio4j.angulillos.Property { - protected Property(Class valueClass) { super(self(), valueClass); } + private final Class valueClass; - // public X get() { return self().get(this); } - // public F set(X value) { return self().set(this, value); } + @Override public final FT elementType() { return self(); } + @Override public final Class valueClass() { return this.valueClass; } + + protected Property(Class valueClass) { + this.valueClass = valueClass; + } } } From 5c2707fa6445ba1f39d3439f5d3b1ee10ca3fdb2 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sun, 24 Apr 2016 00:38:20 +0200 Subject: [PATCH 13/28] Split Arity on two: From/To; Added FromArity to Property --- src/main/java/com/bio4j/angulillos/Arity.java | 82 ++++--------------- .../java/com/bio4j/angulillos/Property.java | 2 +- .../java/com/bio4j/angulillos/TypedEdge.java | 3 +- .../java/com/bio4j/angulillos/Twitter.java | 21 +++-- 4 files changed, 31 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/Arity.java b/src/main/java/com/bio4j/angulillos/Arity.java index 570740b..cdc5e8f 100644 --- a/src/main/java/com/bio4j/angulillos/Arity.java +++ b/src/main/java/com/bio4j/angulillos/Arity.java @@ -1,78 +1,26 @@ package com.bio4j.angulillos; -interface HasArity { +interface HasFromArity { Arity fromArity(); } +interface HasToArity { Arity toArity(); } - /* the arity for this edge. This corresponds to the edge between the two vertex types. */ - Arity arity(); -} - -/* - ### Arities - We have six basic arities: three for in, three for out. -*/ +/* ### Arities */ public enum Arity { - oneToOne, - oneToAtMostOne, - oneToAtLeastOne, - oneToAny, - - atMostOneToOne, - atMostOneToAtMostOne, - atMostOneToAtLeastOne, - atMostOneToAny, + One, // Exactly one: X + AtMostOne, // One or none: Optional[X] + AtLeastOne, // Non-empty list: NEList[X] + Any; // Usual list: List[X] - atLeastOneToOne, - atLeastOneToAtMostOne, - atLeastOneToAtLeastOne, - atLeastOneToAny, - - anyToOne, - anyToAtMostOne, - anyToAtLeastOne, - anyToAny; /* #### In-arities */ - - /* An edge type `e` being _surjective_ implies that calling `inV(e)` will always return some, possibly several, vertices */ - interface FromAtLeastOne extends HasArity {} - /* An edge type `e` being _from many_ implies that calling `inV(e)` will in general return more than one vertex */ - interface FromOne extends HasArity {} - /* An edge type `e` being _from one_ implies that calling `inV(e)` will return at most one vertex */ - interface FromAtMostOne extends HasArity {} + public interface FromAtLeastOne extends HasFromArity { default Arity fromArity() { return Arity.One; } } + public interface FromOne extends HasFromArity { default Arity fromArity() { return Arity.AtMostOne; } } + public interface FromAtMostOne extends HasFromArity { default Arity fromArity() { return Arity.AtLeastOne; } } + public interface FromAny extends HasFromArity { default Arity fromArity() { return Arity.Any; } } /* #### Out-arities */ - - /* That an edge type `e` being _always defined_ implies that calling `outV(e)` will always return some, possibly several, vertices */ - interface ToAtLeastOne extends HasArity {} - /* An edge type `e` being _to many_ implies that calling `outV(e)` will in general return more than one vertex */ - interface ToOne extends HasArity {} - /* An edge type `e` being _to one_ implies that calling `outV(e)` will return at most one vertex */ - interface ToAtMostOne extends HasArity {} - - - /* - #### Arity combinations - These are all the possible combinations of the different arities. In the first line under `extends` you see those that correspond to `in`, and in the second one those that correspond to `out` - */ - public interface OneToOne extends FromOne, ToOne { default Arity arity() { return Arity.oneToOne; } } - public interface OneToAtMostOne extends FromOne, ToAtMostOne { default Arity arity() { return Arity.oneToAtMostOne; } } - public interface OneToAtLeastOne extends FromOne, ToAtLeastOne { default Arity arity() { return Arity.oneToAtLeastOne; } } - public interface OneToAny extends FromOne { default Arity arity() { return Arity.oneToAny; } } - - public interface AtMostOneToOne extends FromAtMostOne, ToOne { default Arity arity() { return Arity.atMostOneToOne; } } - public interface AtMostOneToAtMostOne extends FromAtMostOne, ToAtMostOne { default Arity arity() { return Arity.atMostOneToAtMostOne; } } - public interface AtMostOneToAtLeastOne extends FromAtMostOne, ToAtLeastOne { default Arity arity() { return Arity.atMostOneToAtLeastOne; } } - public interface AtMostOneToAny extends FromAtMostOne { default Arity arity() { return Arity.atMostOneToAny; } } - - public interface AtLeastOneToOne extends FromAtLeastOne, ToOne { default Arity arity() { return Arity.atLeastOneToOne; } } - public interface AtLeastOneToAtMostOne extends FromAtLeastOne, ToAtMostOne { default Arity arity() { return Arity.atLeastOneToAtMostOne; } } - public interface AtLeastOneToAtLeastOne extends FromAtLeastOne, ToAtLeastOne { default Arity arity() { return Arity.atLeastOneToAtLeastOne; } } - public interface AtLeastOneToAny extends FromAtLeastOne { default Arity arity() { return Arity.atLeastOneToAny; } } - - public interface AnyToOne extends ToOne { default Arity arity() { return Arity.anyToOne; } } - public interface AnyToAtMostOne extends ToAtMostOne { default Arity arity() { return Arity.anyToAtMostOne; } } - public interface AnyToAtLeastOne extends ToAtLeastOne { default Arity arity() { return Arity.anyToAtLeastOne; } } - public interface AnyToAny extends HasArity { default Arity arity() { return Arity.anyToAny; } } - + public interface ToAtLeastOne extends HasToArity { default Arity toArity() { return Arity.One; } } + public interface ToOne extends HasToArity { default Arity toArity() { return Arity.AtMostOne; } } + public interface ToAtMostOne extends HasToArity { default Arity toArity() { return Arity.AtLeastOne; } } + public interface ToAny extends HasToArity { default Arity toArity() { return Arity.Any; } } } diff --git a/src/main/java/com/bio4j/angulillos/Property.java b/src/main/java/com/bio4j/angulillos/Property.java index 6135c64..0532415 100644 --- a/src/main/java/com/bio4j/angulillos/Property.java +++ b/src/main/java/com/bio4j/angulillos/Property.java @@ -8,7 +8,7 @@ interface Property< FT extends TypedElement.Type, X -> { +> extends HasFromArity { default public String _label() { return getClass().getCanonicalName(); } diff --git a/src/main/java/com/bio4j/angulillos/TypedEdge.java b/src/main/java/com/bio4j/angulillos/TypedEdge.java index d29ab0c..3274e4e 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdge.java +++ b/src/main/java/com/bio4j/angulillos/TypedEdge.java @@ -41,7 +41,8 @@ interface Type < RV,RE > extends TypedElement.Type, - HasArity + HasFromArity, + HasToArity { ST sourceType(); TT targetType(); diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index 75a714c..feaeb86 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -1,6 +1,7 @@ package com.bio4j.angulillos.test; import com.bio4j.angulillos.*; +import com.bio4j.angulillos.Arity.*; import java.net.URL; import java.util.Date; @@ -44,12 +45,12 @@ public final class UserType extends VertexType { public final User fromRaw(RV raw) { return new User(raw); } public final name name = new name(); - public final class name extends Property { + public final class name extends Property implements FromOne { private name() { super(String.class); } } public final age age = new age(); - public final class age extends Property { + public final class age extends Property implements FromAny { private age() { super(Integer.class); } } } @@ -65,12 +66,12 @@ public final class TweetType extends VertexType { public final Tweet fromRaw(RV raw) { return new Tweet(raw); } public final text text = new text(); - public final class text extends Property { + public final class text extends Property implements FromAny { private text() { super(String.class); } } public final url url = new url(); - public final class url extends Property { + public final class url extends Property implements FromOne { private url() { super(URL.class); } } } @@ -84,12 +85,14 @@ public final class Follows extends Edge { } public final FollowsType follows = new FollowsType(); - public final class FollowsType extends EdgeType implements Arity.AnyToAny { + public final class FollowsType extends EdgeType + implements FromAny, ToAny { + private FollowsType() { super(user, user); } public final Follows fromRaw(RE raw) { return new Follows(raw); } public final since since = new since(); - public final class since extends Property { + public final class since extends Property implements FromAny { private since() { super(Date.class); } } } @@ -101,12 +104,14 @@ public final class Posted extends Edge { } public final PostedType posted = new PostedType(); - public final class PostedType extends EdgeType implements Arity.AnyToAny { + public final class PostedType extends EdgeType + implements FromOne, ToAny { + private PostedType() { super(user, tweet); } public final Posted fromRaw(RE raw) { return new Posted(raw); } public final when when = new when(); - public final class when extends Property { + public final class when extends Property implements FromAny { private when() { super(Date.class); } } } From 5944d47dde5d2665440f13ea35f647fa840f2ba3 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sun, 24 Apr 2016 00:50:40 +0200 Subject: [PATCH 14/28] Added Unique and NonUnique Property types to fix the arity --- src/main/java/com/bio4j/angulillos/TypedGraph.java | 12 +++++++++++- src/test/java/com/bio4j/angulillos/Twitter.java | 12 ++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 844fc91..6d1aa75 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -57,7 +57,7 @@ public abstract class ElementType< protected abstract FT self(); - public abstract class Property + private abstract class Property implements com.bio4j.angulillos.Property { private final Class valueClass; @@ -69,6 +69,16 @@ protected Property(Class valueClass) { this.valueClass = valueClass; } } + + public abstract class UniqueProperty + extends Property implements Arity.FromAtMostOne { + protected UniqueProperty(Class valueClass) { super(valueClass); } + } + + public abstract class NonUniqueProperty + extends Property implements Arity.FromAny { + protected NonUniqueProperty(Class valueClass) { super(valueClass); } + } } diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index feaeb86..c006667 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -45,12 +45,12 @@ public final class UserType extends VertexType { public final User fromRaw(RV raw) { return new User(raw); } public final name name = new name(); - public final class name extends Property implements FromOne { + public final class name extends UniqueProperty { private name() { super(String.class); } } public final age age = new age(); - public final class age extends Property implements FromAny { + public final class age extends NonUniqueProperty { private age() { super(Integer.class); } } } @@ -66,12 +66,12 @@ public final class TweetType extends VertexType { public final Tweet fromRaw(RV raw) { return new Tweet(raw); } public final text text = new text(); - public final class text extends Property implements FromAny { + public final class text extends NonUniqueProperty { private text() { super(String.class); } } public final url url = new url(); - public final class url extends Property implements FromOne { + public final class url extends UniqueProperty { private url() { super(URL.class); } } } @@ -92,7 +92,7 @@ public final class FollowsType extends EdgeType public final Follows fromRaw(RE raw) { return new Follows(raw); } public final since since = new since(); - public final class since extends Property implements FromAny { + public final class since extends NonUniqueProperty { private since() { super(Date.class); } } } @@ -111,7 +111,7 @@ public final class PostedType extends EdgeType public final Posted fromRaw(RE raw) { return new Posted(raw); } public final when when = new when(); - public final class when extends Property implements FromAny { + public final class when extends NonUniqueProperty { private when() { super(Date.class); } } } From 9422e89049c59938df69040fdb9e4f741534c33c Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 27 Apr 2016 23:56:14 +0200 Subject: [PATCH 15/28] Added vertex types list to the typed graph --- .../java/com/bio4j/angulillos/TypedGraph.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 6d1aa75..5d7fac2 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -1,6 +1,8 @@ package com.bio4j.angulillos; import java.util.function.Function; +import java.util.Set; +import java.util.HashSet; /* @@ -20,6 +22,10 @@ public abstract class TypedGraph< protected TypedGraph(UntypedGraph raw) { this.raw = raw; } + /* This set will store all vertex types defined for this graph */ + private Set> vertexTypes = new HashSet<>(); + public final Set> vertexTypes() { return this.vertexTypes; } + /* ### Abstract helper classes @@ -95,6 +101,18 @@ public abstract class VertexType< > extends ElementType, RV> implements TypedVertex.Type, G,RV,RE> { + // NOTE: this initializer block will be inherited and will add each vertex type to the set + { + if ( + TypedGraph.this.vertexTypes.removeIf( (VertexType vt) -> + vt._label().equals( self()._label() ) + ) + ) { + throw new IllegalArgumentException("The graph contains duplicate vertex type: " + self()._label()); + } + TypedGraph.this.vertexTypes.add(self()); + } + protected VertexType self() { return this; } } From 9a32e571bc0398cef76708190e107b4721aaddd7 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 27 Apr 2016 23:58:00 +0200 Subject: [PATCH 16/28] Added edges types list to the typed graph --- .../java/com/bio4j/angulillos/TypedGraph.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 5d7fac2..bce0249 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -26,6 +26,10 @@ public abstract class TypedGraph< private Set> vertexTypes = new HashSet<>(); public final Set> vertexTypes() { return this.vertexTypes; } + /* This set will store all edge types defined for this graph */ + private Set> edgeTypes = new HashSet<>(); + public final Set> edgeTypes() { return this.edgeTypes; } + /* ### Abstract helper classes @@ -143,6 +147,18 @@ public abstract class EdgeType< T, VertexType, G,RV,RE > { + // NOTE: this initializer block will be inherited and will add each edge type to the set + { + if ( + TypedGraph.this.edgeTypes.removeIf( (EdgeType et) -> + et._label().equals( self()._label() ) + ) + ) { + throw new IllegalArgumentException("The graph contains duplicate edge type: " + self()._label()); + } + TypedGraph.this.edgeTypes.add(self()); + } + protected EdgeType self() { return this; } private final VertexType sourceType; From 24f0d5afc05d567eccda4e0bb4a51f01ed248464 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 28 Apr 2016 00:00:23 +0200 Subject: [PATCH 17/28] Added properties list to the typed element --- .../java/com/bio4j/angulillos/TypedGraph.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index bce0249..0eb968c 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -67,8 +67,29 @@ public abstract class ElementType< protected abstract FT self(); + /* This set stores all properties that are defined on this element type */ + private Set> properties = new HashSet<>(); + public final Set> properties() { return this.properties; } + + private abstract class Property implements com.bio4j.angulillos.Property { + // NOTE: this initializer block will be inherited and will add each vertex type to the set + { + if ( + ElementType.this.properties.removeIf( (Property p) -> + p._label().equals( this._label() ) + ) + ) { + throw new IllegalArgumentException( + "Element type [" + + ElementType.this._label() + + "] contains duplicate property: " + + this._label() + ); + } + ElementType.this.properties.add(this); + } private final Class valueClass; From b8f4c2fd06e1a726cdc10dd38b25ceccc31faccc Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 28 Apr 2016 00:13:10 +0200 Subject: [PATCH 18/28] Added self to (nonabstract) Twitter graph; added simple test for the duplicate elements check --- src/test/java/com/bio4j/angulillos/Twitter.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index c006667..10d93b5 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -8,10 +8,11 @@ import java.util.stream.Stream; -public abstract class Twitter +public class Twitter extends TypedGraph, RV,RE> { + @Override public final Twitter self() { return this; } public Twitter(UntypedGraph raw) { super(raw); } @@ -74,8 +75,13 @@ public final class text extends NonUniqueProperty { public final class url extends UniqueProperty { private url() { super(URL.class); } } + + // NOTE: Try to uncomment it and instantiate TwitterSchema + // public final text text2 = new text(); } + // NOTE: Try to uncomment it and instantiate TwitterSchema + // public final TweetType tweet2 = new TweetType(); /* ### Edges and their types */ From c36a074d4736a65f721eeb710a445369166de9e0 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 30 Mar 2016 19:12:50 +0200 Subject: [PATCH 19/28] Added UntypedGraphSchema interface for schema creation; separated transaction-related methods --- .../com/bio4j/angulillos/UntypedGraph.java | 18 +++++--- .../bio4j/angulillos/UntypedGraphSchema.java | 46 +++++++++++++++++++ 2 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java diff --git a/src/main/java/com/bio4j/angulillos/UntypedGraph.java b/src/main/java/com/bio4j/angulillos/UntypedGraph.java index f4733ea..c80e797 100644 --- a/src/main/java/com/bio4j/angulillos/UntypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/UntypedGraph.java @@ -4,6 +4,13 @@ import java.util.Optional; +interface UntypedTransactionalGraph { + + void commit(); + void rollback(); + void shutdown(); +} + /* ## Untyped graph @@ -16,7 +23,10 @@ Properties are represented using `String`s. What the methods are supposed to do is I think pretty obvious from their names; there is anyway a short explanation for each. */ -public interface UntypedGraph { +public interface UntypedGraph +extends + UntypedTransactionalGraph +{ /* #### Methods on vertices */ @@ -71,10 +81,4 @@ public interface UntypedGraph { /* - Returns a new vertex of type `vertexType` */ RV addVertex(String vertexLabel); - - /* These two methods are here at this level just for convenience; - they should be moved to `UntypedTransactionalGraph` or something like that. */ - void commit(); - void shutdown(); - } diff --git a/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java b/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java new file mode 100644 index 0000000..1569326 --- /dev/null +++ b/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java @@ -0,0 +1,46 @@ +package com.bio4j.angulillos; + + +public interface UntypedGraphSchema { + + < + VT extends VertexType + > SM createVertexType(SM schemaManager, VT vertexType); + + + < + ET extends EdgeType + > SM createEdgeType(SM schemaManager, ET edgeType); + + + < + FT extends ElementType, + P extends Property, + X + > SM createProperty(SM schemaManager, P property); + + + default < + VT extends VertexType + > SM createVertexTypeWithProperties(SM schemaManager, VT vertexType) { + SM sm = createVertexType(schemaManager, vertexType); + // TODO: some kind of fold here: + vertexType.properties().forEach( p -> + createProperty(sm, p) + ); + return sm; + } + + default < + G extends TypedGraph + > SM createAllVertexTypes(SM schemaManager, G g) { + // TODO: some kind of fold here: + g.vertexTypes().forEach( (VertexType vt) -> + createVertexTypeWithProperties(schemaManager, vt) + ); + return schemaManager; + } + + // etc. for edges and all together + +} From 36b8e52b20eab988e6c9cb613e5ae51c65a2b9a0 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 5 May 2016 23:58:24 +0200 Subject: [PATCH 20/28] WIP: rewriting schema creation methods --- .../com/bio4j/angulillos/TypedElement.java | 2 +- .../bio4j/angulillos/UntypedGraphSchema.java | 40 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/TypedElement.java b/src/main/java/com/bio4j/angulillos/TypedElement.java index 35452e0..4a703cd 100644 --- a/src/main/java/com/bio4j/angulillos/TypedElement.java +++ b/src/main/java/com/bio4j/angulillos/TypedElement.java @@ -31,7 +31,7 @@ interface Type < FT extends TypedElement.Type, G extends TypedGraph, RF - > { + > extends HasLabel { G graph(); /* Constructs a value of the typed element of this type */ diff --git a/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java b/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java index 1569326..85609b1 100644 --- a/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java +++ b/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java @@ -1,42 +1,42 @@ package com.bio4j.angulillos; -public interface UntypedGraphSchema { +public interface UntypedGraphSchema> { < - VT extends VertexType + VT extends TypedGraph.TypedVertex + // VT extends TypedVertex.Type > SM createVertexType(SM schemaManager, VT vertexType); < - ET extends EdgeType + ET extends TypedEdge.Type > SM createEdgeType(SM schemaManager, ET edgeType); < - FT extends ElementType, + FT extends TypedElement.Type, P extends Property, X - > SM createProperty(SM schemaManager, P property); + > SM createProperty(SM schemaManager, FT elementType, P property); - default < - VT extends VertexType - > SM createVertexTypeWithProperties(SM schemaManager, VT vertexType) { - SM sm = createVertexType(schemaManager, vertexType); - // TODO: some kind of fold here: - vertexType.properties().forEach( p -> - createProperty(sm, p) - ); - return sm; - } + // default < + // VT extends TypedVertex.Type + // > SM createVertexTypeWithProperties(SM schemaManager, VT vertexType) { + // SM sm = createVertexType(schemaManager, vertexType); + // // TODO: some kind of fold here: + // return sm; + // } - default < - G extends TypedGraph - > SM createAllVertexTypes(SM schemaManager, G g) { + default SM createAllVertexTypes(SM schemaManager, G g) { // TODO: some kind of fold here: - g.vertexTypes().forEach( (VertexType vt) -> - createVertexTypeWithProperties(schemaManager, vt) + g.vertexTypes().forEach( vt -> { + createVertexType(schemaManager, vt); + } + // vt.properties().forEach( p -> + // createProperty(sm, vertexType, p) + // ); ); return schemaManager; } From 526513659a4d47491139a11fed7fed00104e7c5a Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Fri, 6 May 2016 00:59:37 +0200 Subject: [PATCH 21/28] * Added common HasLabel interface * Added no-parameters Any-traits for all type-interfaces * Implemented automatic graph schema creation method --- .../java/com/bio4j/angulillos/Labeled.java | 8 +++ .../java/com/bio4j/angulillos/Property.java | 11 ++- .../java/com/bio4j/angulillos/TypedEdge.java | 13 +++- .../com/bio4j/angulillos/TypedElement.java | 15 ++-- .../java/com/bio4j/angulillos/TypedGraph.java | 26 ++++--- .../com/bio4j/angulillos/TypedVertex.java | 4 +- .../bio4j/angulillos/UntypedGraphSchema.java | 70 ++++++++++--------- 7 files changed, 94 insertions(+), 53 deletions(-) create mode 100644 src/main/java/com/bio4j/angulillos/Labeled.java diff --git a/src/main/java/com/bio4j/angulillos/Labeled.java b/src/main/java/com/bio4j/angulillos/Labeled.java new file mode 100644 index 0000000..239a8a6 --- /dev/null +++ b/src/main/java/com/bio4j/angulillos/Labeled.java @@ -0,0 +1,8 @@ +package com.bio4j.angulillos; + +interface HasLabel { + + default public String _label() { + return getClass().getCanonicalName(); + } +} diff --git a/src/main/java/com/bio4j/angulillos/Property.java b/src/main/java/com/bio4j/angulillos/Property.java index 0532415..b5bf442 100644 --- a/src/main/java/com/bio4j/angulillos/Property.java +++ b/src/main/java/com/bio4j/angulillos/Property.java @@ -5,12 +5,17 @@ A property of the [Element](TypedElement.java.md) of type `FT`, with value type `X`. */ +interface AnyProperty +extends HasLabel, HasFromArity { + + public abstract AnyElementType elementType(); + public abstract Class valueClass(); +} + interface Property< FT extends TypedElement.Type, X -> extends HasFromArity { - - default public String _label() { return getClass().getCanonicalName(); } +> extends AnyProperty { public abstract FT elementType(); public abstract Class valueClass(); diff --git a/src/main/java/com/bio4j/angulillos/TypedEdge.java b/src/main/java/com/bio4j/angulillos/TypedEdge.java index 3274e4e..0bfe490 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdge.java +++ b/src/main/java/com/bio4j/angulillos/TypedEdge.java @@ -9,6 +9,16 @@ - `E` the edge, `ET` the edge type - `T` the target TypedVertex, `TT` the target TypedVertex type */ +interface AnyEdgeType extends + AnyElementType, + HasFromArity, + HasToArity +{ + + AnyVertexType sourceType(); + AnyVertexType targetType(); +} + public interface TypedEdge < // source vertex S extends TypedVertex, @@ -41,8 +51,7 @@ interface Type < RV,RE > extends TypedElement.Type, - HasFromArity, - HasToArity + AnyEdgeType { ST sourceType(); TT targetType(); diff --git a/src/main/java/com/bio4j/angulillos/TypedElement.java b/src/main/java/com/bio4j/angulillos/TypedElement.java index 4a703cd..bddab65 100644 --- a/src/main/java/com/bio4j/angulillos/TypedElement.java +++ b/src/main/java/com/bio4j/angulillos/TypedElement.java @@ -1,5 +1,7 @@ package com.bio4j.angulillos; +import java.util.Set; + /* ## Elements @@ -13,6 +15,12 @@ `E` refers to the element itself, and `ET` its type. You cannot define one without defining the other. */ +interface AnyElementType extends HasLabel { + + public abstract AnyTypedGraph graph(); + public abstract Set properties(); +} + public interface TypedElement < F extends TypedElement, FT extends TypedElement.Type, @@ -31,14 +39,11 @@ interface Type < FT extends TypedElement.Type, G extends TypedGraph, RF - > extends HasLabel { - G graph(); + > extends AnyElementType { + public G graph(); /* Constructs a value of the typed element of this type */ F fromRaw(RF rawElem); - - // NOTE: this should be final, but interface cannot have final methods - default String _label() { return getClass().getCanonicalName(); } } diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 0eb968c..401b5f0 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -10,10 +10,16 @@ A `TypedGraph` is, unsurprisingly, the typed version of [UntypedGraph](UntypedGraph.java.md). */ +interface AnyTypedGraph { + + public abstract Set vertexTypes(); + public abstract Set edgeTypes(); +} + public abstract class TypedGraph< G extends TypedGraph, RV,RE -> { +> implements AnyTypedGraph { public abstract G self(); @@ -23,12 +29,12 @@ public abstract class TypedGraph< protected TypedGraph(UntypedGraph raw) { this.raw = raw; } /* This set will store all vertex types defined for this graph */ - private Set> vertexTypes = new HashSet<>(); - public final Set> vertexTypes() { return this.vertexTypes; } + private Set vertexTypes = new HashSet<>(); + public final Set vertexTypes() { return this.vertexTypes; } /* This set will store all edge types defined for this graph */ - private Set> edgeTypes = new HashSet<>(); - public final Set> edgeTypes() { return this.edgeTypes; } + private Set edgeTypes = new HashSet<>(); + public final Set edgeTypes() { return this.edgeTypes; } /* ### Abstract helper classes @@ -68,8 +74,8 @@ public abstract class ElementType< protected abstract FT self(); /* This set stores all properties that are defined on this element type */ - private Set> properties = new HashSet<>(); - public final Set> properties() { return this.properties; } + private Set properties = new HashSet<>(); + public final Set properties() { return this.properties; } private abstract class Property @@ -77,7 +83,7 @@ private abstract class Property // NOTE: this initializer block will be inherited and will add each vertex type to the set { if ( - ElementType.this.properties.removeIf( (Property p) -> + ElementType.this.properties.removeIf( (AnyProperty p) -> p._label().equals( this._label() ) ) ) { @@ -129,7 +135,7 @@ public abstract class VertexType< // NOTE: this initializer block will be inherited and will add each vertex type to the set { if ( - TypedGraph.this.vertexTypes.removeIf( (VertexType vt) -> + TypedGraph.this.vertexTypes.removeIf( (AnyVertexType vt) -> vt._label().equals( self()._label() ) ) ) { @@ -171,7 +177,7 @@ public abstract class EdgeType< // NOTE: this initializer block will be inherited and will add each edge type to the set { if ( - TypedGraph.this.edgeTypes.removeIf( (EdgeType et) -> + TypedGraph.this.edgeTypes.removeIf( (AnyEdgeType et) -> et._label().equals( self()._label() ) ) ) { diff --git a/src/main/java/com/bio4j/angulillos/TypedVertex.java b/src/main/java/com/bio4j/angulillos/TypedVertex.java index a40b0e0..61a643d 100644 --- a/src/main/java/com/bio4j/angulillos/TypedVertex.java +++ b/src/main/java/com/bio4j/angulillos/TypedVertex.java @@ -9,6 +9,8 @@ A typed vertex. A vertex and its type need to be defined at the same time. The vertex keeps a reference of its type, while the type works as a factory for creating vertices with that type. */ +interface AnyVertexType extends AnyElementType {} + public interface TypedVertex < V extends TypedVertex, VT extends TypedVertex.Type, @@ -23,7 +25,7 @@ interface Type < VT extends TypedVertex.Type, G extends TypedGraph, RV,RE - > extends TypedElement.Type { + > extends TypedElement.Type, AnyVertexType { default V addVertex() { diff --git a/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java b/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java index 85609b1..eda69c8 100644 --- a/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java +++ b/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java @@ -1,46 +1,52 @@ package com.bio4j.angulillos; +import java.util.Set; -public interface UntypedGraphSchema> { +public interface UntypedGraphSchema { - < - VT extends TypedGraph.TypedVertex - // VT extends TypedVertex.Type - > SM createVertexType(SM schemaManager, VT vertexType); + /* This method should take into account vertex label */ + SM createVertexType(SM schemaManager, AnyVertexType vertexType); + /* This method should take into account edge label, source/target types and to/from-arities */ + SM createEdgeType(SM schemaManager, AnyEdgeType edgeType); - < - ET extends TypedEdge.Type - > SM createEdgeType(SM schemaManager, ET edgeType); + /* This method should take into account property's element type and from-arity */ + SM createProperty(SM schemaManager, AnyProperty property); + // TODO: indexes - < - FT extends TypedElement.Type, - P extends Property, - X - > SM createProperty(SM schemaManager, FT elementType, P property); + // This is like properties.foldLeft(schemaManager)(createProperty) + default + SM createProperties(SM schemaManager, Set properties) { + // sm is a mutable accumulator passed around + SM sm = schemaManager; + for (AnyProperty p : properties) { + sm = createProperty(sm, p); + } - // default < - // VT extends TypedVertex.Type - // > SM createVertexTypeWithProperties(SM schemaManager, VT vertexType) { - // SM sm = createVertexType(schemaManager, vertexType); - // // TODO: some kind of fold here: - // return sm; - // } - - default SM createAllVertexTypes(SM schemaManager, G g) { - // TODO: some kind of fold here: - g.vertexTypes().forEach( vt -> { - createVertexType(schemaManager, vt); - } - // vt.properties().forEach( p -> - // createProperty(sm, vertexType, p) - // ); - ); - return schemaManager; + return sm; } - // etc. for edges and all together + + /* Creates all graph's vertex/edge types with their properties */ + default < + G extends AnyTypedGraph + > SM createAllVertexTypes(SM schemaManager, G g) { + // sm is a mutable accumulator passed around + SM sm = schemaManager; + + for (AnyVertexType vt : g.vertexTypes()) { + sm = createVertexType(sm, vt); + sm = createProperties(sm, vt.properties()); + } + + for (AnyEdgeType et : g.edgeTypes()) { + sm = createEdgeType(sm, et); + sm = createProperties(sm, et.properties()); + } + + return sm; + } } From f47119673b40d6d9578f731cf93abae1869417b2 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 7 May 2016 00:33:59 +0200 Subject: [PATCH 22/28] Renamed files to make Any-traits public (probably will change later) --- .../bio4j/angulillos/{TypedEdge.java => AnyEdgeType.java} | 4 ++-- .../angulillos/{TypedElement.java => AnyElementType.java} | 4 ++-- .../com/bio4j/angulillos/{Property.java => AnyProperty.java} | 5 +++-- .../angulillos/{TypedVertex.java => AnyVertexType.java} | 4 ++-- src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java | 5 ++--- 5 files changed, 11 insertions(+), 11 deletions(-) rename src/main/java/com/bio4j/angulillos/{TypedEdge.java => AnyEdgeType.java} (97%) rename src/main/java/com/bio4j/angulillos/{TypedElement.java => AnyElementType.java} (96%) rename src/main/java/com/bio4j/angulillos/{Property.java => AnyProperty.java} (85%) rename src/main/java/com/bio4j/angulillos/{TypedVertex.java => AnyVertexType.java} (98%) diff --git a/src/main/java/com/bio4j/angulillos/TypedEdge.java b/src/main/java/com/bio4j/angulillos/AnyEdgeType.java similarity index 97% rename from src/main/java/com/bio4j/angulillos/TypedEdge.java rename to src/main/java/com/bio4j/angulillos/AnyEdgeType.java index 0bfe490..af68a26 100644 --- a/src/main/java/com/bio4j/angulillos/TypedEdge.java +++ b/src/main/java/com/bio4j/angulillos/AnyEdgeType.java @@ -9,7 +9,7 @@ - `E` the edge, `ET` the edge type - `T` the target TypedVertex, `TT` the target TypedVertex type */ -interface AnyEdgeType extends +public interface AnyEdgeType extends AnyElementType, HasFromArity, HasToArity @@ -19,7 +19,7 @@ interface AnyEdgeType extends AnyVertexType targetType(); } -public interface TypedEdge < +interface TypedEdge < // source vertex S extends TypedVertex, ST extends TypedVertex.Type, diff --git a/src/main/java/com/bio4j/angulillos/TypedElement.java b/src/main/java/com/bio4j/angulillos/AnyElementType.java similarity index 96% rename from src/main/java/com/bio4j/angulillos/TypedElement.java rename to src/main/java/com/bio4j/angulillos/AnyElementType.java index bddab65..7213d8d 100644 --- a/src/main/java/com/bio4j/angulillos/TypedElement.java +++ b/src/main/java/com/bio4j/angulillos/AnyElementType.java @@ -15,13 +15,13 @@ `E` refers to the element itself, and `ET` its type. You cannot define one without defining the other. */ -interface AnyElementType extends HasLabel { +public interface AnyElementType extends HasLabel { public abstract AnyTypedGraph graph(); public abstract Set properties(); } -public interface TypedElement < +interface TypedElement < F extends TypedElement, FT extends TypedElement.Type, G extends TypedGraph, diff --git a/src/main/java/com/bio4j/angulillos/Property.java b/src/main/java/com/bio4j/angulillos/AnyProperty.java similarity index 85% rename from src/main/java/com/bio4j/angulillos/Property.java rename to src/main/java/com/bio4j/angulillos/AnyProperty.java index b5bf442..3eb8c8a 100644 --- a/src/main/java/com/bio4j/angulillos/Property.java +++ b/src/main/java/com/bio4j/angulillos/AnyProperty.java @@ -5,8 +5,9 @@ A property of the [Element](TypedElement.java.md) of type `FT`, with value type `X`. */ -interface AnyProperty -extends HasLabel, HasFromArity { +public interface AnyProperty extends + HasLabel, + HasFromArity { public abstract AnyElementType elementType(); public abstract Class valueClass(); diff --git a/src/main/java/com/bio4j/angulillos/TypedVertex.java b/src/main/java/com/bio4j/angulillos/AnyVertexType.java similarity index 98% rename from src/main/java/com/bio4j/angulillos/TypedVertex.java rename to src/main/java/com/bio4j/angulillos/AnyVertexType.java index 61a643d..43c26ab 100644 --- a/src/main/java/com/bio4j/angulillos/TypedVertex.java +++ b/src/main/java/com/bio4j/angulillos/AnyVertexType.java @@ -9,9 +9,9 @@ A typed vertex. A vertex and its type need to be defined at the same time. The vertex keeps a reference of its type, while the type works as a factory for creating vertices with that type. */ -interface AnyVertexType extends AnyElementType {} +public interface AnyVertexType extends AnyElementType {} -public interface TypedVertex < +interface TypedVertex < V extends TypedVertex, VT extends TypedVertex.Type, G extends TypedGraph, diff --git a/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java b/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java index eda69c8..2e44165 100644 --- a/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java +++ b/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java @@ -30,9 +30,8 @@ SM createProperties(SM schemaManager, Set properties) { /* Creates all graph's vertex/edge types with their properties */ - default < - G extends AnyTypedGraph - > SM createAllVertexTypes(SM schemaManager, G g) { + default + SM createAllVertexTypes(SM schemaManager, AnyTypedGraph g) { // sm is a mutable accumulator passed around SM sm = schemaManager; From 0296a75354d9e50c8cf6a4fc884e63e13d320621 Mon Sep 17 00:00:00 2001 From: Eduardo Pareja-Tobes Date: Tue, 10 May 2016 15:57:49 +0200 Subject: [PATCH 23/28] make tests compile --- src/test/java/com/bio4j/angulillos/Twitter.java | 17 ++++++++--------- version.sbt | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index 10d93b5..7d4742e 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -7,7 +7,6 @@ import java.util.Date; import java.util.stream.Stream; - public class Twitter extends TypedGraph, RV,RE> @@ -23,14 +22,14 @@ public abstract class Vertex< protected Vertex(RV raw, VertexType type) { super(raw, type); } // experimenting with override: - @Override public < - E extends TypedEdge, E,ET, ?,?, ?,RV,RE>, - ET extends TypedEdge.Type, E,ET, ?,?, ?,RV,RE> - > - Stream outE(ET edgeType) { - System.out.println("This is overriden Twitter-graph specific outE"); - return outE(edgeType); - } + // @Override public < + // E extends Edge, E,ET, ?,?, ?,RV,RE>, + // ET extends Edge.Type, E,ET, ?,?, ?,RV,RE> + // > + // Stream outE(ET edgeType) { + // System.out.println("This is overriden Twitter-graph specific outE"); + // return outE(edgeType); + // } } diff --git a/version.sbt b/version.sbt index 017a6f8..6e13053 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "0.7.0-SNAPSHOT" \ No newline at end of file +version in ThisBuild := "0.7.0-early-access" From 6e1cbd70f937ee16a50b836f19f7414a41629d90 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Tue, 10 May 2016 20:03:03 +0200 Subject: [PATCH 24/28] Added inEdges/outEdges sets to the AnyVertexType interface filled on schema creation --- .../com/bio4j/angulillos/AnyEdgeType.java | 1 + .../com/bio4j/angulillos/AnyElementType.java | 4 +- .../com/bio4j/angulillos/AnyProperty.java | 9 ++-- .../com/bio4j/angulillos/AnyVertexType.java | 13 +++++- .../java/com/bio4j/angulillos/TypedGraph.java | 44 +++++++++++-------- .../java/com/bio4j/angulillos/Twitter.java | 32 +++++++------- 6 files changed, 61 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/AnyEdgeType.java b/src/main/java/com/bio4j/angulillos/AnyEdgeType.java index af68a26..92baeb8 100644 --- a/src/main/java/com/bio4j/angulillos/AnyEdgeType.java +++ b/src/main/java/com/bio4j/angulillos/AnyEdgeType.java @@ -19,6 +19,7 @@ public interface AnyEdgeType extends AnyVertexType targetType(); } +// TODO: make it public interface TypedEdge < // source vertex S extends TypedVertex, diff --git a/src/main/java/com/bio4j/angulillos/AnyElementType.java b/src/main/java/com/bio4j/angulillos/AnyElementType.java index 7213d8d..8b12f59 100644 --- a/src/main/java/com/bio4j/angulillos/AnyElementType.java +++ b/src/main/java/com/bio4j/angulillos/AnyElementType.java @@ -17,8 +17,8 @@ */ public interface AnyElementType extends HasLabel { - public abstract AnyTypedGraph graph(); - public abstract Set properties(); + AnyTypedGraph graph(); + Set properties(); } interface TypedElement < diff --git a/src/main/java/com/bio4j/angulillos/AnyProperty.java b/src/main/java/com/bio4j/angulillos/AnyProperty.java index 3eb8c8a..4670385 100644 --- a/src/main/java/com/bio4j/angulillos/AnyProperty.java +++ b/src/main/java/com/bio4j/angulillos/AnyProperty.java @@ -9,15 +9,16 @@ public interface AnyProperty extends HasLabel, HasFromArity { - public abstract AnyElementType elementType(); - public abstract Class valueClass(); + AnyElementType elementType(); + Class valueClass(); } +// TODO: make it public interface Property< FT extends TypedElement.Type, X > extends AnyProperty { - public abstract FT elementType(); - public abstract Class valueClass(); + FT elementType(); + Class valueClass(); } diff --git a/src/main/java/com/bio4j/angulillos/AnyVertexType.java b/src/main/java/com/bio4j/angulillos/AnyVertexType.java index 43c26ab..ea86ba2 100644 --- a/src/main/java/com/bio4j/angulillos/AnyVertexType.java +++ b/src/main/java/com/bio4j/angulillos/AnyVertexType.java @@ -1,5 +1,6 @@ package com.bio4j.angulillos; +import java.util.Set; import java.util.Optional; import java.util.stream.Stream; @@ -9,8 +10,13 @@ A typed vertex. A vertex and its type need to be defined at the same time. The vertex keeps a reference of its type, while the type works as a factory for creating vertices with that type. */ -public interface AnyVertexType extends AnyElementType {} +public interface AnyVertexType extends AnyElementType { + Set inEdges(); + Set outEdges(); +} + +// TODO: make it public interface TypedVertex < V extends TypedVertex, VT extends TypedVertex.Type, @@ -25,7 +31,10 @@ interface Type < VT extends TypedVertex.Type, G extends TypedGraph, RV,RE - > extends TypedElement.Type, AnyVertexType { + > extends + TypedElement.Type, + AnyVertexType + { default V addVertex() { diff --git a/src/main/java/com/bio4j/angulillos/TypedGraph.java b/src/main/java/com/bio4j/angulillos/TypedGraph.java index 401b5f0..5b842b5 100644 --- a/src/main/java/com/bio4j/angulillos/TypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/TypedGraph.java @@ -1,8 +1,6 @@ package com.bio4j.angulillos; -import java.util.function.Function; import java.util.Set; -import java.util.HashSet; /* @@ -12,8 +10,8 @@ */ interface AnyTypedGraph { - public abstract Set vertexTypes(); - public abstract Set edgeTypes(); + public Set vertexTypes(); + public Set edgeTypes(); } public abstract class TypedGraph< @@ -29,11 +27,11 @@ public abstract class TypedGraph< protected TypedGraph(UntypedGraph raw) { this.raw = raw; } /* This set will store all vertex types defined for this graph */ - private Set vertexTypes = new HashSet<>(); + private Set vertexTypes = new java.util.HashSet<>(); public final Set vertexTypes() { return this.vertexTypes; } /* This set will store all edge types defined for this graph */ - private Set edgeTypes = new HashSet<>(); + private Set edgeTypes = new java.util.HashSet<>(); public final Set edgeTypes() { return this.edgeTypes; } @@ -74,7 +72,7 @@ public abstract class ElementType< protected abstract FT self(); /* This set stores all properties that are defined on this element type */ - private Set properties = new HashSet<>(); + private Set properties = new java.util.HashSet<>(); public final Set properties() { return this.properties; } @@ -130,7 +128,15 @@ public abstract class Vertex< public abstract class VertexType< V extends Vertex > extends ElementType, RV> - implements TypedVertex.Type, G,RV,RE> { + implements TypedVertex.Type, G,RV,RE> + { + protected VertexType self() { return this; } + + private Set inEdges = new java.util.HashSet<>(); + private Set outEdges = new java.util.HashSet<>(); + + public final Set inEdges() { return this.inEdges; } + public final Set outEdges() { return this.outEdges; } // NOTE: this initializer block will be inherited and will add each vertex type to the set { @@ -143,8 +149,6 @@ public abstract class VertexType< } TypedGraph.this.vertexTypes.add(self()); } - - protected VertexType self() { return this; } } @@ -174,6 +178,14 @@ public abstract class EdgeType< T, VertexType, G,RV,RE > { + protected EdgeType self() { return this; } + + private final VertexType sourceType; + private final VertexType targetType; + + @Override public final VertexType sourceType() { return this.sourceType; } + @Override public final VertexType targetType() { return this.targetType; } + // NOTE: this initializer block will be inherited and will add each edge type to the set { if ( @@ -183,20 +195,16 @@ public abstract class EdgeType< ) { throw new IllegalArgumentException("The graph contains duplicate edge type: " + self()._label()); } + TypedGraph.this.edgeTypes.add(self()); } - protected EdgeType self() { return this; } - - private final VertexType sourceType; - private final VertexType targetType; - - @Override public final VertexType sourceType() { return this.sourceType; } - @Override public final VertexType targetType() { return this.targetType; } - protected EdgeType(VertexType sourceType, VertexType targetType) { this.sourceType = sourceType; this.targetType = targetType; + + sourceType.outEdges.add(self()); + targetType.inEdges.add(self()); } } diff --git a/src/test/java/com/bio4j/angulillos/Twitter.java b/src/test/java/com/bio4j/angulillos/Twitter.java index 10d93b5..9ad4efd 100644 --- a/src/test/java/com/bio4j/angulillos/Twitter.java +++ b/src/test/java/com/bio4j/angulillos/Twitter.java @@ -16,22 +16,22 @@ public class Twitter public Twitter(UntypedGraph raw) { super(raw); } - public abstract class Vertex< - V extends Vertex - > extends TypedGraph, RV,RE>.Vertex { - - protected Vertex(RV raw, VertexType type) { super(raw, type); } - - // experimenting with override: - @Override public < - E extends TypedEdge, E,ET, ?,?, ?,RV,RE>, - ET extends TypedEdge.Type, E,ET, ?,?, ?,RV,RE> - > - Stream outE(ET edgeType) { - System.out.println("This is overriden Twitter-graph specific outE"); - return outE(edgeType); - } - } + // public abstract class Vertex< + // V extends Vertex + // > extends TypedGraph, RV,RE>.Vertex { + // + // protected Vertex(RV raw, VertexType type) { super(raw, type); } + // + // // experimenting with override: + // @Override public < + // E extends TypedEdge, E,ET, ?,?, ?,RV,RE>, + // ET extends TypedEdge.Type, E,ET, ?,?, ?,RV,RE> + // > + // Stream outE(ET edgeType) { + // System.out.println("This is overriden Twitter-graph specific outE"); + // return outE(edgeType); + // } + // } /* ### Vertices and their types */ From de35722bd622ad9ba71b18498b4e7b98626a66c4 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Tue, 10 May 2016 20:13:16 +0200 Subject: [PATCH 25/28] Added some code to for printing schema in the console --- .../angulillos/TwitterGraphTestSuite.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java index fefad35..2bb3e71 100644 --- a/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java +++ b/src/test/java/com/bio4j/angulillos/TwitterGraphTestSuite.java @@ -41,6 +41,24 @@ public abstract class TwitterGraphTestSuite { Stream texts = ts.map(tweet -> tweet.get(g.tweet.text)); + // to print the schema: + + // g.vertexTypes.foreach { vt => + // println(s"""${vt._label}: + // | properties: ${vt.properties().map(_._label())} + // | inEdges: ${vt.inEdges().map{ _._label() }} + // | outEdges: ${vt.outEdges().map{ _._label() }}""".stripMargin + // ) + // } + // + // g.edgeTypes.foreach { et => + // println(s"""${et._label}: + // | properties: ${et.properties().map(_._label())} + // | source: ${et.source()._label()} + // | target: ${et.target()._label()}""".stripMargin + // ) + // } + // public void doSomething(Twitter.User user) { // // Stream.Tweet> tweets = user.outV(g.posted); From 254d2e88a7d78602391e0bfe80973d719e1ec2a5 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Tue, 10 May 2016 20:19:29 +0200 Subject: [PATCH 26/28] Changed UntypedGraph interface to use Any-types instead of strings --- .../com/bio4j/angulillos/AnyEdgeType.java | 6 +-- .../com/bio4j/angulillos/AnyVertexType.java | 38 +++++++++---------- .../com/bio4j/angulillos/UntypedGraph.java | 36 +++++++++--------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/AnyEdgeType.java b/src/main/java/com/bio4j/angulillos/AnyEdgeType.java index 92baeb8..4874da0 100644 --- a/src/main/java/com/bio4j/angulillos/AnyEdgeType.java +++ b/src/main/java/com/bio4j/angulillos/AnyEdgeType.java @@ -61,7 +61,7 @@ interface Type < default E addEdge(S from, T to) { return this.fromRaw( - graph().raw().addEdge( from.raw(), this._label(), to.raw() ) + graph().raw().addEdge( from.raw(), this, to.raw() ) ); } @@ -85,13 +85,13 @@ default T target() { @Override default X get(Property property) { - return graph().raw().getPropertyE(raw(), property._label()); + return graph().raw().getPropertyE(raw(), property); } @Override default E set(Property property, X value) { - graph().raw().setPropertyE(raw(), property._label(), value); + graph().raw().setPropertyE(raw(), property, value); return self(); } diff --git a/src/main/java/com/bio4j/angulillos/AnyVertexType.java b/src/main/java/com/bio4j/angulillos/AnyVertexType.java index ea86ba2..1b2abaf 100644 --- a/src/main/java/com/bio4j/angulillos/AnyVertexType.java +++ b/src/main/java/com/bio4j/angulillos/AnyVertexType.java @@ -39,7 +39,7 @@ interface Type < default V addVertex() { return this.fromRaw( - graph().raw().addVertex( this._label() ) + graph().raw().addVertex( this ) ); } } @@ -48,14 +48,14 @@ default V addVertex() { /* ### Properties */ @Override default X get(Property property) { - return graph().raw().getPropertyV(this.raw(), property._label()); + return graph().raw().getPropertyV(this.raw(), property); } @Override default V set(Property property, X value) { - graph().raw().setPropertyV(this.raw(), property._label(), value); + graph().raw().setPropertyV(this.raw(), property, value); return this.self(); } @@ -74,7 +74,7 @@ Stream outE(ET edgeType) { return graph().raw().outE( this.raw(), - edgeType._label() + edgeType ).map( edgeType::fromRaw ); @@ -89,7 +89,7 @@ Stream outAtLeastOneE(ET edgeType) { return graph().raw().outAtLeastOneE( this.raw(), - edgeType._label() + edgeType ).map( edgeType::fromRaw ); @@ -104,7 +104,7 @@ Optional outAtMostOneE(ET edgeType) { return graph().raw().outAtMostOneE( this.raw(), - edgeType._label() + edgeType ).map( edgeType::fromRaw ); @@ -120,7 +120,7 @@ E outOneE(ET edgeType) { return edgeType.fromRaw( graph().raw().outOneE( this.raw(), - edgeType._label() + edgeType ) ); } @@ -135,7 +135,7 @@ Stream inE(ET edgeType) { return graph().raw().inE( this.raw(), - edgeType._label() + edgeType ).map( edgeType::fromRaw ); @@ -150,7 +150,7 @@ Stream inAtLeastOneE(ET edgeType) { return graph().raw().inAtLeastOneE( this.raw(), - edgeType._label() + edgeType ).map( edgeType::fromRaw ); @@ -165,7 +165,7 @@ Optional inAtMostOneE(ET edgeType) { return graph().raw().inAtMostOneE( this.raw(), - edgeType._label() + edgeType ).map( edgeType::fromRaw ); @@ -181,7 +181,7 @@ E inOneE(ET edgeType) { return edgeType.fromRaw( graph().raw().inOneE( this.raw(), - edgeType._label() + edgeType ) ); } @@ -200,7 +200,7 @@ Stream outV(ET edgeType) { return graph().raw().outV( this.raw(), - edgeType._label() + edgeType ).map( edgeType.targetType()::fromRaw ); @@ -217,7 +217,7 @@ Stream outAtLeastOneV(ET edgeType) { return graph().raw().outAtLeastOneV( this.raw(), - edgeType._label() + edgeType ).map( edgeType.targetType()::fromRaw ); @@ -234,7 +234,7 @@ Optional outAtMostOneV(ET edgeType) { return graph().raw().outAtMostOneV( this.raw(), - edgeType._label() + edgeType ).map( edgeType.targetType()::fromRaw ); @@ -252,7 +252,7 @@ T outOneV(ET edgeType) { return edgeType.targetType().fromRaw( graph().raw().outOneV( this.raw(), - edgeType._label() + edgeType ) ); } @@ -269,7 +269,7 @@ Stream inV(ET edgeType) { return graph().raw().inV( this.raw(), - edgeType._label() + edgeType ).map( edgeType.sourceType()::fromRaw ); @@ -286,7 +286,7 @@ Stream inAtLeastOneV(ET edgeType) { return graph().raw().inAtLeastOneV( this.raw(), - edgeType._label() + edgeType ).map( edgeType.sourceType()::fromRaw ); @@ -303,7 +303,7 @@ Optional inAtMostOneV(ET edgeType) { return graph().raw().inAtMostOneV( this.raw(), - edgeType._label() + edgeType ).map( edgeType.sourceType()::fromRaw ); @@ -321,7 +321,7 @@ S inOneV(ET edgeType) { return edgeType.sourceType().fromRaw( graph().raw().inOneV( this.raw(), - edgeType._label() + edgeType ) ); } diff --git a/src/main/java/com/bio4j/angulillos/UntypedGraph.java b/src/main/java/com/bio4j/angulillos/UntypedGraph.java index be87fab..2d50a1e 100644 --- a/src/main/java/com/bio4j/angulillos/UntypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/UntypedGraph.java @@ -31,9 +31,9 @@ public interface UntypedGraph /* #### Methods on vertices */ /* - Get from `vertex` the value of `property` */ - X getPropertyV(RV vertex, String property); + X getPropertyV(RV vertex, AnyProperty property); /* - Set the `value` of `property` in `vertex` */ - RV setPropertyV(RV vertex, String property, X value); + RV setPropertyV(RV vertex, AnyProperty property, X value); /* - Get the edges of type `edgeType` _out_ of `vertex` */ Stream outE(RV vertex, AnyEdgeType edgeLabel); @@ -42,31 +42,31 @@ public interface UntypedGraph default RE outOneE(RV vertex, AnyEdgeType edgeLabel) { return outE(vertex, edgeLabel).findFirst().get(); } /* - Get the _target_ vertices of the edges of type `edgeType` _out_ of `vertex` */ - Stream outV(RV vertex, String edgeLabel); - default Stream outAtLeastOneV(RV vertex, String edgeLabel) { return outV(vertex, edgeLabel); } - default Optional outAtMostOneV(RV vertex, String edgeLabel) { return outV(vertex, edgeLabel).findFirst(); } - default RV outOneV(RV vertex, String edgeLabel) { return outV(vertex, edgeLabel).findFirst().get(); } + Stream outV(RV vertex, AnyEdgeType edgeLabel); + default Stream outAtLeastOneV(RV vertex, AnyEdgeType edgeLabel) { return outV(vertex, edgeLabel); } + default Optional outAtMostOneV(RV vertex, AnyEdgeType edgeLabel) { return outV(vertex, edgeLabel).findFirst(); } + default RV outOneV(RV vertex, AnyEdgeType edgeLabel) { return outV(vertex, edgeLabel).findFirst().get(); } /* - Get the edges of type `edgeType` _into_ `vertex` */ - Stream inE(RV vertex, String edgeLabel); - default Stream inAtLeastOneE(RV vertex, String edgeLabel) { return inE(vertex, edgeLabel); } - default Optional inAtMostOneE(RV vertex, String edgeLabel) { return inE(vertex, edgeLabel).findFirst(); } - default RE inOneE(RV vertex, String edgeLabel) { return inE(vertex, edgeLabel).findFirst().get(); } + Stream inE(RV vertex, AnyEdgeType edgeLabel); + default Stream inAtLeastOneE(RV vertex, AnyEdgeType edgeLabel) { return inE(vertex, edgeLabel); } + default Optional inAtMostOneE(RV vertex, AnyEdgeType edgeLabel) { return inE(vertex, edgeLabel).findFirst(); } + default RE inOneE(RV vertex, AnyEdgeType edgeLabel) { return inE(vertex, edgeLabel).findFirst().get(); } /* - Get the _source_ vertices of the edges of type `edgeType` _into_ `vertex` */ - Stream inV(RV vertex, String edgeLabel); - default Stream inAtLeastOneV(RV vertex, String edgeLabel) { return inV(vertex, edgeLabel); } - default Optional inAtMostOneV(RV vertex, String edgeLabel) { return inV(vertex, edgeLabel).findFirst(); } - default RV inOneV(RV vertex, String edgeLabel) { return inV(vertex, edgeLabel).findFirst().get(); } + Stream inV(RV vertex, AnyEdgeType edgeLabel); + default Stream inAtLeastOneV(RV vertex, AnyEdgeType edgeLabel) { return inV(vertex, edgeLabel); } + default Optional inAtMostOneV(RV vertex, AnyEdgeType edgeLabel) { return inV(vertex, edgeLabel).findFirst(); } + default RV inOneV(RV vertex, AnyEdgeType edgeLabel) { return inV(vertex, edgeLabel).findFirst().get(); } /* #### Methods on edges */ /* - Get from `edge` the value of `property` */ - X getPropertyE(RE edge, String property); + X getPropertyE(RE edge, AnyProperty property); /* - Set the `value` of `property` in `edge` */ - RE setPropertyE(RE edge, String property, X value); + RE setPropertyE(RE edge, AnyProperty property, X value); /* - Get the source vertex of `edge` */ RV source(RE edge); @@ -77,8 +77,8 @@ public interface UntypedGraph /* #### Create vertices and edges */ /* - Returns a new edge: source -[edgeLabel]-> target */ - RE addEdge(RV source, String edgeLabel, RV target); + RE addEdge(RV source, AnyEdgeType edgeLabel, RV target); /* - Returns a new vertex of type `vertexType` */ - RV addVertex(String vertexLabel); + RV addVertex(AnyVertexType vertexLabel); } From 129ec04dcc602e7ae9bfaf48efe81d7df745f6ac Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Tue, 10 May 2016 20:21:31 +0200 Subject: [PATCH 27/28] Fixed createSchema name --- src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java b/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java index 2e44165..ee0c222 100644 --- a/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java +++ b/src/main/java/com/bio4j/angulillos/UntypedGraphSchema.java @@ -31,7 +31,7 @@ SM createProperties(SM schemaManager, Set properties) { /* Creates all graph's vertex/edge types with their properties */ default - SM createAllVertexTypes(SM schemaManager, AnyTypedGraph g) { + SM createSchema(SM schemaManager, AnyTypedGraph g) { // sm is a mutable accumulator passed around SM sm = schemaManager; From ba2f17dc8b4aa31fa5d5beccb0978bd95086fec2 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Tue, 10 May 2016 20:29:27 +0200 Subject: [PATCH 28/28] Renamed ...Label parameters to ...Type --- .../com/bio4j/angulillos/UntypedGraph.java | 38 +++++++++---------- version.sbt | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/bio4j/angulillos/UntypedGraph.java b/src/main/java/com/bio4j/angulillos/UntypedGraph.java index 2d50a1e..45ebaf8 100644 --- a/src/main/java/com/bio4j/angulillos/UntypedGraph.java +++ b/src/main/java/com/bio4j/angulillos/UntypedGraph.java @@ -36,29 +36,29 @@ public interface UntypedGraph RV setPropertyV(RV vertex, AnyProperty property, X value); /* - Get the edges of type `edgeType` _out_ of `vertex` */ - Stream outE(RV vertex, AnyEdgeType edgeLabel); - default Stream outAtLeastOneE(RV vertex, AnyEdgeType edgeLabel) { return outE(vertex, edgeLabel); } - default Optional outAtMostOneE(RV vertex, AnyEdgeType edgeLabel) { return outE(vertex, edgeLabel).findFirst(); } - default RE outOneE(RV vertex, AnyEdgeType edgeLabel) { return outE(vertex, edgeLabel).findFirst().get(); } + Stream outE(RV vertex, AnyEdgeType edgeType); + default Stream outAtLeastOneE(RV vertex, AnyEdgeType edgeType) { return outE(vertex, edgeType); } + default Optional outAtMostOneE(RV vertex, AnyEdgeType edgeType) { return outE(vertex, edgeType).findFirst(); } + default RE outOneE(RV vertex, AnyEdgeType edgeType) { return outE(vertex, edgeType).findFirst().get(); } /* - Get the _target_ vertices of the edges of type `edgeType` _out_ of `vertex` */ - Stream outV(RV vertex, AnyEdgeType edgeLabel); - default Stream outAtLeastOneV(RV vertex, AnyEdgeType edgeLabel) { return outV(vertex, edgeLabel); } - default Optional outAtMostOneV(RV vertex, AnyEdgeType edgeLabel) { return outV(vertex, edgeLabel).findFirst(); } - default RV outOneV(RV vertex, AnyEdgeType edgeLabel) { return outV(vertex, edgeLabel).findFirst().get(); } + Stream outV(RV vertex, AnyEdgeType edgeType); + default Stream outAtLeastOneV(RV vertex, AnyEdgeType edgeType) { return outV(vertex, edgeType); } + default Optional outAtMostOneV(RV vertex, AnyEdgeType edgeType) { return outV(vertex, edgeType).findFirst(); } + default RV outOneV(RV vertex, AnyEdgeType edgeType) { return outV(vertex, edgeType).findFirst().get(); } /* - Get the edges of type `edgeType` _into_ `vertex` */ - Stream inE(RV vertex, AnyEdgeType edgeLabel); - default Stream inAtLeastOneE(RV vertex, AnyEdgeType edgeLabel) { return inE(vertex, edgeLabel); } - default Optional inAtMostOneE(RV vertex, AnyEdgeType edgeLabel) { return inE(vertex, edgeLabel).findFirst(); } - default RE inOneE(RV vertex, AnyEdgeType edgeLabel) { return inE(vertex, edgeLabel).findFirst().get(); } + Stream inE(RV vertex, AnyEdgeType edgeType); + default Stream inAtLeastOneE(RV vertex, AnyEdgeType edgeType) { return inE(vertex, edgeType); } + default Optional inAtMostOneE(RV vertex, AnyEdgeType edgeType) { return inE(vertex, edgeType).findFirst(); } + default RE inOneE(RV vertex, AnyEdgeType edgeType) { return inE(vertex, edgeType).findFirst().get(); } /* - Get the _source_ vertices of the edges of type `edgeType` _into_ `vertex` */ - Stream inV(RV vertex, AnyEdgeType edgeLabel); - default Stream inAtLeastOneV(RV vertex, AnyEdgeType edgeLabel) { return inV(vertex, edgeLabel); } - default Optional inAtMostOneV(RV vertex, AnyEdgeType edgeLabel) { return inV(vertex, edgeLabel).findFirst(); } - default RV inOneV(RV vertex, AnyEdgeType edgeLabel) { return inV(vertex, edgeLabel).findFirst().get(); } + Stream inV(RV vertex, AnyEdgeType edgeType); + default Stream inAtLeastOneV(RV vertex, AnyEdgeType edgeType) { return inV(vertex, edgeType); } + default Optional inAtMostOneV(RV vertex, AnyEdgeType edgeType) { return inV(vertex, edgeType).findFirst(); } + default RV inOneV(RV vertex, AnyEdgeType edgeType) { return inV(vertex, edgeType).findFirst().get(); } /* #### Methods on edges */ @@ -76,9 +76,9 @@ public interface UntypedGraph /* #### Create vertices and edges */ - /* - Returns a new edge: source -[edgeLabel]-> target */ - RE addEdge(RV source, AnyEdgeType edgeLabel, RV target); + /* - Returns a new edge: source -[edgeType]-> target */ + RE addEdge(RV source, AnyEdgeType edgeType, RV target); /* - Returns a new vertex of type `vertexType` */ - RV addVertex(AnyVertexType vertexLabel); + RV addVertex(AnyVertexType vertexType); } diff --git a/version.sbt b/version.sbt index 6e13053..a3ddb27 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "0.7.0-early-access" +version in ThisBuild := "0.7.0-SNAPSHOT"