]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph/src/org/simantics/graph/diff/Statement.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.graph / src / org / simantics / graph / diff / Statement.java
1 package org.simantics.graph.diff;
2
3 public class Statement {
4         int subject;
5         int predicate;
6         int inverse;
7         int object;
8         
9         public Statement(int subject, int predicate, int inverse, int object) {
10                 this.subject = subject;
11                 this.predicate = predicate;
12                 this.inverse = inverse;
13                 this.object = object;
14         }
15
16         @Override
17         public int hashCode() {
18                 final int prime = 31;
19                 int result = 1;
20                 result = prime * result + inverse;
21                 result = prime * result + object;
22                 result = prime * result + predicate;
23                 result = prime * result + subject;
24                 return result;
25         }
26
27         @Override
28         public boolean equals(Object obj) {
29                 if (this == obj)
30                         return true;
31                 if (obj == null)
32                         return false;
33                 if (getClass() != obj.getClass())
34                         return false;
35                 Statement other = (Statement) obj;
36                 if (inverse != other.inverse)
37                         return false;
38                 if (object != other.object)
39                         return false;
40                 if (predicate != other.predicate)
41                         return false;
42                 if (subject != other.subject)
43                         return false;
44                 return true;
45         }
46         
47         public Statement map(int[] map) {
48                 int mappedSubject = map[subject];
49                 if(mappedSubject < 0) return null;
50                 int mappedPredicate = map[predicate];
51                 if(mappedPredicate < 0) return null;            
52                 int mappedInverse;
53                 if(inverse < 0)
54                         mappedInverse = inverse;
55                 else {
56                         mappedInverse = map[inverse];
57                         if(mappedInverse < 0) return null;
58                 }
59                 int mappedObject = map[object];
60                 if(mappedObject < 0) return null;
61                 return new Statement(mappedSubject, mappedPredicate, mappedInverse, mappedObject);
62         }
63 }