Implement equals and hashCode for markers and markerSets
This commit is contained in:
parent
1838ebbc93
commit
8265cdfe05
|
@ -78,4 +78,27 @@ public abstract class DistanceRangedMarker extends Marker {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -215,6 +215,36 @@ public class ExtrudeMarker extends ObjectMarker {
|
|||
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;
|
||||
|
|
|
@ -129,4 +129,24 @@ public class HtmlMarker extends DistanceRangedMarker {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -153,6 +153,30 @@ public class LineMarker extends ObjectMarker {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -107,4 +107,24 @@ public abstract class Marker {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ package de.bluecolored.bluemap.api.markers;
|
|||
import de.bluecolored.bluemap.api.debug.DebugDump;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
|
@ -55,7 +56,7 @@ public class 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<>();
|
||||
|
@ -73,7 +74,7 @@ public class MarkerSet {
|
|||
* @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<>();
|
||||
|
@ -93,7 +94,7 @@ public class MarkerSet {
|
|||
* @param label the new label
|
||||
*/
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
this.label = Objects.requireNonNull(label);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,4 +147,26 @@ public class MarkerSet {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -107,4 +107,26 @@ public abstract class ObjectMarker extends DistanceRangedMarker {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -114,4 +114,24 @@ public class POIMarker extends DistanceRangedMarker {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -200,6 +200,34 @@ public class ShapeMarker extends ObjectMarker {
|
|||
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());
|
||||
|
|
|
@ -107,4 +107,26 @@ public class Color {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -97,4 +97,19 @@ public class Line {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -98,6 +98,21 @@ public class Shape {
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue