1 package org.molwind.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class BaseRelationship implements Relationship, PartialMatch {
27
28 private WorldEntity left;
29 private WorldEntity right;
30
31
32
33
34
35
36
37
38
39 public BaseRelationship(final WorldEntity newLeft,
40 final WorldEntity newRight) {
41 this.left = newLeft;
42 this.right = newRight;
43 }
44
45
46
47
48
49
50
51
52 public BaseRelationship(final WorldEntity newRight) {
53 this(null, newRight);
54 }
55
56
57
58
59
60
61
62 public void setLeft(final WorldEntity newLeft) {
63 this.left = newLeft;
64 }
65
66
67
68
69
70
71
72 public WorldEntity getLeft() {
73 return left;
74 }
75
76
77
78
79
80
81
82 public void setRight(final WorldEntity newRight) {
83 this.right = newRight;
84 }
85
86
87
88
89
90
91
92 public WorldEntity getRight() {
93 return right;
94 }
95
96
97
98
99
100
101
102 public boolean isTransitive() {
103 return true;
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117 public boolean equals(final Object object) {
118 if (!this.getClass().isInstance(object)) {
119 return false;
120 }
121
122 if (!this.getClass().equals(object.getClass())) {
123 return false;
124 }
125
126 WorldEntity objectLeft = ((BaseRelationship) object).getLeft();
127 WorldEntity objectRight = ((BaseRelationship) object).getRight();
128
129 boolean leftEqual = false;
130
131 if (objectLeft == null) {
132 leftEqual = (this.getLeft() == null);
133 } else {
134 leftEqual = objectLeft.equals(this.getLeft());
135 }
136
137 boolean rightEqual = false;
138
139 if (objectRight == null) {
140 rightEqual = (this.getRight() == null);
141 } else {
142 rightEqual = objectRight.equals(this.getRight());
143 }
144
145 return (leftEqual && rightEqual);
146 }
147
148
149
150
151
152
153
154
155
156
157 public int hashCode() {
158 String string = this.toString();
159
160 return string.hashCode();
161 }
162
163
164
165
166
167
168
169
170
171 public boolean matches(final Relationship relation) {
172 if (relation == null) {
173 return false;
174 }
175
176 if (relation instanceof BaseRelationship) {
177 boolean match = true;
178
179 if (relation.getLeft() != null) {
180 match = match && relation.getLeft().equals(this.getLeft());
181 }
182
183 if (relation.getRight() != null) {
184 match = match && relation.getRight().equals(this.getRight());
185 }
186
187 return match;
188 }
189
190
191
192
193 return relation.equals(this);
194 }
195
196
197
198
199
200
201
202
203
204
205 public static BaseRelationship right(final WorldEntity entity) {
206 return new BaseRelationship(entity);
207 }
208
209
210
211
212
213
214
215
216
217
218 public static BaseRelationship left(final WorldEntity entity) {
219 return new BaseRelationship(entity, null);
220 }
221
222 }