com.ajjpj.abase.collection.AEqualsWrapper Maven / Gradle / Ivy
Show all versions of a-base Show documentation
package com.ajjpj.abase.collection;
/**
* This class wraps arbitrary objects, providing customizable equals()
and hashCode()
behavior based
* on an AEquality
instance. Calls to equals()
or hashCode()
on the wrapper are delegated
* to the corresponding calls on the AEquality
instance.
*
* This is a rather low-level class that is primarily useful for infrstructure code. If you do not understand its usefulness, you
* probably do not need it.
*
* @author arno
*/
public class AEqualsWrapper { //TODO junit
private final AEquality equality;
public final T value;
public AEqualsWrapper(AEquality equality, T value) {
this.equality = equality;
this.value = value;
}
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Override public boolean equals(Object obj) {
return equality.equals(value, ((AEqualsWrapper)obj).value);
}
@Override public int hashCode() {
return equality.hashCode(value);
}
@Override
public String toString() {
return value.toString();
}
}