Skip to content

Commit 8265cdf

Browse files
committed
Implement equals and hashCode for markers and markerSets
1 parent 1838ebb commit 8265cdf

File tree

12 files changed

+265
-3
lines changed

12 files changed

+265
-3
lines changed

src/main/java/de/bluecolored/bluemap/api/markers/DistanceRangedMarker.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,27 @@ public void setMaxDistance(double maxDistance) {
7878
this.maxDistance = maxDistance;
7979
}
8080

81+
@Override
82+
public boolean equals(Object o) {
83+
if (this == o) return true;
84+
if (o == null || getClass() != o.getClass()) return false;
85+
if (!super.equals(o)) return false;
86+
87+
DistanceRangedMarker that = (DistanceRangedMarker) o;
88+
89+
if (Double.compare(that.minDistance, minDistance) != 0) return false;
90+
return Double.compare(that.maxDistance, maxDistance) == 0;
91+
}
92+
93+
@Override
94+
public int hashCode() {
95+
int result = super.hashCode();
96+
long temp;
97+
temp = Double.doubleToLongBits(minDistance);
98+
result = 31 * result + (int) (temp ^ (temp >>> 32));
99+
temp = Double.doubleToLongBits(maxDistance);
100+
result = 31 * result + (int) (temp ^ (temp >>> 32));
101+
return result;
102+
}
103+
81104
}

src/main/java/de/bluecolored/bluemap/api/markers/ExtrudeMarker.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,36 @@ public void setColors(Color lineColor, Color fillColor) {
215215
setFillColor(fillColor);
216216
}
217217

218+
@Override
219+
public boolean equals(Object o) {
220+
if (this == o) return true;
221+
if (o == null || getClass() != o.getClass()) return false;
222+
if (!super.equals(o)) return false;
223+
224+
ExtrudeMarker that = (ExtrudeMarker) o;
225+
226+
if (Float.compare(that.shapeMinY, shapeMinY) != 0) return false;
227+
if (Float.compare(that.shapeMaxY, shapeMaxY) != 0) return false;
228+
if (depthTest != that.depthTest) return false;
229+
if (lineWidth != that.lineWidth) return false;
230+
if (!shape.equals(that.shape)) return false;
231+
if (!lineColor.equals(that.lineColor)) return false;
232+
return fillColor.equals(that.fillColor);
233+
}
234+
235+
@Override
236+
public int hashCode() {
237+
int result = super.hashCode();
238+
result = 31 * result + shape.hashCode();
239+
result = 31 * result + (shapeMinY != 0.0f ? Float.floatToIntBits(shapeMinY) : 0);
240+
result = 31 * result + (shapeMaxY != 0.0f ? Float.floatToIntBits(shapeMaxY) : 0);
241+
result = 31 * result + (depthTest ? 1 : 0);
242+
result = 31 * result + lineWidth;
243+
result = 31 * result + lineColor.hashCode();
244+
result = 31 * result + fillColor.hashCode();
245+
return result;
246+
}
247+
218248
private static Vector3d calculateShapeCenter(Shape shape, float shapeMinY, float shapeMaxY) {
219249
Vector2d center = shape.getMin().add(shape.getMax()).mul(0.5);
220250
float centerY = (shapeMinY + shapeMaxY) * 0.5f;

src/main/java/de/bluecolored/bluemap/api/markers/HtmlMarker.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,24 @@ public void setHtml(String html) {
129129
this.html = Objects.requireNonNull(html, "html must not be null");
130130
}
131131

132+
@Override
133+
public boolean equals(Object o) {
134+
if (this == o) return true;
135+
if (o == null || getClass() != o.getClass()) return false;
136+
if (!super.equals(o)) return false;
137+
138+
HtmlMarker that = (HtmlMarker) o;
139+
140+
if (!anchor.equals(that.anchor)) return false;
141+
return html.equals(that.html);
142+
}
143+
144+
@Override
145+
public int hashCode() {
146+
int result = super.hashCode();
147+
result = 31 * result + anchor.hashCode();
148+
result = 31 * result + html.hashCode();
149+
return result;
150+
}
151+
132152
}

src/main/java/de/bluecolored/bluemap/api/markers/LineMarker.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ public void setLineColor(Color color) {
153153
this.lineColor = Objects.requireNonNull(color, "color must not be null");
154154
}
155155

