From fad4f969df9c90a425851b66363dfea9c8d3b5d0 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Sat, 27 Apr 2013 14:02:30 +0000 Subject: [PATCH] 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 --- .../collections4/functors/DefaultEquator.java | 28 ++++++++++++------- .../collections4/CollectionUtilsTest.java | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/functors/DefaultEquator.java b/src/main/java/org/apache/commons/collections4/functors/DefaultEquator.java index 29d231d75..78de84ffc 100644 --- a/src/main/java/org/apache/commons/collections4/functors/DefaultEquator.java +++ b/src/main/java/org/apache/commons/collections4/functors/DefaultEquator.java @@ -38,6 +38,24 @@ public class DefaultEquator implements Equator, Serializable { */ public static final int HASHCODE_NULL = -1; + /** + * Factory returning the typed singleton instance. + * + * @param the object type + * @return the singleton instance + */ + @SuppressWarnings("unchecked") + public static DefaultEquator defaultEquator() { + return (DefaultEquator) DefaultEquator.INSTANCE; + } + + /** + * Restricted constructor. + */ + private DefaultEquator() { + super(); + } + /** * {@inheritDoc} Delegates to {@link Object#equals(Object)}. */ @@ -59,14 +77,4 @@ public class DefaultEquator implements Equator, Serializable { return INSTANCE; } - /** - * Get a typed {@link DefaultEquator} instance. - * - * @param the object type - * @return {@link DefaultEquator#INSTANCE} - */ - @SuppressWarnings("unchecked") - public static DefaultEquator defaultEquator() { - return (DefaultEquator) DefaultEquator.INSTANCE; - } } diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java index a84c51bd5..0945ab22f 100644 --- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java @@ -571,7 +571,7 @@ public class CollectionUtilsTest extends MockTestCase { assertTrue(CollectionUtils.isEqualCollection(collectionA, collB, e)); assertTrue(CollectionUtils.isEqualCollection(collB, collectionA, e)); - final Equator defaultEquator = new DefaultEquator(); + final Equator defaultEquator = DefaultEquator.defaultEquator(); assertFalse(CollectionUtils.isEqualCollection(collectionA, collectionB, defaultEquator)); assertFalse(CollectionUtils.isEqualCollection(collectionA, collB, defaultEquator)); }