]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 package org.simantics.structural2.queries;\r
2 \r
3 import org.simantics.db.ReadGraph;\r
4 import org.simantics.db.Resource;\r
5 import org.simantics.db.common.utils.NameUtils;\r
6 import org.simantics.db.exception.DatabaseException;\r
7 \r
8 /**\r
9  * @author Tuukka Lehtonen\r
10  */\r
11 public class Terminal {\r
12 \r
13     private final Resource component;\r
14     private final Resource relation;\r
15 \r
16     private final int      hash;\r
17 \r
18     public Terminal(Resource component, Resource relation) {\r
19         this.component = component;\r
20         this.relation = relation;\r
21         this.hash = makeHash();\r
22     }\r
23 \r
24     @Override\r
25     public boolean equals(Object obj) {\r
26         if (this == obj)\r
27             return true;\r
28         if (obj == null)\r
29             return false;\r
30         if (!(obj.getClass().equals(this.getClass())))\r
31             return false;\r
32         Terminal other = (Terminal) obj;\r
33         return component.equals(other.component) && relation.equals(other.relation);\r
34     }\r
35 \r
36     public Resource getComponent() {\r
37         return component;\r
38     }\r
39 \r
40     public Resource getRelation() {\r
41         return relation;\r
42     }\r
43 \r
44     private int makeHash() {\r
45         return component.hashCode() + relation.hashCode() * 31;\r
46     }\r
47 \r
48     @Override\r
49     public int hashCode() {\r
50         return hash;\r
51     }\r
52 \r
53     @Override\r
54     public String toString() {\r
55         return component + " " + relation;\r
56     }\r
57 \r
58     public String toString(ReadGraph graph) throws DatabaseException {\r
59         return NameUtils.getSafeName(graph, component) + " " + NameUtils.getSafeName(graph, relation);\r
60     }\r
61 \r
62 }\r