[wpimath] Add Pair.equals() (#6580)

This commit is contained in:
Wispy
2024-05-06 23:52:59 -05:00
committed by GitHub
parent f77d01c085
commit 2563ff9f18

View File

@@ -4,6 +4,8 @@
package edu.wpi.first.math;
import java.util.Objects;
/**
* Represents a pair of two objects.
*
@@ -60,4 +62,27 @@ public class Pair<A, B> {
public String toString() {
return String.format("Pair(%s, %s)", m_first, m_second);
}
/**
* Checks equality between this Pair and another object.
*
* @param obj The other object.
* @return Whether the two objects are equal or not.
*/
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof Pair) {
return Objects.equals(m_first, ((Pair) obj).getFirst())
&& Objects.equals(m_second, ((Pair) obj).getSecond());
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(m_first, m_second);
}
}