Skip to content

Commit 8384f1c

Browse files
author
gjdev
committed
Revert to the old behavior for Domain/Range annotations, introduce
Initial and Terminal annotations for edge framing Following the discussion in #65 the Domain and Range annotations are now deprecated. Instead of altering their semantics, the new behavior is activated by using Initial/Terminal instead of Domain/Range
1 parent ce36a25 commit 8384f1c

27 files changed

+338
-191
lines changed

CHANGELOG.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ h3. Version 2.4.0 (NOT OFFICIALLY RELEASED YET)
1515
</dependency>
1616
```
1717

18-
* Deprecate direction parameter for framing Edges from FramedGraph.frame. Starting from 2.4.0 the direction for Domain/Range annotations is taken from the edge direction.
18+
* Deprecate direction parameter for framing Edges from FramedGraph.frame. Starting from the next major release the direction parameter will be dropped. Instead of using Domain/Range annotations with a frame direction, you should use EdgeSource/EdgeTarget annotations that use the implicit direction of the edge.
1919
* Framing a null element returns null
2020
* Fixed NPE when enum property type set to null
2121
* Inheritance/Poymorphism support

src/main/java/com/tinkerpop/frames/Domain.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* The source of the adjacency.
1010
*
1111
* @author Marko A. Rodriguez (http://markorodriguez.com)
12+
*
13+
* @deprecated Use {@link Initial} or {@link Terminal} instead.
1214
*/
1315
@Retention(RetentionPolicy.RUNTIME)
1416
@Target(ElementType.METHOD)

src/main/java/com/tinkerpop/frames/FramedElement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class FramedElement implements InvocationHandler {
4242
}
4343

4444
/**
45-
* @deprecated The direction field will be dropped in 2.4.0
45+
* @deprecated The direction field will be dropped in the next major release
4646
*/
4747
public FramedElement(final FramedGraph framedGraph, final Element element, final Direction direction) {
4848
if (null == framedGraph) {
@@ -59,7 +59,7 @@ public FramedElement(final FramedGraph framedGraph, final Element element, final
5959
}
6060

6161
public FramedElement(final FramedGraph framedGraph, final Element element) {
62-
this(framedGraph, element, null);
62+
this(framedGraph, element, Direction.OUT);
6363
}
6464

6565
public Object invoke(final Object proxy, final Method method, final Object[] arguments) {

src/main/java/com/tinkerpop/frames/FramedGraph.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import com.tinkerpop.frames.annotations.AnnotationHandler;
1919
import com.tinkerpop.frames.annotations.DomainAnnotationHandler;
2020
import com.tinkerpop.frames.annotations.IncidenceAnnotationHandler;
21+
import com.tinkerpop.frames.annotations.InitialAnnotationHandler;
2122
import com.tinkerpop.frames.annotations.PropertyAnnotationHandler;
2223
import com.tinkerpop.frames.annotations.RangeAnnotationHandler;
24+
import com.tinkerpop.frames.annotations.TerminalAnnotationHandler;
2325
import com.tinkerpop.frames.annotations.gremlin.GremlinGroovyAnnotationHandler;
2426
import com.tinkerpop.frames.structures.FramedEdgeIterable;
2527
import com.tinkerpop.frames.structures.FramedVertexIterable;
@@ -68,6 +70,8 @@ public FramedGraph(final T baseGraph) {
6870
registerAnnotationHandler(new IncidenceAnnotationHandler());
6971
registerAnnotationHandler(new DomainAnnotationHandler());
7072
registerAnnotationHandler(new RangeAnnotationHandler());
73+
registerAnnotationHandler(new InitialAnnotationHandler());
74+
registerAnnotationHandler(new TerminalAnnotationHandler());
7175
registerAnnotationHandler(new GremlinGroovyAnnotationHandler());
7276
}
7377

@@ -117,8 +121,8 @@ public <F> F frame(final Vertex vertex, final Class<F> kind) {
117121
* @return a proxy objects backed by an edge and interpreted from the
118122
* perspective of the annotate interface or null if the edge paramenter was null
119123
*
120-
* @deprecated Use {@link #frame(Edge, Class)}, which uses the edge direction to determine
121-
* {@link Domain} and {@link Range} of the frame.
124+
* @deprecated Use {@link #frame(Edge, Class)}, in combination with {@link Initial}
125+
* and {@link Terminal}.
122126
*/
123127
public <F> F frame(final Edge edge, final Direction direction,
124128
final Class<F> kind) {
@@ -141,7 +145,7 @@ public <F> F frame(final Edge edge, final Direction direction,
141145

142146
/**
143147
* A helper method for framing an edge. Note that all framed edges implement
144-
* {@link EdgeFrame} to allow access to the underlying element
148+
* {@link EdgeFrame} to allow access to the underlying element.
145149
*
146150
* @param edge
147151
* the edge to frame
@@ -153,7 +157,7 @@ public <F> F frame(final Edge edge, final Direction direction,
153157
* perspective of the annotate interface or null if the edge paramenter was null
154158
*/
155159
public <F> F frame(final Edge edge, final Class<F> kind) {
156-
return frame(edge, null, kind);
160+
return frame(edge, Direction.OUT, kind);
157161
}
158162

159163
/**
@@ -187,8 +191,8 @@ public <F> Iterable<F> frameVertices(final Iterable<Vertex> vertices,
187191
* @return an iterable of proxy objects backed by an edge and interpreted
188192
* from the perspective of the annotate interface
189193
*
190-
* @deprecated Use {@link #frameEdges(Iterable, Class)}, which uses the edge direction to determine
191-
* {@link Domain} and {@link Range} of the framed edges.
194+
* @deprecated Use {@link #frameEdges(Iterable, Class)}, in combination with {@link Initial}
195+
* and {@link Terminal}.
192196
*/
193197
public <F> Iterable<F> frameEdges(final Iterable<Edge> edges,
194198
final Direction direction, final Class<F> kind) {
@@ -276,8 +280,8 @@ public Edge getEdge(final Object id) {
276280
* @return a proxy object backed by the edge and interpreted from the
277281
* perspective of the annotate interface
278282
*
279-
* @deprecated Use {@link #getEdges(Object, Class)}, which uses the edge direction to determine
280-
* {@link Domain} and {@link Range} of the framed edge.
283+
* @deprecated Use {@link #getEdges(Object, Class)}, in combination with {@link Initial}
284+
* and {@link Terminal}.
281285
*/
282286
public <F> F getEdge(final Object id, final Direction direction,
283287
final Class<F> kind) {
@@ -328,8 +332,7 @@ public Edge addEdge(final Object id, final Vertex outVertex,
328332
* perspective of the annotate interface
329333
*
330334
* @deprecated Use {@link #addEdge(Object, Vertex, Vertex, String, Class)},
331-
* which uses the edge direction to determine {@link Domain}
332-
* and {@link Range} of the framed edge.
335+
* in combination with {@link Initial} and {@link Terminal}.
333336
*/
334337
public <F> F addEdge(final Object id, final Vertex outVertex,
335338
final Vertex inVertex, final String label,
@@ -344,7 +347,7 @@ public <F> F addEdge(final Object id, final Vertex outVertex,
344347
public <F> F addEdge(final Object id, final Vertex outVertex,
345348
final Vertex inVertex, final String label,
346349
final Class<F> kind) {
347-
return addEdge(id, outVertex, inVertex, label, null, kind);
350+
return addEdge(id, outVertex, inVertex, label, Direction.OUT, kind);
348351
}
349352

350353
public void removeVertex(final Vertex vertex) {
@@ -407,9 +410,8 @@ public Iterable<Edge> getEdges(final String key, final Object value) {
407410
* @return an iterable of proxy objects backed by the edges and interpreted
408411
* from the perspective of the annotate interface
409412
*
410-
* @deprecated Use {@link #getEdges(String, Object, Class)},
411-
* which uses the edge direction to determine {@link Domain}
412-
* and {@link Range} of the framed edges.
413+
* @deprecated Use {@link #getEdges(String, Object, Class)}, in combination with
414+
* {@link Initial} and {@link Terminal}.
413415
*/
414416
public <F> Iterable<F> getEdges(final String key, final Object value,
415417
final Direction direction, final Class<F> kind) {
@@ -432,10 +434,6 @@ public <F> Iterable<F> getEdges(final String key, final Object value,
432434
* the default type of the annotated interface
433435
* @return an iterable of proxy objects backed by the edges and interpreted
434436
* from the perspective of the annotate interface
435-
*
436-
* @deprecated Use {@link #getEdges(String, Object, Class)},
437-
* which uses the edge direction to determine {@link Domain}
438-
* and {@link Range} of the framed edges.
439437
*/
440438
public <F> Iterable<F> getEdges(final String key, final Object value,
441439
final Class<F> kind) {

src/main/java/com/tinkerpop/frames/FramedGraphFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import com.tinkerpop.frames.annotations.AdjacencyAnnotationHandler;
66
import com.tinkerpop.frames.annotations.DomainAnnotationHandler;
77
import com.tinkerpop.frames.annotations.IncidenceAnnotationHandler;
8+
import com.tinkerpop.frames.annotations.InitialAnnotationHandler;
89
import com.tinkerpop.frames.annotations.PropertyAnnotationHandler;
910
import com.tinkerpop.frames.annotations.RangeAnnotationHandler;
11+
import com.tinkerpop.frames.annotations.TerminalAnnotationHandler;
1012

1113
/**
1214
* Creates a factory for creating {@link FramedGraph}s using a set of modules to
@@ -86,6 +88,8 @@ private FramedGraphConfiguration getBaseConfig() {
8688
config.addAnnotationhandler(new IncidenceAnnotationHandler());
8789
config.addAnnotationhandler(new DomainAnnotationHandler());
8890
config.addAnnotationhandler(new RangeAnnotationHandler());
91+
config.addAnnotationhandler(new InitialAnnotationHandler());
92+
config.addAnnotationhandler(new TerminalAnnotationHandler());
8993
return config;
9094
}
9195

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.tinkerpop.frames;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Marks the Initial Vertex (source) of a framed edge.
10+
*/
11+
@Retention(RetentionPolicy.RUNTIME)
12+
@Target(ElementType.METHOD)
13+
public @interface Initial {
14+
}

src/main/java/com/tinkerpop/frames/Range.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* The target of the adjacency.
1010
*
1111
* @author Marko A. Rodriguez (http://markorodriguez.com)
12+
*
13+
* @deprecated Use {@link Initial} or {@link Terminal} instead.
1214
*/
1315
@Retention(RetentionPolicy.RUNTIME)
1416
@Target(ElementType.METHOD)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.tinkerpop.frames;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Marks the Terminal Vertex (target) of a framed edge.
10+
*/
11+
@Retention(RetentionPolicy.RUNTIME)
12+
@Target(ElementType.METHOD)
13+
public @interface Terminal {
14+
}

src/main/java/com/tinkerpop/frames/annotations/DomainAnnotationHandler.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ public Object processElement(final Domain annotation, final Method method, final
2525
}
2626

2727
public Object processEdge(final Domain annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Edge edge, final Direction direction) {
28-
if (direction != null)
29-
//deprecated behavior: the edge direction should be used instead
30-
return framedGraph.frame(edge.getVertex(direction), method.getReturnType());
31-
//correct behavior (not using deprecated edge-framing is used):
32-
return framedGraph.frame(edge.getVertex(Direction.OUT), method.getReturnType());
28+
return framedGraph.frame(edge.getVertex(direction), method.getReturnType());
3329
}
3430

3531
}

src/main/java/com/tinkerpop/frames/annotations/IncidenceAnnotationHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public Object processElement(final Incidence annotation, final Method method, fi
3030

3131
public Object processVertex(final Incidence incidence, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Vertex element) {
3232
if (ClassUtilities.isGetMethod(method)) {
33-
return new FramedEdgeIterable(framedGraph, element.getEdges(incidence.direction(), incidence.label()), ClassUtilities.getGenericClass(method));
33+
return new FramedEdgeIterable(framedGraph, element.getEdges(incidence.direction(), incidence.label()), incidence.direction(), ClassUtilities.getGenericClass(method));
3434
} else if (ClassUtilities.isAddMethod(method)) {
3535

3636
switch(incidence.direction()) {
3737
case OUT:
38-
return framedGraph.addEdge(null, element, ((VertexFrame) arguments[0]).asVertex(), incidence.label(), method.getReturnType());
38+
return framedGraph.addEdge(null, element, ((VertexFrame) arguments[0]).asVertex(), incidence.label(), Direction.OUT, method.getReturnType());
3939
case IN:
40-
return framedGraph.addEdge(null, ((VertexFrame) arguments[0]).asVertex(), element, incidence.label(), method.getReturnType());
40+
return framedGraph.addEdge(null, ((VertexFrame) arguments[0]).asVertex(), element, incidence.label(), Direction.IN, method.getReturnType());
4141
case BOTH:
4242
throw new UnsupportedOperationException("Direction.BOTH it not supported on 'add' or 'set' methods");
4343
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.tinkerpop.frames.annotations;
2+
3+
import com.tinkerpop.blueprints.Direction;
4+
import com.tinkerpop.blueprints.Edge;
5+
import com.tinkerpop.blueprints.Element;
6+
import com.tinkerpop.frames.FramedGraph;
7+
import com.tinkerpop.frames.Initial;
8+
9+
import java.lang.reflect.Method;
10+
11+
public class InitialAnnotationHandler implements AnnotationHandler<Initial> {
12+
@Override
13+
public Class<Initial> getAnnotationType() {
14+
return Initial.class;
15+
}
16+
17+
@Override
18+
public Object processElement(final Initial annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Element element, final Direction direction) {
19+
if (element instanceof Edge) {
20+
return framedGraph.frame(((Edge)element).getVertex(Direction.OUT), method.getReturnType());
21+
} else {
22+
throw new UnsupportedOperationException();
23+
}
24+
}
25+
}

src/main/java/com/tinkerpop/frames/annotations/RangeAnnotationHandler.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ public Object processElement(final Range annotation, final Method method, final
2525
}
2626

2727
public Object processEdge(final Range annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Edge edge, final Direction direction) {
28-
if (direction != null)
29-
//deprecated behavior: the edge direction should be used instead
30-
return framedGraph.frame(edge.getVertex(direction.opposite()), method.getReturnType());
31-
//correct behavior (not using deprecated edge-framing is used):
32-
return framedGraph.frame(edge.getVertex(Direction.IN), method.getReturnType());
28+
return framedGraph.frame(edge.getVertex(direction.opposite()), method.getReturnType());
3329
}
3430

3531
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.tinkerpop.frames.annotations;
2+
3+
import com.tinkerpop.blueprints.Direction;
4+
import com.tinkerpop.blueprints.Edge;
5+
import com.tinkerpop.blueprints.Element;
6+
import com.tinkerpop.frames.FramedGraph;
7+
import com.tinkerpop.frames.Terminal;
8+
9+
import java.lang.reflect.Method;
10+
11+
public class TerminalAnnotationHandler implements AnnotationHandler<Terminal> {
12+
@Override
13+
public Class<Terminal> getAnnotationType() {
14+
return Terminal.class;
15+
}
16+
17+
@Override
18+
public Object processElement(final Terminal annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Element element, final Direction direction) {
19+
if (element instanceof Edge) {
20+
return framedGraph.frame(((Edge)element).getVertex(Direction.IN), method.getReturnType());
21+
} else {
22+
throw new UnsupportedOperationException();
23+
}
24+
}
25+
}

src/main/java/com/tinkerpop/frames/structures/FramedEdgeIterable.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.tinkerpop.blueprints.Direction;
44
import com.tinkerpop.blueprints.Edge;
55
import com.tinkerpop.blueprints.Graph;
6-
import com.tinkerpop.frames.Domain;
6+
import com.tinkerpop.frames.Initial;
7+
import com.tinkerpop.frames.Terminal;
78
import com.tinkerpop.frames.FramedGraph;
8-
import com.tinkerpop.frames.Range;
99

1010
import java.util.Iterator;
1111

@@ -19,8 +19,8 @@ public class FramedEdgeIterable<T> implements Iterable<T> {
1919
protected final FramedGraph<? extends Graph> framedGraph;
2020

2121
/**
22-
* @deprecated Use {@link #FramedEdgeIterable(FramedGraph, Iterable, Class)}, which uses
23-
* the edge direction to determine {@link Domain} and {@link Range} of the frame.
22+
* @deprecated Use {@link #FramedEdgeIterable(FramedGraph, Iterable, Class)}, in combination with {@link Initial}
23+
* and {@link Terminal}.
2424
*/
2525
public FramedEdgeIterable(final FramedGraph<? extends Graph> framedGraph, final Iterable<Edge> iterable, final Direction direction, final Class<T> kind) {
2626
this.framedGraph = framedGraph;
@@ -33,7 +33,7 @@ public FramedEdgeIterable(final FramedGraph<? extends Graph> framedGraph, final
3333
this.framedGraph = framedGraph;
3434
this.iterable = iterable;
3535
this.kind = kind;
36-
this.direction = null;
36+
this.direction = Direction.OUT;
3737
}
3838

3939
public Iterator<T> iterator() {

0 commit comments

Comments
 (0)