Implement equals and hashCode for markers and markerSets

This commit is contained in:
Lukas Rieger (Blue) 2022-08-04 16:31:44 +02:00
parent 1838ebbc93
commit 8265cdfe05
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
12 changed files with 265 additions and 3 deletions

View File

@ -78,4 +78,27 @@ public void setMaxDistance(double maxDistance) {
this.maxDistance = maxDistance; this.maxDistance = maxDistance;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
DistanceRangedMarker that = (DistanceRangedMarker) o;
if (Double.compare(that.minDistance, minDistance) != 0) return false;
return Double.compare(that.maxDistance, maxDistance) == 0;
}
@Override
public int hashCode() {
int result = super.hashCode();
long temp;
temp = Double.doubleToLongBits(minDistance);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(maxDistance);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
} }

View File

@ -215,6 +215,36 @@ public void setColors(Color lineColor, Color fillColor) {
setFillColor(fillColor); setFillColor(fillColor);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
ExtrudeMarker that = (ExtrudeMarker) o;
if (Float.compare(that.shapeMinY, shapeMinY) != 0) return false;
if (Float.compare(that.shapeMaxY, shapeMaxY) != 0) return false;
if (depthTest != that.depthTest) return false;
if (lineWidth != that.lineWidth) return false;
if (!shape.equals(that.shape)) return false;
if (!lineColor.equals(that.lineColor)) return false;
return fillColor.equals(that.fillColor);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + shape.hashCode();
result = 31 * result + (shapeMinY != 0.0f ? Float.floatToIntBits(shapeMinY) : 0);
result = 31 * result + (shapeMaxY != 0.0f ? Float.floatToIntBits(shapeMaxY) : 0);
result = 31 * result + (depthTest ? 1 : 0);
result = 31 * result + lineWidth;
result = 31 * result + lineColor.hashCode();
result = 31 * result + fillColor.hashCode();
return result;
}
private static Vector3d calculateShapeCenter(Shape shape, float shapeMinY, float shapeMaxY) { private static Vector3d calculateShapeCenter(Shape shape, float shapeMinY, float shapeMaxY) {
Vector2d center = shape.getMin().add(shape.getMax()).mul(0.5); Vector2d center = shape.getMin().add(shape.getMax()).mul(0.5);
float centerY = (shapeMinY + shapeMaxY) * 0.5f; float centerY = (shapeMinY + shapeMaxY) * 0.5f;

View File

@ -129,4 +129,24 @@ public void setHtml(String html) {
this.html = Objects.requireNonNull(html, "html must not be null"); this.html = Objects.requireNonNull(html, "html must not be null");
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
HtmlMarker that = (HtmlMarker) o;
if (!anchor.equals(that.anchor)) return false;
return html.equals(that.html);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + anchor.hashCode();
result = 31 * result + html.hashCode();
return result;
}
} }

View File

@ -153,6 +153,30 @@ public void setLineColor(Color color) {
this.lineColor = Objects.requireNonNull(color, "color must not be null"); this.lineColor = Objects.requireNonNull(color, "color must not be null");
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
LineMarker that = (LineMarker) o;
if (depthTest != that.depthTest) return false;
if (lineWidth != that.lineWidth) return false;
if (!line.equals(that.line)) return false;
return lineColor.equals(that.lineColor);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + line.hashCode();
result = 31 * result + (depthTest ? 1 : 0);
result = 31 * result + lineWidth;
result = 31 * result + lineColor.hashCode();
return result;
}
private static Vector3d calculateLineCenter(Line line) { private static Vector3d calculateLineCenter(Line line) {
return line.getMin().add(line.getMax()).mul(0.5); return line.getMin().add(line.getMax()).mul(0.5);
} }

View File

@ -107,4 +107,24 @@ public void setPosition(int x, int y, int z) {
setPosition(new Vector3d(x, y, z)); setPosition(new Vector3d(x, y, z));
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Marker marker = (Marker) o;
if (!type.equals(marker.type)) return false;
if (!label.equals(marker.label)) return false;
return position.equals(marker.position);
}
@Override
public int hashCode() {
int result = type.hashCode();
result = 31 * result + label.hashCode();
result = 31 * result + position.hashCode();
return result;
}
} }

View File

