magi.toolkit.util
Class MagiList

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.ArrayList
                    |
                    +--magi.toolkit.util.MagiList
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, IList, java.util.List, java.util.RandomAccess, java.io.Serializable
Direct Known Subclasses:
ComboList

public class MagiList
extends java.util.ArrayList
implements java.util.List, IList

A List (or Collection) that enhances the functionality of a standard List, also supporting "immutable".

Author:
Paul Atkinson, Magi Systems Pty Ltd.
See Also:
Serialized Form

Field Summary
static int ADD_MAP_KEYS
           
static int ADD_MAP_VALUES
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
MagiList()
          Default constructor.
MagiList(java.util.Collection collection)
          Creates a List and pre-populates this List with elements from the Collection object, eg another List, or Set, Vector, etc.
MagiList(int initialCapacity)
          Creates a List with the initial capacity specified here.
MagiList(java.util.Map map, int addType)
          Creates a List and pre-populates this List with elements from the Map provided.
MagiList(java.lang.Object[] objects)
          Creates a List and pre-populates this List with elements from the object array provided.
 
Method Summary
 boolean add(int index, java.util.Map map, java.lang.Object key)
          Adds a "value" element from the Map provided, which matches the key passed in.
 boolean add(java.util.Map map, java.lang.Object key)
          Adds a "value" element from the Map provided, which matches the key passed in.
 boolean addAll(int index, java.util.Map map, int addType)
          Populates this List with elements from the Map provided.
 boolean addAll(int index, java.lang.Object[] objects)
          Populates this List with elements from the object array provided.
 boolean addAll(java.util.Map map, int addType)
          Populates this List with elements from the Map provided.
 boolean addAll(java.lang.Object[] objects)
          Populates this List with elements from the object array provided.
 IList asImmutable()
          Returns the "immutable" list for this object.
 void reverse()
          Reverses the order of all elements in this List.
 void sort()
          Sorts elements in this List into ascending order.
 void sort(java.util.Comparator comparator)
          Sorts elements in this List in the order defined by the Comparator.
 void sortAscending()
          Sorts elements in this List into ascending order.
 void sortDescending()
          Sorts elements in this List into ascending order.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArray
 
Methods inherited from interface magi.toolkit.util.IList
contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, size, subList, toArray, toArray
 

Field Detail

ADD_MAP_KEYS

public static final int ADD_MAP_KEYS
See Also:
Constant Field Values

ADD_MAP_VALUES

public static final int ADD_MAP_VALUES
See Also:
Constant Field Values
Constructor Detail

MagiList

public MagiList()
Default constructor.


MagiList

public MagiList(int initialCapacity)
Creates a List with the initial capacity specified here.

Parameters:
initialCapacity - the initial size of the List array.

MagiList

public MagiList(java.util.Collection collection)
Creates a List and pre-populates this List with elements from the Collection object, eg another List, or Set, Vector, etc.

Parameters:
collection - a Collection of objects to pre-populate.

MagiList

public MagiList(java.lang.Object[] objects)
Creates a List and pre-populates this List with elements from the object array provided.

Parameters:
objects - an array of object elements to pre-populate.

MagiList

public MagiList(java.util.Map map,
                int addType)
Creates a List and pre-populates this List with elements from the Map provided. Map keys or values may be added, depending on the value passed in for addType. See ADD_MAP constants defined by this class for possible values of addType. Allows the addition of elements from Maps such as HashMap, Hashtable, TreeMap, etc.

Parameters:
map - the Map object to pre-populate this List from.
addType - the type of objects to add, either keys or values, see ADD_MAP constants defined by this class for possible values.
Method Detail

addAll

public boolean addAll(java.lang.Object[] objects)
Populates this List with elements from the object array provided. The additional elements are added to the end of the List.

Parameters:
objects - an array of object elements to populate.
Returns:
true if the List is altered by this call.

addAll

public boolean addAll(int index,
                      java.lang.Object[] objects)
Populates this List with elements from the object array provided. The additional elements are added to the List starting at the index position. The element at that position, and elements after that position are right-shifted by the number of elements added.

Parameters:
objects - an array of object elements to populate.
Returns:
true if the List is altered by this call.

addAll

public boolean addAll(java.util.Map map,
                      int addType)
Populates this List with elements from the Map provided. Map keys or values may be added, depending on the value passed in for addType. See ADD_MAP constants defined by this class for possible values of addType. New elements are added to the end of this List. Allows the addition of elements from Maps such as HashMap, Hashtable, TreeMap, etc.

Parameters:
map - the Map object to populate this List from.
addType - the type of objects to add, either keys or values, see ADD_MAP constants defined by this class for possible values.

addAll

public boolean addAll(int index,
                      java.util.Map map,
                      int addType)
Populates this List with elements from the Map provided. Map keys or values may be added, depending on the value passed in for addType. See ADD_MAP constants defined by this class for possible values of addType. New elements are added to the end of this List. Allows the addition of elements from Maps such as HashMap, Hashtable, TreeMap, etc.

Parameters:
index - the index to begin adding elements in this List.
map - the Map object to populate this List from.
addType - the type of objects to add, either keys or values, see ADD_MAP constants defined by this class for possible values.

add

public boolean add(java.util.Map map,
                   java.lang.Object key)
Adds a "value" element from the Map provided, which matches the key passed in. If the "key" does not exist in the Map, nothing is added. The element is added to the end of this List.

Parameters:
map - a Map object to extract a value from.
key - the "key" of the value to add to this List.
Returns:
true if an element is added, and false if not.

add

public boolean add(int index,
                   java.util.Map map,
                   java.lang.Object key)
Adds a "value" element from the Map provided, which matches the key passed in. If the "key" does not exist in the Map, nothing is added. The element is added to the end of this List.

Parameters:
index - the index to add this element at.
map - a Map object to extract a value from.
key - the "key" of the value to add to this List.
Returns:
true if an element is added, and false if not.

sort

public void sort()
Sorts elements in this List into ascending order. Elements must implement the Comparable interface for this sort to work.

See Also:
Arrays.sort(Object[])

sort

public void sort(java.util.Comparator comparator)
Sorts elements in this List in the order defined by the Comparator.

See Also:
Arrays.sort(Object[],Comparator)

sortAscending

public void sortAscending()
Sorts elements in this List into ascending order. Elements must implement the Comparable interface for this sort to work.

See Also:
Arrays.sort(Object[])

sortDescending

public void sortDescending()
Sorts elements in this List into ascending order. Elements must implement the Comparable interface for this sort to work.

See Also:
Arrays.sort(Object[])

reverse

public void reverse()
Reverses the order of all elements in this List. For example, the first element in the List becomes the last, and vice-versa. Very useful for sorting manipulations.


asImmutable

public IList asImmutable()
Returns the "immutable" list for this object. No elements can be modified in the IList. MagiList implements IList, so it can be cast directly also.

Returns:
an immutable IList reference.