From bb3a44e5874e34928bc9ec0aa3bf2eb4bf0e296a Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Sat, 25 Oct 2008 00:56:42 +0000 Subject: [PATCH] code cleanup: newSet() is redundant with asSet() use of Arrays.asList() instead of local iteration in asSet() git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@6665 51baf565-9d33-0410-a72c-fc3788e3496d --- .../sourceforge/pmd/util/CollectionUtil.java | 55 +++++++------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/util/CollectionUtil.java b/pmd/src/net/sourceforge/pmd/util/CollectionUtil.java index e362a246c9..f1a1927f42 100644 --- a/pmd/src/net/sourceforge/pmd/util/CollectionUtil.java +++ b/pmd/src/net/sourceforge/pmd/util/CollectionUtil.java @@ -1,5 +1,6 @@ package net.sourceforge.pmd.util; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -7,7 +8,7 @@ import java.util.Set; /** * Generic collection and array-related utility functions. - * + * * @author Brian Remedios * @version $Revision$ */ @@ -27,7 +28,7 @@ public final class CollectionUtil { /** * Returns the collection type if we recognize it by its short name. - * + * * @param shortName String * @return Class */ @@ -43,7 +44,7 @@ public final class CollectionUtil { /** * Return whether we can identify the typeName as a java.util collection class * or interface as specified. - * + * * @param typeName String * @param includeInterfaces boolean * @return boolean @@ -60,7 +61,7 @@ public final class CollectionUtil { /** * Return whether we can identify the typeName as a java.util collection class * or interface as specified. - * + * * @param clazzType Class * @param includeInterfaces boolean * @return boolean @@ -76,23 +77,19 @@ public final class CollectionUtil { /** * Returns the items as a populated set. - * + * * @param items Object[] * @return Set */ public static Set asSet(T[] items) { - Set set = new HashSet(items.length); - for (T element : items) { - set.add(element); - } - return set; + return new HashSet(Arrays.asList(items)); } /** * Creates and returns a map populated with the keyValuesSets where * the value held by the tuples are they key and value in that order. - * + * * @param keys K[] * @param values V[] * @return Map @@ -110,7 +107,7 @@ public final class CollectionUtil { /** * Returns a map based on the source but with the key & values swapped. - * + * * @param source Map * @return Map */ @@ -125,7 +122,7 @@ public final class CollectionUtil { /** * Returns true if the objects are array instances and each of their elements compares * via equals as well. - * + * * @param value Object * @param otherValue Object * @return boolean @@ -143,7 +140,7 @@ public final class CollectionUtil { /** * Returns whether the arrays are equal by examining each of their elements, even if they are * arrays themselves. - * + * * @param thisArray Object[] * @param thatArray Object[] * @return boolean @@ -168,7 +165,7 @@ public final class CollectionUtil { /** * A comprehensive isEqual method that handles nulls and arrays safely. - * + * * @param value Object * @param otherValue Object * @return boolean @@ -190,43 +187,29 @@ public final class CollectionUtil { } return value.equals(otherValue); } - - /** - * Factory method for a set that uses an array for initial data - * - * @param - * @param items - * @return - */ - public static Set newSet(T[] items) { - - Set results = new HashSet(items.length); - for (int i=0; i * @param a * @param b * @return boolean */ public static boolean areSemanticEquals(T[] a, T[] b) { - + if (a == null) { return isEmpty(b); } - if (b == null) { return isEmpty(a); } + if (b == null) { return isEmpty(a); } return a.equals(b); } }