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:
Thomas Neidhart 2013-04-27 14:02:30 +00:00
parent bac0bd081e
commit fad4f969df
2 changed files with 19 additions and 11 deletions

View File

@ -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;
}
}

View File

@ -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));
}