]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableNode.java
Fixed invalid comparisons which were identified by Eclipse IDE 2018-09
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / VariableNode.java
1 package org.simantics.db.layer0.variable;
2
3 public class VariableNode<Node> {
4     public final NodeSupport<Node> support;
5     public final Object node;
6     private int hash;
7     public VariableNode(NodeSupport<Node> support, Object node) {
8         assert(support != null);
9         this.support = support;
10         this.node = node;
11     }
12     
13     private int computeHash() {
14         return 31*support.hashCode() + 41*node.hashCode();
15     }
16
17     @Override
18     public int hashCode() {
19         if (hash == 0)
20             hash = computeHash();
21         return hash;
22     }
23     
24     @Override
25     public boolean equals(Object object) {
26         if (this == object)
27             return true;
28         else if (object == null)
29             return false;
30         else if (!(object instanceof VariableNode))
31             return false;
32         VariableNode<?> r = (VariableNode<?>)object;
33         if (r.hashCode() != hashCode())
34             return false;
35         return r.support.equals(support) && r.node.equals(node);
36     }
37     
38 }