]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableReference.java
Tried to improve the implementation of getPossibleDomainProperty
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / VariableReference.java
1 package org.simantics.db.layer0.variable;
2
3 import org.simantics.databoard.type.Datatype;
4 import org.simantics.utils.ObjectUtils;
5
6 /**
7  * @author Tuukka Lehtonen
8  */
9 public class VariableReference {
10
11     public final RVI variableId;
12
13     public final Datatype datatype;
14
15     public String label;
16
17     public static VariableReference of(RVI variableId, Datatype datatype, String label) {
18         return new VariableReference(variableId, datatype, label);
19     }
20
21     public VariableReference(RVI variableId, Datatype datatype, String label) {
22         if (variableId == null)
23             throw new NullPointerException("null variable reference");
24         this.variableId = variableId;
25         this.datatype = datatype;
26         this.label = label;
27     }
28     
29     public RVI getVariableId() {
30         return variableId;
31     }
32
33     public Datatype getDatatype() {
34         return datatype;
35     }
36
37     public String getLabel() {
38         return label;
39     }
40
41     @Override
42     public int hashCode() {
43         return ObjectUtils.hashCode(datatype) * 31 + variableId.hashCode();
44     }
45
46     @Override
47     public boolean equals(Object obj) {
48         if (this == obj)
49             return true;
50         if (obj == null)
51             return false;
52         if (getClass() != obj.getClass())
53             return false;
54         VariableReference other = (VariableReference) obj;
55         return variableId.equals(other.variableId) && ObjectUtils.objectEquals(datatype, other.datatype);
56 //                && ObjectUtils.objectEquals(label, other.label);
57     }
58
59     @Override
60     public String toString() {
61         StringBuilder sb = new StringBuilder();
62         sb.append(variableId);
63         if (datatype != null)
64             sb.append(" : ").append(datatype.toSingleLineString());
65         if (label != null)
66             sb.append(" (").append(label).append(")");
67         return sb.toString();
68     }
69
70 }