Permalink
Browse files

remformatted code, optimzied imports, and added FramesManager.createF…

…ramedVertex().
  • Loading branch information...
1 parent 3bd8eb1 commit 7d2bf62c4e9d731caa731095729deeee52c8e95d @okram okram committed Jan 23, 2012
View
@@ -22,6 +22,7 @@ h3. Version 0.7 (NOT OFFICIALLY RELEASED YET)
* Added support for registering annotations
* Added more @frame@-based methods to @FramesManager@
* Added support for inference determined by a @GremlinGroovy@ annotation
+* Added helper method @FramesManager.createFramedVertex()@
==<hr/>==
@@ -2,7 +2,6 @@
import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Graph;
-import com.tinkerpop.blueprints.pgm.Index;
import com.tinkerpop.blueprints.pgm.IndexableGraph;
import com.tinkerpop.blueprints.pgm.Vertex;
import com.tinkerpop.frames.annotations.AdjacencyAnnotationHandler;
@@ -94,6 +93,29 @@ public Graph getGraph() {
}
/**
+ * Create a vertex in the underlying graph and frame it according to provided annotated interface.
+ *
+ * @param kind the annotated interface to frame the created vertex as
+ * @param <T> the type of the annotated interface
+ * @return a proxy object backed by the vertex and interpreted from the perspective of the annotate interface
+ */
+ public <T> T createFramedVertex(final Class<T> kind) {
+ return this.frame(graph.addVertex(null), kind);
+ }
+
+ /**
+ * Create a vertex (with provided id) in the underlying graph and frame it according to provided annotated interface.
+ *
+ * @param id the id to use when creating the underlying vertex
+ * @param kind the annotated interface to frame the created vertex as
+ * @param <T> the type of the annotated interface
+ * @return a proxy object backed by the vertex and interpreted from the perspective of the annotate interface
+ */
+ public <T> T createFramedVertex(final Object id, final Class<T> kind) {
+ return this.frame(graph.addVertex(id), kind);
+ }
+
+ /**
* Frame an edge according to a particular kind of annotated interface.
*
* @param id the id of the edge
@@ -1,8 +1,5 @@
package com.tinkerpop.frames.annotations;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Vertex;
import com.tinkerpop.frames.Adjacency;
@@ -12,6 +9,9 @@
import com.tinkerpop.frames.util.AdjacencyCollection;
import com.tinkerpop.frames.util.ClassUtils;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
public class AdjacencyAnnotationHandler implements AnnotationHandler<Adjacency> {
@Override
@@ -1,13 +1,13 @@
package com.tinkerpop.frames.annotations;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Vertex;
import com.tinkerpop.frames.Direction;
import com.tinkerpop.frames.FramesManager;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
public interface AnnotationHandler<T extends Annotation> {
public Class<T> getAnnotationType();
@@ -1,13 +1,13 @@
package com.tinkerpop.frames.annotations;
-import java.lang.reflect.Method;
-
import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Vertex;
import com.tinkerpop.frames.Direction;
import com.tinkerpop.frames.Domain;
import com.tinkerpop.frames.FramesManager;
+import java.lang.reflect.Method;
+
public class DomainAnnotationHandler implements AnnotationHandler<Domain> {
@Override
@@ -1,7 +1,5 @@
package com.tinkerpop.frames.annotations;
-import java.lang.reflect.Method;
-
import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Element;
import com.tinkerpop.blueprints.pgm.Vertex;
@@ -10,6 +8,8 @@
import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.util.ClassUtils;
+import java.lang.reflect.Method;
+
public class PropertyAnnotationHandler implements AnnotationHandler<Property> {
@Override
@@ -1,13 +1,13 @@
package com.tinkerpop.frames.annotations;
-import java.lang.reflect.Method;
-
import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Vertex;
import com.tinkerpop.frames.Direction;
import com.tinkerpop.frames.FramesManager;
import com.tinkerpop.frames.Range;
+import java.lang.reflect.Method;
+
public class RangeAnnotationHandler implements AnnotationHandler<Range> {
@Override
@@ -1,11 +1,5 @@
package com.tinkerpop.frames.annotations;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-
import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Graph;
import com.tinkerpop.blueprints.pgm.Vertex;
@@ -16,6 +10,12 @@
import com.tinkerpop.frames.util.ClassUtils;
import com.tinkerpop.frames.util.RelationCollection;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
public class RelationAnnotationHandler implements AnnotationHandler<Relation> {
@Override
@@ -4,12 +4,9 @@
import com.tinkerpop.blueprints.pgm.Element;
import com.tinkerpop.blueprints.pgm.Vertex;
import com.tinkerpop.frames.Direction;
-import com.tinkerpop.frames.Domain;
import com.tinkerpop.frames.FramesManager;
-import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.annotations.AnnotationHandler;
import com.tinkerpop.frames.util.ClassUtils;
-import com.tinkerpop.frames.util.FramingEdgeIterable;
import com.tinkerpop.frames.util.FramingVertexIterable;
import com.tinkerpop.frames.util.IterableCollection;
import com.tinkerpop.gremlin.groovy.Gremlin;
@@ -1,11 +1,11 @@
package com.tinkerpop.frames.util;
+import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
+
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Collection;
-import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
-
public class ClassUtils {
private static final String SET = "set";
private static final String GET = "get";
@@ -1,8 +1,11 @@
package com.tinkerpop.frames;
import com.tinkerpop.blueprints.pgm.AutomaticIndex;
+import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Graph;
import com.tinkerpop.blueprints.pgm.Index;
+import com.tinkerpop.blueprints.pgm.Vertex;
+import com.tinkerpop.blueprints.pgm.impls.tg.TinkerGraph;
import com.tinkerpop.blueprints.pgm.impls.tg.TinkerGraphFactory;
import com.tinkerpop.frames.domain.classes.Person;
import com.tinkerpop.frames.domain.classes.Project;
@@ -54,4 +57,31 @@ public void testFrameEdges() {
}
assertEquals(counter, 2);
}
+
+ public void testCreateFrame() {
+ Graph graph = new TinkerGraph();
+ FramesManager manager = new FramesManager(graph);
+ Person person = manager.createFramedVertex(Person.class);
+ assertEquals(person.asVertex(), graph.getVertices().iterator().next());
+ int counter = 0;
+ for (Vertex v : graph.getVertices()) {
+ counter++;
+ }
+ assertEquals(counter, 1);
+ counter = 0;
+ for (Edge e : graph.getEdges()) {
+ counter++;
+ }
+ assertEquals(counter, 0);
+ Person person2 = manager.createFramedVertex("aPerson", Person.class);
+ assertEquals(person2.asVertex().getId(), "aPerson");
+ counter = 0;
+ for (Vertex v : graph.getVertices()) {
+ counter++;
+ }
+ assertEquals(counter, 2);
+
+
+ }
+
}

0 comments on commit 7d2bf62

Please sign in to comment.