Make DefaultEquator a singleton, hide default ctor.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1476578 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bac0bd081e
commit
fad4f969df
|
@ -38,6 +38,24 @@ public class DefaultEquator<T> implements Equator<T>, Serializable {
|
|||
*/
|
||||
public static final int HASHCODE_NULL = -1;
|
||||
|
||||
/**
|
||||
* Factory returning the typed singleton instance.
|
||||
*
|
||||
* @param <T> the object type
|
||||
* @return the singleton instance
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> DefaultEquator<T> defaultEquator() {
|
||||
return (DefaultEquator<T>) DefaultEquator.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restricted constructor.
|
||||
*/
|
||||
private DefaultEquator() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc} Delegates to {@link Object#equals(Object)}.
|
||||
*/
|
||||
|
@ -59,14 +77,4 @@ public class DefaultEquator<T> implements Equator<T>, Serializable {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a typed {@link DefaultEquator} instance.
|
||||
*
|
||||
* @param <T> the object type
|
||||
* @return {@link DefaultEquator#INSTANCE}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> DefaultEquator<T> defaultEquator() {
|
||||
return (DefaultEquator<T>) DefaultEquator.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -571,7 +571,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||
assertTrue(CollectionUtils.isEqualCollection(collectionA, collB, e));
|
||||
assertTrue(CollectionUtils.isEqualCollection(collB, collectionA, e));
|
||||
|
||||
final Equator<Number> defaultEquator = new DefaultEquator<Number>();
|
||||
final Equator<Number> defaultEquator = DefaultEquator.defaultEquator();
|
||||
assertFalse(CollectionUtils.isEqualCollection(collectionA, collectionB, defaultEquator));
|
||||
assertFalse(CollectionUtils.isEqualCollection(collectionA, collB, defaultEquator));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue