org.springframework.shell.support.util
Class PairList<K,V>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<Pair<K,V>>
              extended by org.springframework.shell.support.util.PairList<K,V>
Type Parameters:
K - the type of key
V - the type of value
All Implemented Interfaces:
Serializable, Cloneable, Iterable<Pair<K,V>>, Collection<Pair<K,V>>, List<Pair<K,V>>, RandomAccess

public class PairList<K,V>
extends ArrayList<Pair<K,V>>

A List of Pairs. Unlike a Map, it can have duplicate and/or null keys.

Since:
1.2.0
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
PairList()
          Constructor for an empty list of pairs
PairList(List<? extends K> keys, List<? extends V> values)
          Constructor for building a list of the given key-value pairs
PairList(Pair<K,V>... pairs)
          Returns the given array of pairs as a modifiable list
 
Method Summary
 boolean add(K key, V value)
          Adds a new pair to this list with the given key and value
 List<K> getKeys()
          Returns the keys of each Pair in this list
 List<V> getValues()
          Returns the values of each Pair in this list
 Pair<K,V>[] toArray()
           
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

PairList

public PairList(Pair<K,V>... pairs)
Returns the given array of pairs as a modifiable list

Type Parameters:
K - the type of key
V - the type of value
Parameters:
pairs - the pairs to put in a list

PairList

public PairList(List<? extends K> keys,
                List<? extends V> values)
Constructor for building a list of the given key-value pairs

Parameters:
keys - the keys (can be null)
values - the values (must be null if the keys are null, otherwise must be non-null and of the same size as the keys)

PairList

public PairList()
Constructor for an empty list of pairs

Method Detail

getKeys

public List<K> getKeys()
Returns the keys of each Pair in this list

Returns:
a non-null list

getValues

public List<V> getValues()
Returns the values of each Pair in this list

Returns:
a non-null modifiable copy of this list

add

public boolean add(K key,
                   V value)
Adds a new pair to this list with the given key and value

Parameters:
key - the key to add; can be null
value - the value to add; can be null
Returns:
true (as specified by Collection.add(E))

toArray

public Pair<K,V>[] toArray()
Specified by:
toArray in interface Collection<Pair<K,V>>
Specified by:
toArray in interface List<Pair<K,V>>
Overrides:
toArray in class ArrayList<Pair<K,V>>