nl.knowledgeplaza.util
Class CollectionUtil

java.lang.Object
  extended by nl.knowledgeplaza.util.CollectionUtil

public class CollectionUtil
extends Object

The CollectionUtil provides methods for wrapping normal Collection objects with ObservableCollection objects, which allows a listener to register for changes to the Collection object.

Although the Collection interface is not implemented by Maps, and therefore it seems inconsistent to place it in a CollectionUtil class, it is sticking with the inconsistent Sun standard used in the Collections object.


Constructor Summary
CollectionUtil()
           
 
Method Summary
static
<T> T[]
a(T... params)
          quickly make an array a("a", "b" , "c", "e")
static Map addAll(Map map, String keyValues)
          quick insert some string key / values in a map and return the map itself
static Collection appendNull(Collection c)
          Add null to a collection (used for comboboxes and lists to allow clearing)
static List asList(Object[] objects)
          Easily convert an array of objects to a list of objects (which then can be casted).
static int binaryFindInsertLocation(List list, Object o, Comparator comparator)
          Use a binary find algorithm to determine the index where a new object should be inserted
static int compareForNull(Object o1, Object o2)
          Do a compare for null on the two objects.
static Map createMap(String keyValues)
          quick insert some string key / values in a linear map
static
<T> List<T>
createNewArrayListAndClearOriginal(List<T> list)
          For synchronized lists: create a new collection and clear the original
static
<T> List<T>
l(T... params)
          quickly make a list l("a", "b" , "c", "e")
static
<K,V> Map<K,V>
m(Map<K,V> map, Object... params)
          quickly make a map: alternate keys and values in the parameter list m(new LinearMap(), "a", "b" , "c", "e") Map m = m(new LinearMap(), "a", 1 , "c", 2);
static
<K,V> Map<K,V>
m(Object... params)
          quickly make a linear map m("a", "b" , "c", "e") Map m = m("a", 1 , "c", 2);
static List observableList(List l)
          Returns an observable view of the specified object.
static Map observableMap(Map m)
          Returns an observable view of the specified object.
static Set observableSet(Set s)
          Returns an observable view of the specified object.
static SortedMap observableSortedMap(SortedMap m)
          Returns an observable view of the specified object.
static SortedSet observableSortedSet(SortedSet s)
          Returns an observable view of the specified object.
static Collection prependNull(Collection c)
          Add null to a new collection (used for comboboxes and lists to allow clearing)
static Map put(Map map, Object key, Object value)
          quick insert some string key / values in a map and return the map itself
static
<T> List<T>
toList(T... arr)
          Produce lists of ints or Strings: List ints = CollectionUtil.toList(1, 2, 3); List words = CollectionUtil.toList("hello", "world");
static String toString(Map m)
          because maps may contains array, which do not toString themselves too well
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtil

public CollectionUtil()
Method Detail

observableList

public static List observableList(List l)
Returns an observable view of the specified object. Listeners can observe changes to the list by calling its addCollectionListener() method.

Parameters:
l - the list for which the observable list is returned
Returns:
an observable view of the specified list

observableSet

public static Set observableSet(Set s)
Returns an observable view of the specified object. Listeners can observe changes to the set by calling its addCollectionListener() method.

Parameters:
s - the set for which the observable set is returned
Returns:
an observable view of the specified set

observableSortedSet

public static SortedSet observableSortedSet(SortedSet s)
Returns an observable view of the specified object. Listeners can observe changes to the sorted set by calling its addCollectionListener() method.

Parameters:
s - the sorted set for which the observable sorted set is returned
Returns:
an observable view of the specified sorted set

observableMap

public static Map observableMap(Map m)
Returns an observable view of the specified object. Listeners can observe changes to the map by calling its addCollectionListener() method.

Parameters:
m - the map for which the observable map is returned
Returns:
an observable view of the specified map

observableSortedMap

public static SortedMap observableSortedMap(SortedMap m)
Returns an observable view of the specified object. Listeners can observe changes to the sorted map by calling its addCollectionListener() method.

Parameters:
m - the sorted map for which the observable sorted map is returned
Returns:
an observable view of the specified sorted map

addAll

public static Map addAll(Map map,
                         String keyValues)
quick insert some string key / values in a map and return the map itself


put

public static Map put(Map map,
                      Object key,
                      Object value)
quick insert some string key / values in a map and return the map itself


createMap

public static Map createMap(String keyValues)
quick insert some string key / values in a linear map


toString

public static String toString(Map m)
because maps may contains array, which do not toString themselves too well


compareForNull

public static int compareForNull(Object o1,
                                 Object o2)
Do a compare for null on the two objects. If either is null, -1, 0 or 1 will be returned depending. If neither is null, Integer.MIN_VALUE will be returned and the compare should then delve into actually comparing the objects.


binaryFindInsertLocation

public static int binaryFindInsertLocation(List list,
                                           Object o,
                                           Comparator comparator)
Use a binary find algorithm to determine the index where a new object should be inserted

Parameters:
list -
o -
comparator -
Returns:

appendNull

public static Collection appendNull(Collection c)
Add null to a collection (used for comboboxes and lists to allow clearing)


prependNull

public static Collection prependNull(Collection c)
Add null to a new collection (used for comboboxes and lists to allow clearing)


asList

public static List asList(Object[] objects)
Easily convert an array of objects to a list of objects (which then can be casted). This won't work with arrays of primitives (e.g. int[]). So you can write: for (X lX : (List)CollectionUtil.asList(iJList.getSelectedValues()) ) Casting is not working on an object array (e.g. "(X[])iJList.getSelectedValues()" )

Parameters:
object - array
Returns:
list containing the objects

toList

public static <T> List<T> toList(T... arr)
Produce lists of ints or Strings: List ints = CollectionUtil.toList(1, 2, 3); List words = CollectionUtil.toList("hello", "world");

Type Parameters:
T -
Parameters:
arr -
Returns:

createNewArrayListAndClearOriginal

public static <T> List<T> createNewArrayListAndClearOriginal(List<T> list)
For synchronized lists: create a new collection and clear the original

Type Parameters:
T -
Parameters:
list -
Returns:

a

public static <T> T[] a(T... params)
quickly make an array a("a", "b" , "c", "e")


l

public static <T> List<T> l(T... params)
quickly make a list l("a", "b" , "c", "e")


m

public static <K,V> Map<K,V> m(Map<K,V> map,
                               Object... params)
quickly make a map: alternate keys and values in the parameter list m(new LinearMap(), "a", "b" , "c", "e") Map m = m(new LinearMap(), "a", 1 , "c", 2);


m

public static <K,V> Map<K,V> m(Object... params)
quickly make a linear map m("a", "b" , "c", "e") Map m = m("a", 1 , "c", 2);

Returns:


Copyright © 2012 KnowledgePlaza. All Rights Reserved.