Package org.apache.openejb.jee
Class KeyedCollection<K,V>
- java.lang.Object
-
- java.util.AbstractCollection<V>
-
- 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
Constructors Constructor Description KeyedCollection()KeyedCollection(int initialCapacity)KeyedCollection(Collection<? extends V> c)KeyedCollection(KeyExtractor<? extends K,? super V> keyExtractor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(V value)voidclear()protected KgetKey(V value)booleanisEmpty()Iterator<V>iterator()intsize()Map<K,V>toMap()Get the underlying map used by this collection.StringtoString()-
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, parallelStream, removeIf, spliterator, stream
-
-
-
-
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:
addin interfaceCollection<K>- Overrides:
addin classAbstractCollection<V>
-
iterator
public Iterator<V> iterator()
- Specified by:
iteratorin interfaceCollection<K>- Specified by:
iteratorin interfaceIterable<K>- Specified by:
iteratorin classAbstractCollection<V>
-
size
public int size()
- Specified by:
sizein interfaceCollection<K>- Specified by:
sizein classAbstractCollection<V>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<K>- Overrides:
isEmptyin classAbstractCollection<V>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<K>- Overrides:
clearin classAbstractCollection<V>
-
toString
public String toString()
- Overrides:
toStringin classAbstractCollection<V>
-
-