@ -27,6 +27,7 @@
import de.bluecolored.bluemap.api.debug.DebugDump; import de.bluecolored.bluemap.api.debug.DebugDump;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
@ -55,7 +56,7 @@ private MarkerSet() {
* @see #setLabel(String) * @see #setLabel(String)
*/ */
public MarkerSet(String label) { public MarkerSet(String label) {
this.label = label; this.label = Objects.requireNonNull(label);
this.toggleable = true; this.toggleable = true;
this.defaultHidden = false; this.defaultHidden = false;
this.markers = new ConcurrentHashMap<>(); this.markers = new ConcurrentHashMap<>();
@ -73,7 +74,7 @@ public MarkerSet(String label) {
* @see #setDefaultHidden(boolean) * @see #setDefaultHidden(boolean)
*/ */
public MarkerSet(String label, boolean toggleable, boolean defaultHidden) { public MarkerSet(String label, boolean toggleable, boolean defaultHidden) {
this.label = label; this.label = Objects.requireNonNull(label);
this.toggleable = toggleable; this.toggleable = toggleable;
this.defaultHidden = defaultHidden; this.defaultHidden = defaultHidden;
this.markers = new ConcurrentHashMap<>(); this.markers = new ConcurrentHashMap<>();
@ -93,7 +94,7 @@ public String getLabel() {
* @param label the new label * @param label the new label
*/ */
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = Objects.requireNonNull(label);
} }
/** /**
@ -146,4 +147,26 @@ public Map<String, Marker> getMarkers() {
return markers; return markers;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MarkerSet markerSet = (MarkerSet) o;
if (toggleable != markerSet.toggleable) return false;
if (defaultHidden != markerSet.defaultHidden) return false;
if (!label.equals(markerSet.label)) return false;
return markers.equals(markerSet.markers);
}
@Override
public int hashCode() {
int result = label.hashCode();
result = 31 * result + (toggleable ? 1 : 0);
result = 31 * result + (defaultHidden ? 1 : 0);
result = 31 * result + markers.hashCode();
return result;
}
} }

View File

@ -107,4 +107,26 @@ public void removeLink() {
this.newTab = false; this.newTab = false;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
ObjectMarker that = (ObjectMarker) o;
if (newTab != that.newTab) return false;
if (!detail.equals(that.detail)) return false;
return Objects.equals(link, that.link);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + detail.hashCode();
result = 31 * result + (link != null ? link.hashCode() : 0);
result = 31 * result + (newTab ? 1 : 0);
return result;
}
} }

View File

@ -114,4 +114,24 @@ public void setIcon(String iconAddress, Vector2i anchor) {
this.anchor = Objects.requireNonNull(anchor, "anchor must not be null"); this.anchor = Objects.requireNonNull(anchor, "anchor must not be null");
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
POIMarker poiMarker = (POIMarker) o;
if (!icon.equals(poiMarker.icon)) return false;
return anchor.equals(poiMarker.anchor);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + icon.hashCode();
result = 31 * result + anchor.hashCode();
return result;
}
} }

View File

@ -200,6 +200,34 @@ public void setColors(Color lineColor, Color fillColor) {
setFillColor(fillColor); setFillColor(fillColor);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
ShapeMarker that = (ShapeMarker) o;
if (Float.compare(that.shapeY, shapeY) != 0) return false;
if (depthTest != that.depthTest) return false;
if (lineWidth != that.lineWidth) return false;
if (!shape.equals(that.shape)) return false;
if (!lineColor.equals(that.lineColor)) return false;
return fillColor.equals(that.fillColor);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + shape.hashCode();
result = 31 * result + (shapeY != 0.0f ? Float.floatToIntBits(shapeY) : 0);
result = 31 * result + (depthTest ? 1 : 0);
result = 31 * result + lineWidth;
result = 31 * result + lineColor.hashCode();
result = 31 * result + fillColor.hashCode();
return result;
}
private static Vector3d calculateShapeCenter(Shape shape, float shapeY) { private static Vector3d calculateShapeCenter(Shape shape, float shapeY) {
Vector2d center = shape.getMin().add(shape.getMax()).mul(0.5); Vector2d center = shape.getMin().add(shape.getMax()).mul(0.5);
return new Vector3d(center.getX(), shapeY, center.getY()); return new Vector3d(center.getX(), shapeY, center.getY());

View File

@ -107,4 +107,26 @@ private static int parseColorString(String val) {
return Integer.parseInt(val); return Integer.parseInt(val);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Color color = (Color) o;
if (r != color.r) return false;
if (g != color.g) return false;
if (b != color.b) return false;
return Float.compare(color.a, a) == 0;
}
@Override
public int hashCode() {
int result = r;
result = 31 * result + g;
result = 31 * result + b;
result = 31 * result + (a != +0.0f ? Float.floatToIntBits(a) : 0);
return result;
}
} }

View File

@ -97,4 +97,19 @@ public Vector3d getMax() {
return this.max; return this.max;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Line line = (Line) o;
return Arrays.equals(points, line.points);
}
@Override
public int hashCode() {
return Arrays.hashCode(points);
}
} }

View File

@ -98,6 +98,21 @@ public Vector2d getMax() {
return this.max; return this.max;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Shape shape = (Shape) o;
return Arrays.equals(points, shape.points);
}
@Override
public int hashCode() {
return Arrays.hashCode(points);
}
/** /**
* Creates a {@link Shape} representing a rectangle spanning over pos1 and pos2 * Creates a {@link Shape} representing a rectangle spanning over pos1 and pos2
* @param pos1 one corner of the rectangle * @param pos1 one corner of the rectangle