]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph/src/org/simantics/graph/matching/Stat.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.graph / src / org / simantics / graph / matching / Stat.java
1 package org.simantics.graph.matching;
2
3 import java.util.Comparator;
4
5 class Stat {
6         public int p, o;
7
8         public Stat(int p, int o) {
9                 this.p = p;
10                 this.o = o;
11         }
12         
13         public Stat(Stat stat) {
14                 this.p = stat.p;
15                 this.o = stat.o;
16         }
17         
18         public void map(int[] map) {
19                 if(p >= 0)
20                         p = map[p];
21                 if(o >= 0)
22                         o = map[o];
23         }
24         
25         @Override
26         public String toString() {
27                 return p + " " + o;
28         }
29         
30         public String toString(String[] names) {
31                 return (p >= 0 ? names[p] : "?") + " " + (o >= 0 ? names[o] : "?");
32         }
33         
34         @Override
35         public int hashCode() {
36                 return 31*p + o;
37         }
38
39         @Override
40         public boolean equals(Object obj) {
41                 if (this == obj)
42                         return true;
43                 if (obj == null)
44                         return false;
45                 if (getClass() != obj.getClass())
46                         return false;
47                 Stat other = (Stat) obj;
48                 return p==other.p && o==other.o;
49         }
50
51
52
53         static final Stat[] NO_STATS = new Stat[0];
54         
55         static final Comparator<Stat> STAT_COMPARATOR = new Comparator<Stat>() {
56                 @Override
57                 public int compare(Stat o1, Stat o2) {
58                         if(o1.p < o2.p)
59                                 return -1;
60                         else if(o1.p > o2.p)
61                                 return 1;
62                         else if(o1.o < o2.o)
63                                 return -1;
64                         else if(o1.o > o2.o)
65                                 return 1;
66                         else
67                                 return 0;
68                 }
69         };
70 }