org.ujac.util
Class CollectionUtils

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

public class CollectionUtils
extends Object

Name: CollectionUtils
Description: A class providing methods to ease the handling of collections.

Author:
lauerc

Constructor Summary
CollectionUtils()
           
 
Method Summary
static void clear(Collection collection)
          Clears the given collection.
static void clear(Map map)
          Clears the given map.
static boolean contains(Collection collection, Object element)
          Probes whether the given map contains the given key or not.
static boolean containsKey(Map map, Object key)
          Probes whether the given map contains the given key or not.
static boolean containsValue(Map map, Object value)
          Probes whether the given map contains the given value or not.
static List createArrayList(Object obj)
          Creates an ArrayList instance and adds the given object to it.
static List createArrayList(Object[] objs)
          Creates an ArrayList instance and adds the given objects to it.
static Map createHashMap(Object key, Object value)
          Creates a HashMap instance and adds the given key/value pair to it.
static Set createHashSet(Object obj)
          Creates an HashSet instance and adds the given object to it.
static Set createHashSet(Object[] objs)
          Creates an HashSet instance and adds the given objects to it.
static Object get(Map map, Object key)
          Gets a value according to the given key from the given map.
static int getSize(Collection collection)
          Gets the size of the given collection.
static int getSize(Map map)
          Gets the size of the given map.
static boolean isEmpty(Collection collection)
          Probes whether the given collection is empty or not.
static boolean isEmpty(Map map)
          Probes whether the given map is empty or not.
static Map put(Map map, Object key, Object value)
          Puts the given key/value pair into the given map.
static Map putAll(Map map, Map other)
          Puts the given key/value pair into the given map.
static Object putAll(Map map, Object key)
          Gets a value according to the given key from the given map.
static void sortList(List list, CompareTuple compareTuple)
          Creates an ArrayList instance and adds the given objects to it.
static void sortList(List list, CompareTuple[] compareTuples)
          Creates an ArrayList instance and adds the given objects to it.
static void sortList(List list, String fieldName)
          Creates an ArrayList instance and adds the given objects to it.
static void sortList(List list, String[] fieldNames)
          Creates an ArrayList instance and adds the given objects to it.
 
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 final boolean isEmpty(Collection collection)
Probes whether the given collection is empty or not.

Parameters:
collection - The collection to test.
Returns:
true if the given collection is null or contains no elements

getSize

public static final int getSize(Collection collection)
Gets the size of the given collection.

Parameters:
collection - The collection to to get the size for.
Returns:
The size of the given collection or -1 in case null was given.

contains

public static final boolean contains(Collection collection,
                                     Object element)
Probes whether the given map contains the given key or not.

Parameters:
collection - The collection to check the presence of the element for.
element - The collection to to test.
Returns:
true if the given map contains the given key, else false.

clear

public static final void clear(Collection collection)
Clears the given collection.

Parameters:
collection - The collection to clear.

isEmpty

public static final boolean isEmpty(Map map)
Probes whether the given map is empty or not.

Parameters:
map - The map to test.
Returns:
true if the given map is null or contains no elements

getSize

public static final int getSize(Map map)
Gets the size of the given map.

Parameters:
map - The map to to get the size for.
Returns:
The size of the given map or -1 in case null was given.

containsKey

public static final boolean containsKey(Map map,
                                        Object key)
Probes whether the given map contains the given key or not.

Parameters:
map - The map to check the presence of the key for.
key - The key to to test.
Returns:
true if the given map contains the given key, else false.

containsValue

public static final boolean containsValue(Map map,
                                          Object value)
Probes whether the given map contains the given value or not.

Parameters:
map - The map to check the presence of the value for.
value - The value to to test.
Returns:
true if the given map contains the given value, else false.

clear

public static final void clear(Map map)
Clears the given map.

Parameters:
map - The map to clear.

createArrayList

public static final List createArrayList(Object obj)
Creates an ArrayList instance and adds the given object to it.

Parameters:
obj - The object to add to the List.
Returns:
The created List instance.

createArrayList

public static final List createArrayList(Object[] objs)
Creates an ArrayList instance and adds the given objects to it.

Parameters:
objs - The objects to add to the List.
Returns:
The created List instance.

sortList

public static final void sortList(List list,
                                  String fieldName)
Creates an ArrayList instance and adds the given objects to it.

Parameters:
list - The list to sort.
fieldName - The name of the field by which to sort.

sortList

public static final void sortList(List list,
                                  CompareTuple compareTuple)
Creates an ArrayList instance and adds the given objects to it.

Parameters:
list - The list to sort.
compareTuple - The name of the field plus the direction by which to sort.

sortList

public static final void sortList(List list,
                                  String[] fieldNames)
Creates an ArrayList instance and adds the given objects to it.

Parameters:
list - The list to sort.
fieldNames - The names of the fields by which to sort.

sortList

public static final void sortList(List list,
                                  CompareTuple[] compareTuples)
Creates an ArrayList instance and adds the given objects to it.

Parameters:
list - The list to sort.
compareTuples - The names of the field plus the directions by which to sort.

createHashSet

public static final Set createHashSet(Object obj)
Creates an HashSet instance and adds the given object to it.

Parameters:
obj - The object to add to the Set.
Returns:
The created Set instance.

createHashSet

public static final Set createHashSet(Object[] objs)
Creates an HashSet instance and adds the given objects to it.

Parameters:
objs - The objects to add to the List.
Returns:
The created Set instance.

createHashMap

public static final Map createHashMap(Object key,
                                      Object value)
Creates a HashMap instance and adds the given key/value pair to it.

Parameters:
key - The key for the value to add.
value - The value to add.
Returns:
The created Map instance.

put

public static final Map put(Map map,
                            Object key,
                            Object value)
Puts the given key/value pair into the given map.

Parameters:
map - The map to set the key/value pair to.
key - The key to associate the value with.
value - The value to add.
Returns:
The map instance.

putAll

public static final Map putAll(Map map,
                               Map other)
Puts the given key/value pair into the given map.

Parameters:
map - The map to add the given other map's entries to.
other - The map to merge with the given map.
Returns:
The map instance.

get

public static final Object get(Map map,
                               Object key)
Gets a value according to the given key from the given map.

Parameters:
map - The map to get the value from.
key - The key to get the value for.
Returns:
value The associated value.

putAll

public static final Object putAll(Map map,
                                  Object key)
Gets a value according to the given key from the given map.

Parameters:
map - The map to get the value from.
key - The key to get the value for.
Returns:
value The associated value.


Copyright © 2003-2004 UJAC.org. All Rights Reserved.