156+
@Override
157+
public boolean equals(Object o) {
158+
if (this == o) return true;
159+
if (o == null || getClass() != o.getClass()) return false;
160+
if (!super.equals(o)) return false;
161+
162+
LineMarker that = (LineMarker) o;
163+
164+
if (depthTest != that.depthTest) return false;
165+
if (lineWidth != that.lineWidth) return false;
166+
if (!line.equals(that.line)) return false;
167+
return lineColor.equals(that.lineColor);
168+
}
169+
170+
@Override
171+
public int hashCode() {
172+
int result = super.hashCode();
173+
result = 31 * result + line.hashCode();
174+
result = 31 * result + (depthTest ? 1 : 0);
175+
result = 31 * result + lineWidth;
176+
result = 31 * result + lineColor.hashCode();
177+
return result;
178+
}
179+
156180
private static Vector3d calculateLineCenter(Line line) {
157181
return line.getMin().add(line.getMax()).mul(0.5);
158182
}

src/main/java/de/bluecolored/bluemap/api/markers/Marker.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,24 @@ public void setPosition(int x, int y, int z) {
107107
setPosition(new Vector3d(x, y, z));
108108
}
109109

110+
@Override
111+
public boolean equals(Object o) {
112+
if (this == o) return true;
113+
if (o == null || getClass() != o.getClass()) return false;
114+
115+
Marker marker = (Marker) o;
116+
117+
if (!type.equals(marker.type)) return false;
118+
if (!label.equals(marker.label)) return false;
119+
return position.equals(marker.position);
120+
}
121+
122+
@Override
123+
public int hashCode() {
124+
int result = type.hashCode();
125+
result = 31 * result + label.hashCode();
126+
result = 31 * result + position.hashCode();
127+
return result;
128+
}
129+
110130
}

src/main/java/de/bluecolored/bluemap/api/markers/MarkerSet.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import de.bluecolored.bluemap.api.debug.DebugDump;
2828

2929
import java.util.Map;
30+
import java.util.Objects;
3031
import java.util.concurrent.ConcurrentHashMap;
3132

