Skip to content

Commit

Permalink
Implement equals and hashCode for markers and markerSets
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Aug 4, 2022
1 parent 1838ebb commit 8265cdf
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,27 @@ public void setMaxDistance(double 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,36 @@ public void setColors(Color lineColor, Color 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) {
Vector2d center = shape.getMin().add(shape.getMax()).mul(0.5);
float centerY = (shapeMinY + shapeMaxY) * 0.5f;
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/de/bluecolored/bluemap/api/markers/HtmlMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,24 @@ public void setHtml(String html) {
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;
}

}
24 changes: 24 additions & 0 deletions src/main/java/de/bluecolored/bluemap/api/markers/LineMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ public void setLineColor(Color color) {
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) {
return line.getMin().add(line.getMax()).mul(0.5);
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/de/bluecolored/bluemap/api/markers/Marker.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,24 @@ public void setPosition(int x, int y, int 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;
}

}
29 changes: 26 additions & 3 deletions src/main/java/de/bluecolored/bluemap/api/markers/MarkerSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import de.bluecolored.bluemap.api.debug.DebugDump;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand Down Expand Up @@ -55,7 +56,7 @@ private MarkerSet() {
* @see #setLabel(String)
*/
public MarkerSet(String label) {
this.label = label;
this.label = Objects.requireNonNull(label);
this.toggleable = true;
this.defaultHidden = false;
this.markers = new ConcurrentHashMap<>();
Expand All @@ -73,7 +74,7 @@ public MarkerSet(String label) {
* @see #setDefaultHidden(boolean)
*/
public MarkerSet(String label, boolean toggleable, boolean defaultHidden) {
this.label = label;
this.label = Objects.requireNonNull(label);
this.toggleable = toggleable;
this.defaultHidden = defaultHidden;
this.markers = new ConcurrentHashMap<>();
Expand All @@ -93,7 +94,7 @@ public String getLabel() {
* @param label the new label
*/
public void setLabel(String label) {
this.label = label;
this.label = Objects.requireNonNull(label);
}

/**
Expand Down Expand Up @@ -146,4 +147,26 @@ public Map<String, Marker> getMarkers() {
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;
}

}
22 changes: 22 additions & 0 deletions src/main/java/de/bluecolored/bluemap/api/markers/ObjectMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,26 @@ public void removeLink() {
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;
}

}
20 changes: 20 additions & 0 deletions src/main/java/de/bluecolored/bluemap/api/markers/POIMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,24 @@ public void setIcon(String iconAddress, Vector2i anchor) {
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;
}

}
28 changes: 28 additions & 0 deletions src/main/java/de/bluecolored/bluemap/api/markers/ShapeMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,34 @@ public void setColors(Color lineColor, Color 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) {
Vector2d center = shape.getMin().add(shape.getMax()).mul(0.5);
return new Vector3d(center.getX(), shapeY, center.getY());
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/de/bluecolored/bluemap/api/math/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,26 @@ private static int parseColorString(String 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;
}

}
15 changes: 15 additions & 0 deletions src/main/java/de/bluecolored/bluemap/api/math/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,19 @@ public Vector3d getMax() {
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);
}

}
15 changes: 15 additions & 0 deletions src/main/java/de/bluecolored/bluemap/api/math/Shape.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ public Vector2d getMax() {
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
* @param pos1 one corner of the rectangle
Expand Down

0 comments on commit 8265cdf

Please sign in to comment.