Skip to content

Commit

Permalink
Use pattern variables in conjunction with instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesbraun committed Aug 30, 2023
1 parent ae4e964 commit 0ce25e1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/main/java/hso/autonomy/util/geometry/Area2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ public boolean equals(Object obj)
return true;
}

if (obj instanceof Area2D.Int) {
Area2D.Int other = (Area2D.Int) obj;
if (obj instanceof Int other) {
return other.minX == minX && other.maxX == maxX && other.minY == minY && other.maxY == maxY;
}

Expand Down Expand Up @@ -314,8 +313,7 @@ public boolean equals(Object obj)
return true;
}

if (obj instanceof Area2D.Float) {
Area2D.Float other = (Area2D.Float) obj;
if (obj instanceof Float other) {
return other.minX == minX && other.maxX == maxX && other.minY == minY && other.maxY == maxY;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/hso/autonomy/util/geometry/Circle2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ public double getDistance(Circle2D other)
@Override
public boolean equals(Object other)
{
if (!(other instanceof Circle2D))
if (!(other instanceof Circle2D c))
return false;
Circle2D c = (Circle2D) other;
return (this.x == c.getX() && this.y == c.getY() && this.radius == c.getRadius());
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/hso/autonomy/util/geometry/Pose2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,8 @@ public String toString()
@Override
public boolean equals(Object other)
{
if (!(other instanceof Pose2D))
if (!(other instanceof Pose2D p))
return false;
Pose2D p = (Pose2D) other;
return (this.x == p.x && this.y == p.y && this.angle.equals(p.angle));
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/hso/autonomy/util/geometry/Pose3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ public double getDistanceTo(IPose3D other)
@Override
public boolean equals(Object obj)
{
if (obj instanceof IPose3D) {
IPose3D other = (IPose3D) obj;
if (obj instanceof IPose3D other) {
return position.equals(other.getPosition()) &&
Rotation.distance(orientation, other.getOrientation()) < 0.0001;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/hso/autonomy/util/geometry/Tangent.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public Tangent(Pose2D p1, Pose2D p2)
@Override
public boolean equals(Object other)
{
if (other instanceof Tangent) {
Tangent t = (Tangent) other;
if (other instanceof Tangent t) {
if ((this.p1.equals(t.p1) && this.p2.equals(t.p2)) || (this.p1.equals(t.p2) && this.p2.equals(t.p1)))
return true;
}
Expand Down

0 comments on commit 0ce25e1

Please sign in to comment.