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