Skip to content

Commit

Permalink
fix Distance javadoc and equals method
Browse files Browse the repository at this point in the history
  • Loading branch information
JustCris654 committed Jan 24, 2025
1 parent c47569f commit 0185022
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ public class Distance {
private static final int MILLIMETERS_PER_KM = 1000 * MILLIMETERS_PER_M;
private final int millimeters;

/** Returns a Distance object representing the given number of meters */
/**
* Represents a distance.
* The class ensures that the distance, saved as an integer
* representing the millimeters, is not negative.
*/
private Distance(int distanceInMillimeters) {
this.millimeters = distanceInMillimeters;
}
Expand Down Expand Up @@ -78,12 +82,12 @@ public int toMeters() {
}

@Override
public boolean equals(Object other) {
if (other instanceof Distance distance) {
return distance.millimeters == this.millimeters;
} else {
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
var other = (Distance) o;
return this.millimeters == other.millimeters;
}

@Override
Expand Down

0 comments on commit 0185022

Please sign in to comment.