net.sourceforge.pmd.util

Class CollectionUtil

public class CollectionUtil extends Object

Generic collection and array-related utility functions.

Version: $Revision$

Author: Brian Remedios

Field Summary
static TypeMapcollectionClassesByNames
static TypeMapcollectionInterfacesByNames
Method Summary
static booleanareEqual(Object value, Object otherValue)
A comprehensive isEqual method that handles nulls and arrays safely.
static booleanarraysAreEqual(Object value, Object otherValue)
Returns true if the objects are array instances and each of their elements compares via equals as well.
static <T> Set<T>asSet(T[] items)
Returns the items as a populated set.
static ClassgetCollectionTypeFor(String shortName)
Returns the collection type if we recognize it by its short name.
static <K,V> Map<V,K>invertedMapFrom(Map<K,V> source)
Returns a map based on the source but with the key & values swapped.
static booleanisCollectionType(String typeName, boolean includeInterfaces)
Return whether we can identify the typeName as a java.util collection class or interface as specified.
static booleanisCollectionType(Class clazzType, boolean includeInterfaces)
Return whether we can identify the typeName as a java.util collection class or interface as specified.
static <K,V> Map<K,V>mapFrom(K[] keys, V[] values)
Creates and returns a map populated with the keyValuesSets where the value held by the tuples are they key and value in that order.
static booleanvaluesAreTransitivelyEqual(Object[] thisArray, Object[] thatArray)
Returns whether the arrays are equal by examining each of their elements, even if they are arrays themselves.

Field Detail

collectionClassesByNames

public static final TypeMap collectionClassesByNames

collectionInterfacesByNames

public static final TypeMap collectionInterfacesByNames

Method Detail

areEqual

public static final boolean areEqual(Object value, Object otherValue)
A comprehensive isEqual method that handles nulls and arrays safely.

Parameters: value Object otherValue Object

Returns: boolean

arraysAreEqual

public static final boolean arraysAreEqual(Object value, Object otherValue)
Returns true if the objects are array instances and each of their elements compares via equals as well.

Parameters: value Object otherValue Object

Returns: boolean

asSet

public static <T> Set<T> asSet(T[] items)
Returns the items as a populated set.

Parameters: items Object[]

Returns: Set

getCollectionTypeFor

public static Class getCollectionTypeFor(String shortName)
Returns the collection type if we recognize it by its short name.

Parameters: shortName String

Returns: Class

invertedMapFrom

public static <K,V> Map<V,K> invertedMapFrom(Map<K,V> source)
Returns a map based on the source but with the key & values swapped.

Parameters: source Map

Returns: Map

isCollectionType

public static boolean isCollectionType(String typeName, boolean includeInterfaces)
Return whether we can identify the typeName as a java.util collection class or interface as specified.

Parameters: typeName String includeInterfaces boolean

Returns: boolean

isCollectionType

public static boolean isCollectionType(Class clazzType, boolean includeInterfaces)
Return whether we can identify the typeName as a java.util collection class or interface as specified.

Parameters: clazzType Class includeInterfaces boolean

Returns: boolean

mapFrom

public static <K,V> Map<K,V> mapFrom(K[] keys, V[] values)
Creates and returns a map populated with the keyValuesSets where the value held by the tuples are they key and value in that order.

Parameters: keys K[] values V[]

Returns: Map

valuesAreTransitivelyEqual

public static final boolean valuesAreTransitivelyEqual(Object[] thisArray, Object[] thatArray)
Returns whether the arrays are equal by examining each of their elements, even if they are arrays themselves.

Parameters: thisArray Object[] thatArray Object[]

Returns: boolean