|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.pmd.util.CollectionUtil
public final class CollectionUtil
Generic collection and array-related utility functions for java.util types. See ClassUtil for comparable facilities for short name lookup.
Field Summary | |
---|---|
static TypeMap |
COLLECTION_CLASSES_BY_NAMES
|
static TypeMap |
COLLECTION_INTERFACES_BY_NAMES
|
Method Summary | ||
---|---|---|
static int |
addWithoutDuplicates(java.util.Collection<java.lang.String> source,
java.util.Collection<java.lang.String> target)
Add elements from the source to the target as long as they don't already exist there. |
|
static
|
addWithoutDuplicates(T[] values,
T newValue)
If the newValue is already held within the values array then the values array is returned, otherwise a new array is created appending the newValue to the end. |
|
static
|
addWithoutDuplicates(T[] values,
T[] newValues)
Returns an array of values as a union set of the two input arrays. |
|
static boolean |
areEqual(java.lang.Object value,
java.lang.Object otherValue)
A comprehensive isEqual method that handles nulls and arrays safely. |
|
static
|
areSemanticEquals(T[] a,
T[] b)
Returns true if both arrays are if both are null or have zero-length, otherwise return the false if their respective elements are not equal by position. |
|
static boolean |
arraysAreEqual(java.lang.Object value,
java.lang.Object otherValue)
Returns true if the objects are array instances and each of their elements compares via equals as well. |
|
static
|
asSet(T[] items)
Returns the items as a populated set. |
|
static java.lang.Class<?> |
getCollectionTypeFor(java.lang.String shortName)
Returns the collection type if we recognize it by its short name. |
|
static
|
invertedMapFrom(java.util.Map<K,V> source)
Returns a map based on the source but with the key & values swapped. |
|
static boolean |
isCollectionType(java.lang.Class<?> clazzType,
boolean includeInterfaces)
Return whether we can identify the typeName as a java.util collection class or interface as specified. |
|
static boolean |
isCollectionType(java.lang.String typeName,
boolean includeInterfaces)
Return whether we can identify the typeName as a java.util collection class or interface as specified. |
|
static boolean |
isEmpty(java.lang.Object[] items)
Returns whether the items array is null or has zero length. |
|
static boolean |
isNotEmpty(java.lang.Object[] items)
Returns whether the items array is non-null and has at least one entry. |
|
static
|
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 boolean |
valuesAreTransitivelyEqual(java.lang.Object[] thisArray,
java.lang.Object[] thatArray)
Returns whether the arrays are equal by examining each of their elements, even if they are arrays themselves. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final TypeMap COLLECTION_INTERFACES_BY_NAMES
public static final TypeMap COLLECTION_CLASSES_BY_NAMES
Method Detail |
---|
public static int addWithoutDuplicates(java.util.Collection<java.lang.String> source, java.util.Collection<java.lang.String> target)
source
- target
-
public static java.lang.Class<?> getCollectionTypeFor(java.lang.String shortName)
shortName
- String
public static boolean isCollectionType(java.lang.String typeName, boolean includeInterfaces)
typeName
- StringincludeInterfaces
- boolean
public static boolean isCollectionType(java.lang.Class<?> clazzType, boolean includeInterfaces)
clazzType
- ClassincludeInterfaces
- boolean
public static <T> java.util.Set<T> asSet(T[] items)
items
- Object[]
public static <K,V> java.util.Map<K,V> mapFrom(K[] keys, V[] values)
keys
- K[]values
- V[]
public static <K,V> java.util.Map<V,K> invertedMapFrom(java.util.Map<K,V> source)
source
- Map
public static boolean arraysAreEqual(java.lang.Object value, java.lang.Object otherValue)
value
- ObjectotherValue
- Object
public static boolean valuesAreTransitivelyEqual(java.lang.Object[] thisArray, java.lang.Object[] thatArray)
thisArray
- Object[]thatArray
- Object[]
public static boolean areEqual(java.lang.Object value, java.lang.Object otherValue)
value
- ObjectotherValue
- Object
public static boolean isEmpty(java.lang.Object[] items)
items
-
public static boolean isNotEmpty(java.lang.Object[] items)
items
-
public static <T> boolean areSemanticEquals(T[] a, T[] b)
T
- a
- b
-
public static <T> T[] addWithoutDuplicates(T[] values, T newValue)
T
- values
- newValue
-
public static <T> T[] addWithoutDuplicates(T[] values, T[] newValues)
T
- values
- newValues
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |