This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delegate implementation of Relationship interface
- Loading branch information
Martin Kleppmann
committed
Jun 14, 2009
1 parent
c2a0a22
commit 0ad82dd
Showing
2 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/main/java/com/eptcomputing/neo4j/version/RelationshipImplBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
package com.eptcomputing.neo4j.version; | |||
|
|||
import org.neo4j.api.core.Node; | |||
import org.neo4j.api.core.Relationship; | |||
import org.neo4j.api.core.RelationshipType; | |||
|
|||
|
|||
/** | |||
* Implementation of the boring/repetitive parts of the Neo4j Relationship interface, | |||
* to support alternative implementations like versioned resources. | |||
* | |||
* See the Neo4j Relationship interface for documentation. | |||
*/ | |||
abstract class RelationshipImplBase extends PrimitiveBase implements Relationship, Comparable<Relationship> { | |||
|
|||
public abstract long getId(); | |||
|
|||
public abstract Node getStartNode(); | |||
|
|||
public abstract Node getEndNode(); | |||
|
|||
public abstract RelationshipType getType(); | |||
|
|||
public abstract void delete(); | |||
|
|||
public Node[] getNodes() { | |||
return new Node[] { getStartNode(), getEndNode() }; | |||
} | |||
|
|||
public Node getOtherNode(Node node) { | |||
if (getStartNode().equals(node)) return getEndNode(); | |||
else if (getEndNode().equals(node)) return getStartNode(); | |||
throw new RuntimeException("Node[" + node.getId() + "] not connected to this relationship[" + getId() + "]"); | |||
} | |||
|
|||
public boolean isType(RelationshipType otherType) { | |||
return (otherType != null) && otherType.name().equals(getType().name()); | |||
} | |||
|
|||
public String toString() { | |||
return "Relationship #" + this.getId() + " of type " + getType().name() + | |||
" between Node[" + getStartNode().getId() + "] and Node[" + getEndNode().getId() + "]"; | |||
} | |||
|
|||
public int compareTo(Relationship r) { | |||
int ourId = (int) this.getId(), theirId = (int) r.getId(); | |||
if (ourId < theirId) return -1; | |||
else if (ourId > theirId) return 1; | |||
else return 0; | |||
} | |||
|
|||
public boolean equals(Object o) { | |||
if (!(o instanceof Relationship)) return false; | |||
return this.getId() == ((Relationship) o).getId(); | |||
} | |||
|
|||
public int hashCode() { | |||
return (int) getId(); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters