Package com.globalmentor.collections
Class DecoratorIDedMappedList<K,E extends IDed<K>>
- java.lang.Object
-
- com.globalmentor.collections.CollectionDecorator<E>
-
- com.globalmentor.collections.ListDecorator<E>
-
- com.globalmentor.collections.DecoratorIDedMappedList<K,E>
-
- All Implemented Interfaces:
MappedList<K,E>
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.List<E>
public class DecoratorIDedMappedList<K,E extends IDed<K>> extends ListDecorator<E> implements MappedList<K,E>
A list that allows quick lookup ofIDed
objects. This list will give unpredictable results if multiple objects with the same ID are added to the list.- Author:
- Garret Wilson
- Implementation Specification:
- This list does not support
null
values.
-
-
Field Summary
-
Fields inherited from class com.globalmentor.collections.ListDecorator
list
-
Fields inherited from class com.globalmentor.collections.CollectionDecorator
collection
-
-
Constructor Summary
Constructors Constructor Description DecoratorIDedMappedList(java.util.Map<K,E> map, java.util.List<E> list)
Decorates the given list by mapping its values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
boolean
add(E o)
boolean
addAll(int index, java.util.Collection<? extends E> c)
boolean
addAll(java.util.Collection<? extends E> c)
void
clear()
boolean
containsKey(java.lang.Object key)
Returnstrue
if this map contains a mapping for the specified key.E
get(java.lang.Object key)
Returns the value to which this map maps the specified key.protected java.util.Map<K,E>
getMap()
E
remove(int index)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
E
removeKey(java.lang.Object key)
Removes the value from the list mapped to the given key value.boolean
retainAll(java.util.Collection<?> c)
E
set(int index, E element)
-
Methods inherited from class com.globalmentor.collections.ListDecorator
get, indexOf, lastIndexOf, listIterator, listIterator, replaceAll, sort, subList
-
Methods inherited from class com.globalmentor.collections.CollectionDecorator
contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeIf, size, spliterator, stream, toArray, toArray
-
-
-
-
Constructor Detail
-
DecoratorIDedMappedList
public DecoratorIDedMappedList(java.util.Map<K,E> map, java.util.List<E> list)
Decorates the given list by mapping its values. Any values present in the map will be removed. Any values already present in the list will be mapped.- Parameters:
map
- The map which stores the ID to list item associations.list
- The list in which to store the list items.- Throws:
java.lang.IllegalArgumentException
- if more than one item with the same ID exists in the list.
-
-
Method Detail
-
add
public boolean add(E o)
-
remove
public boolean remove(java.lang.Object o)
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
clear
public void clear()
-
add
public void add(int index, E element)
-
remove
public E remove(int index)
-
containsKey
public boolean containsKey(java.lang.Object key)
Description copied from interface:MappedList
Returnstrue
if this map contains a mapping for the specified key. More formally, returnstrue
if and only if this map contains a mapping for a keyk
such that(key==null ? k==null : key.equals(k))
. (There can be at most one such mapping.)- Specified by:
containsKey
in interfaceMappedList<K,E extends IDed<K>>
- Parameters:
key
- key whose presence in this map is to be tested.- Returns:
true
if this map contains a mapping for the specified key.
-
get
public E get(java.lang.Object key)
Description copied from interface:MappedList
Returns the value to which this map maps the specified key. Returnsnull
if the map contains no mapping for this key. A return value ofnull
does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull
. ThecontainsKey
operation may be used to distinguish these two cases.More formally, if this map contains a mapping from a key
k
to a valuev
such that(key==null ? k==null : key.equals(k))
, then this method returnsv
; otherwise it returnsnull
. (There can be at most one such mapping.)- Specified by:
get
in interfaceMappedList<K,E extends IDed<K>>
- Parameters:
key
- key whose associated value is to be returned.- Returns:
- the value to which this map maps the specified key, or
null
if the map contains no mapping for this key. - See Also:
MappedList.containsKey(Object)
-
removeKey
public E removeKey(java.lang.Object key)
Description copied from interface:MappedList
Removes the value from the list mapped to the given key value.
-
-