org.springframework.util
Class CollectionUtils

java.lang.Object
  extended by org.springframework.util.CollectionUtils

public abstract class CollectionUtils
extends Object

Miscellaneous collection utility methods. Mainly for internal use within the framework.

Since:
1.1.3
Author:
Juergen Hoeller, Rob Harrop

Constructor Summary
CollectionUtils()
           
 
Method Summary
static Object findValueOfType(Collection coll, Class type)
          Find a value of the given type in the given collection.
static Object findValueOfType(Collection coll, Class[] types)
          Find a value of one of the given types in the given collection: searching the collection for a value of the first type, then searching for a value of the second type, etc.
static boolean hasUniqueObject(Collection coll)
          Determine whether the given collection only contains a single unique object.
static boolean isEmpty(Collection collection)
          Return true if the supplied Collection is null or empty.
static boolean isEmpty(Map map)
          Return true if the supplied Map is null or empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtils

public CollectionUtils()
Method Detail

isEmpty

public static boolean isEmpty(Collection collection)
Return true if the supplied Collection is null or empty. Otherwise, return false.

Parameters:
collection - the Collection to check

isEmpty

public static boolean isEmpty(Map map)
Return true if the supplied Map is null or empty. Otherwise, return false.

Parameters:
map - the Map to check

hasUniqueObject

public static boolean hasUniqueObject(Collection coll)
Determine whether the given collection only contains a single unique object.

Parameters:
coll - the collection to check
Returns:
true if the collection contains a single reference or multiple references to the same instance, false else

findValueOfType

public static Object findValueOfType(Collection coll,
                                     Class type)
                              throws IllegalArgumentException
Find a value of the given type in the given collection.

Parameters:
coll - the collection to search
type - the type to look for
Returns:
a value of the given type found, or null if none
Throws:
IllegalArgumentException - if more than one value of the given type found

findValueOfType

public static Object findValueOfType(Collection coll,
                                     Class[] types)
                              throws IllegalArgumentException
Find a value of one of the given types in the given collection: searching the collection for a value of the first type, then searching for a value of the second type, etc.

Parameters:
coll - the collection to search
types - the types to look for, in prioritized order
Returns:
a of one of the given types found, or null if none
Throws:
IllegalArgumentException - if more than one value of the given type found


Copyright (c) 2002-2006 The Spring Framework Project.