3233
/**
@@ -55,7 +56,7 @@ private MarkerSet() {
5556
* @see #setLabel(String)
5657
*/
5758
public MarkerSet(String label) {
58-
this.label = label;
59+
this.label = Objects.requireNonNull(label);
5960
this.toggleable = true;
6061
this.defaultHidden = false;
6162
this.markers = new ConcurrentHashMap<>();
@@ -73,7 +74,7 @@ public MarkerSet(String label) {
7374
* @see #setDefaultHidden(boolean)
7475
*/
7576
public MarkerSet(String label, boolean toggleable, boolean defaultHidden) {
76-
this.label = label;
77+
this.label = Objects.requireNonNull(label);
7778
this.toggleable = toggleable;
7879
this.defaultHidden = defaultHidden;
7980
this.markers = new ConcurrentHashMap<>();
@@ -93,7 +94,7 @@ public String getLabel() {
9394
* @param label the new label
9495
*/
9596
public void setLabel(String label) {
96-
this.label = label;
97+
this.label = Objects.requireNonNull(label);
9798
}
9899

99100
/**
@@ -146,4 +147,26 @@ public Map<String, Marker> getMarkers() {
146147
return markers;
147148
}
148149

150+
@Override
151+
public boolean equals(Object o) {
152+
if (this == o) return true;
153+
if (o == null || getClass() != o.getClass()) return false;
154+
155+
MarkerSet markerSet = (MarkerSet) o;
156+
157+
if (toggleable != markerSet.toggleable) return false;
158+
if (defaultHidden != markerSet.defaultHidden) return false;
159+
if (!label.equals(markerSet.label)) return false;
160+
return markers.equals(markerSet.markers);
161+
}
162+
163+
@Override
164+
public int hashCode() {
165+
int result = label.hashCode();
166+
result = 31 * result + (toggleable ? 1 : 0);
167+
result = 31 * result + (defaultHidden ? 1 : 0);
168+
result = 31 * result + markers.hashCode();
169+
return result;
170+
}
171+
149172
}

src/main/java/de/bluecolored/bluemap/api/markers/ObjectMarker.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,26 @@ public void removeLink() {
107107
this.newTab = false;
108108
}
109109

110+
@Override
111+
public boolean equals(Object o) {
112+
if (this == o) return true;
113+
if (o == null || getClass() != o.getClass()) return false;
114+
if (!super.equals(o)) return false;
115+
116+
ObjectMarker that = (ObjectMarker) o;
117+
118+
if (newTab != that.newTab) return false;
119+
if (!detail.equals(that.detail)) return false;
120+
return Objects.equals(link, that.link);
121+
}
122+
123+
@Override
124+
public int hashCode() {
125+
int result = super.hashCode();
126+
result = 31 * result + detail.hashCode();
127+
result = 31 * result + (link != null ? link.hashCode() : 0);
128+
result = 31 * result + (newTab ? 1 : 0);
129+
return result;
130+
}
131+
110132
}

src/main/java/de/bluecolored/bluemap/api/markers/POIMarker.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,24 @@ public void setIcon(String iconAddress, Vector2i anchor) {
114114
this.anchor = Objects.requireNonNull(anchor, "anchor must not be null");
115115
}
116116

117+
@Override
118+
public boolean equals(Object o) {
119+
if (this == o) return true;
120+
if (o == null || getClass() != o.getClass()) return false;
121+
if (!super.equals(o)) return false;
122+
123+
POIMarker poiMarker = (POIMarker) o;
124+
125+
if (!icon.equals(poiMarker.icon)) return false;
126+
return anchor.equals(poiMarker.anchor);
127+
}
128+
129+
@Override
130+
public int hashCode() {
131+
int result = super.hashCode();
132+
result = 31 * result + icon.hashCode();
133+
result = 31 * result + anchor.hashCode();
134+
return result;
135+
}
136+
117137
}

src/main/java/de/bluecolored/bluemap/api/markers/ShapeMarker.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,34 @@ public void setColors(Color lineColor, Color fillColor) {
200200
setFillColor(fillColor);
201201
}
202202

203+
@Override
204+
public boolean equals(Object o) {
205+
if (this == o) return true;
206+
if (o == null || getClass() != o.getClass()) return false;
207+
if (!super.equals(o)) return false;
208+
209+
ShapeMarker that = (ShapeMarker) o;
210+
211+
if (Float.compare(that.shapeY, shapeY) != 0) return false;
212+
if (depthTest != that.depthTest) return false;
213+
if (lineWidth != that.lineWidth) return false;
214+
if (!shape.equals(that.shape)) return false;
215+
if (!lineColor.equals(that.lineColor)) return false;
216+
return fillColor.equals(that.fillColor);
217+
}
218+
219+
@Override
220+
public int hashCode() {
221+
int result = super.hashCode();
222+
result = 31 * result + shape.hashCode();
223+
result = 31 * result + (shapeY != 0.0f ? Float.floatToIntBits(shapeY) : 0);
224+
result = 31 * result + (depthTest ? 1 : 0);
225+
result = 31 * result + lineWidth;
226+
result = 31 * result + lineColor.hashCode();
227+
result = 31 * result + fillColor.hashCode();
228+
return result;
229+
}
230+
203231
private static Vector3d calculateShapeCenter(Shape shape, float shapeY) {
204232
Vector2d center = shape.getMin().add(shape.getMax()).mul(0.5);
205233
return new Vector3d(center.getX(), shapeY, center.getY());

src/main/java/de/bluecolored/bluemap/api/math/Color.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,26 @@ private static int parseColorString(String val) {
107107
return Integer.parseInt(val);
108108
}
109109

110+
@Override
111+
public boolean equals(Object o) {
112+
if (this == o) return true;
113+
if (o == null || getClass() != o.getClass()) return false;
114+
115+
Color color = (Color) o;
116+
117+
if (r != color.r) return false;
118+
if (g != color.g) return false;
119+
if (b != color.b) return false;
120+
return Float.compare(color.a, a) == 0;
121+
}
122+
123+
@Override
124+
public int hashCode() {
125+
int result = r;
126+
result = 31 * result + g;
127+
result = 31 * result + b;
128+
result = 31 * result + (a != +0.0f ? Float.floatToIntBits(a) : 0);
129+
return result;
130+
}
131+
110132
}

0 commit comments

Comments
 (0)