]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural2/src/org/simantics/structural2/queries/Terminal.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / queries / Terminal.java
diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/Terminal.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/Terminal.java
new file mode 100644 (file)
index 0000000..38e7f18
--- /dev/null
@@ -0,0 +1,62 @@
+package org.simantics.structural2.queries;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class Terminal {\r
+\r
+    private final Resource component;\r
+    private final Resource relation;\r
+\r
+    private final int      hash;\r
+\r
+    public Terminal(Resource component, Resource relation) {\r
+        this.component = component;\r
+        this.relation = relation;\r
+        this.hash = makeHash();\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj)\r
+            return true;\r
+        if (obj == null)\r
+            return false;\r
+        if (!(obj.getClass().equals(this.getClass())))\r
+            return false;\r
+        Terminal other = (Terminal) obj;\r
+        return component.equals(other.component) && relation.equals(other.relation);\r
+    }\r
+\r
+    public Resource getComponent() {\r
+        return component;\r
+    }\r
+\r
+    public Resource getRelation() {\r
+        return relation;\r
+    }\r
+\r
+    private int makeHash() {\r
+        return component.hashCode() + relation.hashCode() * 31;\r
+    }\r
+\r
+    @Override\r
+    public int hashCode() {\r
+        return hash;\r
+    }\r
+\r
+    @Override\r
+    public String toString() {\r
+        return component + " " + relation;\r
+    }\r
+\r
+    public String toString(ReadGraph graph) throws DatabaseException {\r
+        return NameUtils.getSafeName(graph, component) + " " + NameUtils.getSafeName(graph, relation);\r
+    }\r
+\r
+}\r