1 package eu.ehri.project.core.impl.neo4j;
2
3
4 import com.tinkerpop.blueprints.Direction;
5 import com.tinkerpop.blueprints.Edge;
6 import com.tinkerpop.blueprints.Vertex;
7 import com.tinkerpop.blueprints.util.ExceptionFactory;
8 import com.tinkerpop.blueprints.util.StringFactory;
9 import org.neo4j.graphdb.Relationship;
10
11
12 public class Neo4j2Edge extends Neo4j2Element implements Edge {
13
14 public Neo4j2Edge(Relationship relationship, Neo4j2Graph graph) {
15 super(graph);
16 this.rawElement = relationship;
17 }
18
19 public String getLabel() {
20 this.graph.autoStartTransaction(false);
21 return ((Relationship) this.rawElement).getType().name();
22 }
23
24 public Vertex getVertex(Direction direction) {
25 this.graph.autoStartTransaction(false);
26 if (direction.equals(Direction.OUT))
27 return new Neo4j2Vertex(((Relationship) this.rawElement).getStartNode(), this.graph);
28 else if (direction.equals(Direction.IN))
29 return new Neo4j2Vertex(((Relationship) this.rawElement).getEndNode(), this.graph);
30 else
31 throw ExceptionFactory.bothIsNotSupported();
32
33 }
34
35 public boolean equals(Object object) {
36 return object instanceof Neo4j2Edge && ((Neo4j2Edge) object).getId().equals(this.getId());
37 }
38
39 public String toString() {
40 return StringFactory.edgeString(this);
41 }
42
43 public Relationship getRawEdge() {
44 return (Relationship) this.rawElement;
45 }
46 }