Skip to content

Commit 3b689cd

Browse files
committed
Merge branch 'gjdev-edgedir3'
Conflicts: CHANGELOG.textile
2 parents 939e363 + 78ddce8 commit 3b689cd

20 files changed

+455
-31
lines changed

CHANGELOG.textile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ h3. Version 2.4.0 (NOT OFFICIALLY RELEASED YET)
1515
</dependency>
1616
```
1717

18+
* Deprecate the direction parameter for framing Edges from FramedGraph.frame. When using Initial/Terminal to annotate the out/in vertices of an edgeframe, the direction parameter is not used. The deprecated methods will be removed in the next major release.
19+
* Deprecate the Domain and Range annotations in favour of Initial and Terminal. See #65 and #57 for the rationale behind this change. Domain and Range will be removed from the next major release.
20+
* Introduce Initial and Terminal annotations for framed edges to set the source (out-vertex) and target (in-vertex) of an edge frame. These annotations will replace Domain and Range in the next major release.
1821
* Framing a @null@ element returns @null@
1922
* Fixed @NullPointerException@ when enum property type set to @null@
2023
* 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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public class FramedElement implements InvocationHandler {
4141
}
4242
}
4343

44+
/**
45+
* @deprecated The direction field will be dropped in the next major release
46+
*/
4447
public FramedElement(final FramedGraph framedGraph, final Element element, final Direction direction) {
4548
if (null == framedGraph) {
4649
throw new IllegalArgumentException("FramedGraph can not be null");
@@ -56,7 +59,7 @@ public FramedElement(final FramedGraph framedGraph, final Element element, final
5659
}
5760

5861
public FramedElement(final FramedGraph framedGraph, final Element element) {
59-
this(framedGraph, element, null);
62+
this(framedGraph, element, Direction.OUT);
6063
}
6164

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

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

Lines changed: 101 additions & 0 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

@@ -116,6 +120,9 @@ public <F> F frame(final Vertex vertex, final Class<F> kind) {
116120
* the default type of the annotated interface
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
123+
*
124+
* @deprecated Use {@link #frame(Edge, Class)}, in combination with {@link Initial}
125+
* and {@link Terminal}.
119126
*/
120127
public <F> F frame(final Edge edge, final Direction direction,
121128
final Class<F> kind) {
@@ -135,6 +142,23 @@ public <F> F frame(final Edge edge, final Direction direction,
135142
resolvedTypes.toArray(new Class[resolvedTypes.size()]),
136143
new FramedElement(this, edge, direction));
137144
}
145+
146+
/**
147+
* A helper method for framing an edge. Note that all framed edges implement
148+
* {@link EdgeFrame} to allow access to the underlying element.
149+
*
150+
* @param edge
151+
* the edge to frame
152+
* @param kind
153+
* the default annotated interface to frame the edges as
154+
* @param <F>
155+
* the default type of the annotated interface
156+
* @return a proxy objects backed by an edge and interpreted from the
157+
* perspective of the annotate interface or null if the edge paramenter was null
158+
*/
159+
public <F> F frame(final Edge edge, final Class<F> kind) {
160+
return frame(edge, Direction.OUT, kind);
161+
}
138162

139163
/**
140164
* A helper method for framing an iterable of vertices.
@@ -166,11 +190,33 @@ public <F> Iterable<F> frameVertices(final Iterable<Vertex> vertices,
166190
* the default type of the annotated interface
167191
* @return an iterable of proxy objects backed by an edge and interpreted
168192
* from the perspective of the annotate interface
193+
*
194+
* @deprecated Use {@link #frameEdges(Iterable, Class)}, in combination with {@link Initial}
195+
* and {@link Terminal}.
169196
*/
170197
public <F> Iterable<F> frameEdges(final Iterable<Edge> edges,
171198
final Direction direction, final Class<F> kind) {
172199
return new FramedEdgeIterable<F>(this, edges, direction, kind);
173200
}
201+
202+
/**
203+
* A helper method for framing an iterable of edges.
204+
*
205+
* @param edges
206+
* the edges to frame
207+
* @param direction
208+
* the direction of the edges
209+
* @param kind
210+
* the default annotated interface to frame the edges as
211+
* @param <F>
212+
* the default type of the annotated interface
213+
* @return an iterable of proxy objects backed by an edge and interpreted
214+
* from the perspective of the annotate interface
215+
*/
216+
public <F> Iterable<F> frameEdges(final Iterable<Edge> edges,
217+
final Class<F> kind) {
218+
return new FramedEdgeIterable<F>(this, edges, kind);
219+
}
174220

175221
public Vertex getVertex(final Object id) {
176222
return config.getConfiguredGraph().getVertex(id);
@@ -233,11 +279,32 @@ public Edge getEdge(final Object id) {
233279
* the default type of the annotated interface
234280
* @return a proxy object backed by the edge and interpreted from the
235281
* perspective of the annotate interface
282+
*
283+
* @deprecated Use {@link #getEdges(Object, Class)}, in combination with {@link Initial}
284+
* and {@link Terminal}.
236285
*/
237286
public <F> F getEdge(final Object id, final Direction direction,
238287
final Class<F> kind) {
239288
return this.frame(getEdge(id), direction, kind);
240289
}
290+
291+
/**
292+
* Frame an edge according to a particular kind of annotated interface.
293+
*
294+
* @param id
295+
* the id of the edge
296+
* @param direction
297+
* the direction of the edge
298+
* @param kind
299+
* the default annotated interface to frame the edge as
300+
* @param <F>
301+
* the default type of the annotated interface
302+
* @return a proxy object backed by the edge and interpreted from the
303+
* perspective of the annotate interface
304+
*/
305+
public <F> F getEdge(final Object id, final Class<F> kind) {
306+
return this.frame(getEdge(id), kind);
307+
}
241308

242309
public Edge addEdge(final Object id, final Vertex outVertex,
243310
final Vertex inVertex, final String label) {
@@ -263,6 +330,9 @@ public Edge addEdge(final Object id, final Vertex outVertex,
263330
* the default type of the annotated interface
264331
* @return a proxy object backed by the edge and interpreted from the
265332
* perspective of the annotate interface
333+
*
334+
* @deprecated Use {@link #addEdge(Object, Vertex, Vertex, String, Class)},
335+
* in combination with {@link Initial} and {@link Terminal}.
266336
*/
267337
public <F> F addEdge(final Object id, final Vertex outVertex,
268338
final Vertex inVertex, final String label,
@@ -273,6 +343,12 @@ public <F> F addEdge(final Object id, final Vertex outVertex,
273343
}
274344
return this.frame(edge, direction, kind);
275345
}
346+
347+
public <F> F addEdge(final Object id, final Vertex outVertex,
348+
final Vertex inVertex, final String label,
349+
final Class<F> kind) {
350+
return addEdge(id, outVertex, inVertex, label, Direction.OUT, kind);
351+
}
276352

277353
public void removeVertex(final Vertex vertex) {
278354
config.getConfiguredGraph().removeVertex(vertex);
@@ -333,12 +409,37 @@ public Iterable<Edge> getEdges(final String key, final Object value) {
333409
* the default type of the annotated interface
334410
* @return an iterable of proxy objects backed by the edges and interpreted
335411
* from the perspective of the annotate interface
412+
*
413+
* @deprecated Use {@link #getEdges(String, Object, Class)}, in combination with
414+
* {@link Initial} and {@link Terminal}.
336415
*/
337416
public <F> Iterable<F> getEdges(final String key, final Object value,
338417
final Direction direction, final Class<F> kind) {
339418
return new FramedEdgeIterable<F>(this, config.getConfiguredGraph().getEdges(key,
340419
value), direction, kind);
341420
}
421+
422+
/**
423+
* Frame edges according to a particular kind of annotated interface.
424+
*
425+
* @param key
426+
* the key of the edges to get
427+
* @param value
428+
* the value of the edges to get
429+
* @param direction
430+
* the direction of the edges
431+
* @param kind
432+
* the default annotated interface to frame the edges as
433+
* @param <F>
434+
* the default type of the annotated interface
435+
* @return an iterable of proxy objects backed by the edges and interpreted
436+
* from the perspective of the annotate interface
437+
*/
438+
public <F> Iterable<F> getEdges(final String key, final Object value,
439+
final Class<F> kind) {
440+
return new FramedEdgeIterable<F>(this, config.getConfiguredGraph().getEdges(key,
441+
value), kind);
442+
}
342443

343444
public Features getFeatures() {
344445
Features features = config.getConfiguredGraph().getFeatures().copyFeatures();

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+
}
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+
}
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.tinkerpop.blueprints.Direction;
44
import com.tinkerpop.blueprints.Edge;
55
import com.tinkerpop.blueprints.Graph;
6+
import com.tinkerpop.frames.Initial;
7+
import com.tinkerpop.frames.Terminal;
68
import com.tinkerpop.frames.FramedGraph;
79

810
import java.util.Iterator;
@@ -16,12 +18,23 @@ public class FramedEdgeIterable<T> implements Iterable<T> {
1618
protected final Iterable<Edge> iterable;
1719
protected final FramedGraph<? extends Graph> framedGraph;
1820

21+
/**
22+
* @deprecated Use {@link #FramedEdgeIterable(FramedGraph, Iterable, Class)}, in combination with {@link Initial}
23+
* and {@link Terminal}.
24+
*/
1925
public FramedEdgeIterable(final FramedGraph<? extends Graph> framedGraph, final Iterable<Edge> iterable, final Direction direction, final Class<T> kind) {
2026
this.framedGraph = framedGraph;
2127
this.iterable = iterable;
2228
this.kind = kind;
2329
this.direction = direction;
2430
}
31+
32+
public FramedEdgeIterable(final FramedGraph<? extends Graph> framedGraph, final Iterable<Edge> iterable, final Class<T> kind) {
33+
this.framedGraph = framedGraph;
34+
this.iterable = iterable;
35+
this.kind = kind;
36+
this.direction = Direction.OUT;
37+
}
2538

2639
public Iterator<T> iterator() {
2740
return new Iterator<T>() {

0 commit comments

Comments
 (0)