Let Pair represent null values.
Bug: 7121262 Change-Id: I067ea0a4af40a0e8935a9408404df7a2e851e22c
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package android.util;
|
package android.util;
|
||||||
|
|
||||||
|
import libcore.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container to ease passing around a tuple of two objects. This object provides a sensible
|
* Container to ease passing around a tuple of two objects. This object provides a sensible
|
||||||
* implementation of equals(), returning true if equals() is true on each of the contained
|
* implementation of equals(), returning true if equals() is true on each of the contained
|
||||||
@@ -26,8 +28,8 @@ public class Pair<F, S> {
|
|||||||
public final S second;
|
public final S second;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for a Pair. If either are null then equals() and hashCode() will throw
|
* Constructor for a Pair.
|
||||||
* a NullPointerException.
|
*
|
||||||
* @param first the first object in the Pair
|
* @param first the first object in the Pair
|
||||||
* @param second the second object in the pair
|
* @param second the second object in the pair
|
||||||
*/
|
*/
|
||||||
@@ -37,31 +39,30 @@ public class Pair<F, S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the two objects for equality by delegating to their respective equals() methods.
|
* Checks the two objects for equality by delegating to their respective
|
||||||
* @param o the Pair to which this one is to be checked for equality
|
* {@link Object#equals(Object)} methods.
|
||||||
* @return true if the underlying objects of the Pair are both considered equals()
|
*
|
||||||
|
* @param o the {@link Pair} to which this one is to be checked for equality
|
||||||
|
* @return true if the underlying objects of the Pair are both considered
|
||||||
|
* equal
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (!(o instanceof Pair)) {
|
||||||
if (!(o instanceof Pair)) return false;
|
|
||||||
final Pair<F, S> other;
|
|
||||||
try {
|
|
||||||
other = (Pair<F, S>) o;
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return first.equals(other.first) && second.equals(other.second);
|
Pair<?, ?> p = (Pair<?, ?>) o;
|
||||||
|
return Objects.equal(p.first, first) && Objects.equal(p.second, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute a hash code using the hash codes of the underlying objects
|
* Compute a hash code using the hash codes of the underlying objects
|
||||||
|
*
|
||||||
* @return a hashcode of the Pair
|
* @return a hashcode of the Pair
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = 17;
|
return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
|
||||||
result = 31 * result + first.hashCode();
|
|
||||||
result = 31 * result + second.hashCode();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user