org.apache.openejb.jee
Class KeyedCollection<K,V>

java.lang.Object
  extended by java.util.AbstractCollection<V>
      extended by org.apache.openejb.jee.KeyedCollection<K,V>
All Implemented Interfaces:
Iterable<V>, Collection<V>
Direct Known Subclasses:
LocalCollection

public class KeyedCollection<K,V>
extends AbstractCollection<V>

A KeyedCollection is a light weight wrapper around a Map (LinkedHashMap) values set. When a value is added using the add method of this class a key is obtained for the value using either the provided KeyExtractor, or if no KeyExtractor was provided, the value is cast to Keyable and the getKey() method is called. The underlying Map can be obtainded with the toMap method. Any changes to this map are directly reflected in this collection. Additions to the map do not need to implement Keyable, nor do the values need to be keyed using the key returned from the KeyExtractor.getKey(value) or the key returned from the Keyable.getKey() Method.


Constructor Summary
KeyedCollection()
           
KeyedCollection(Collection<? extends V> c)
           
KeyedCollection(int initialCapacity)
           
KeyedCollection(KeyExtractor<? extends K,? super V> keyExtractor)
           
 
Method Summary
 boolean add(V value)
           
 void clear()
           
protected  K getKey(V value)
           
 boolean isEmpty()
           
 Iterator<V> iterator()
           
 int size()
           
 Map<K,V> toMap()
          Get the underlying map used by this collection.
 String toString()
           
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

KeyedCollection

public KeyedCollection()

KeyedCollection

public KeyedCollection(KeyExtractor<? extends K,? super V> keyExtractor)

KeyedCollection

public KeyedCollection(Collection<? extends V> c)

KeyedCollection

public KeyedCollection(int initialCapacity)
Method Detail

toMap

public Map<K,V> toMap()
Get the underlying map used by this collection. Any changes to this map are directly reflected in this collection. Additions to the map do not need to implement Keyable, nor do the values need to be keyed using the key returned from the KeyExtractor.getKey(value) or the key returned from the Keyable.getKey() Method.

Returns:
the indexed contents of this collection

add

public boolean add(V value)
Specified by:
add in interface Collection<V>
Overrides:
add in class AbstractCollection<V>

iterator

public Iterator<V> iterator()
Specified by:
iterator in interface Iterable<V>
Specified by:
iterator in interface Collection<V>
Specified by:
iterator in class AbstractCollection<V>

size

public int size()
Specified by:
size in interface Collection<V>
Specified by:
size in class AbstractCollection<V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<V>
Overrides:
isEmpty in class AbstractCollection<V>

clear

public void clear()
Specified by:
clear in interface Collection<V>
Overrides:
clear in class AbstractCollection<V>

toString

public String toString()
Overrides:
toString in class AbstractCollection<V>

getKey

protected K getKey(V value)


Copyright © 1999-2013 The Apache OpenEJB development community. All Rights Reserved.