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:
java.lang.Iterable<V>, java.util.Collection<V>
Direct Known Subclasses:
LocalCollection

public class KeyedCollection<K,V>
extends java.util.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(java.util.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()
           
 java.util.Iterator<V> iterator()
           
 int size()
           
 java.util.Map<K,V> toMap()
          Get the underlying map used by this collection.
 java.lang.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(java.util.Collection<? extends V> c)

KeyedCollection

public KeyedCollection(int initialCapacity)
Method Detail

toMap

public java.util.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 java.util.Collection<V>
Overrides:
add in class java.util.AbstractCollection<V>

iterator

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

size

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

isEmpty

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

clear

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

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection<V>

getKey

protected K getKey(V value)


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