nl.knowledgeplaza.util
Class CollectionUtil

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

public class CollectionUtil
extends java.lang.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 java.util.Map addAll(java.util.Map map, java.lang.String keyValues)
          quick insert some string key / values in a map and return the map itself
static java.util.Collection appendNull(java.util.Collection c)
          Add null to a collection (used for comboboxes and lists to allow clearing)
static java.util.List asList(java.lang.Object[] objects)
          Easily convert an array of objects to a list of objects (which then can be casted).
static int binaryFindInsertLocation(java.util.List list, java.lang.Object o, java.util.Comparator comparator)
          Use a binary find algorithm to determine the index where a new object should be inserted
static int compareForNull(java.lang.Object o1, java.lang.Object o2)
          Do a compare for null on the two objects.
static java.util.Map createMap(java.lang.String keyValues)
          quick insert some string key / values in a linear map
static
<T> java.util.List<T>
createNewArrayListAndClearOriginal(java.util.List<T> list)
          For synchronized lists: create a new collection and clear the original
static java.util.List observableList(java.util.List l)
          Returns an observable view of the specified object.
static java.util.Map observableMap(java.util.Map m)
          Returns an observable view of the specified object.
static java.util.Set observableSet(java.util.Set s)
          Returns an observable view of the specified object.
static java.util.SortedMap observableSortedMap(java.util.SortedMap m)
          Returns an observable view of the specified object.
static java.util.SortedSet observableSortedSet(java.util.SortedSet s)
          Returns an observable view of the specified object.
static java.util.Collection prependNull(java.util.Collection c)
          Add null to a new collection (used for comboboxes and lists to allow clearing)
static java.util.Map put(java.util.Map map, java.lang.Object key, java.lang.Object value)
          quick insert some string key / values in a map and return the map itself
static
<T> java.util.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 java.lang.String toString(java.util.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 java.util.List observableList(java.util.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 java.util.Set observableSet(java.util.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 java.util.SortedSet observableSortedSet(java.util.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 java.util.Map observableMap(java.util.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 java.util.SortedMap observableSortedMap(java.util.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 java.util.Map addAll(java.util.Map map,
                                   java.lang.String keyValues)
quick insert some string key / values in a map and return the map itself


put

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


createMap

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


toString

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


compareForNull

public static int compareForNull(java.lang.Object o1,
                                 java.lang.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(java.util.List list,
                                           java.lang.Object o,
                                           java.util.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 java.util.Collection appendNull(java.util.Collection c)
Add null to a collection (used for comboboxes and lists to allow clearing)


prependNull

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


asList

public static java.util.List asList(java.lang.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> java.util.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> java.util.List<T> createNewArrayListAndClearOriginal(java.util.List<T> list)
For synchronized lists: create a new collection and clear the original

Type Parameters:
T -
Parameters:
list -
Returns:


Copyright © 2010. All Rights Reserved.