The Map API is very difficult to decorate correctly, and involves implementing lots of different classes. This class exists to provide a simpler API.
Special hook methods are provided that are called when objects are added to the map. By overriding these methods, the input can be validated or manipulated. In addition to the main map methods, the entrySet is also affected, which is the hardest part of writing map implementations.
This class is package-scoped, and may be withdrawn or replaced in future versions of Commons Collections.
| Modifier and Type | Class and Description |
|---|---|
| private class | AbstractInputCheckedMapDecorator.EntrySet
Implementation of an entry set that checks additions via setValue. |
| private class | AbstractInputCheckedMapDecorator.EntrySetIterator
Implementation of an entry set iterator that checks additions via setValue. |
| private class | AbstractInputCheckedMapDecorator.MapEntry
Implementation of a map entry that checks additions via setValue. |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected | AbstractInputCheckedMapDecorator(final Map<K, V>
the map to decorate, must not be null map)Constructor that wraps (not copies). |
| Modifier and Type | Method and Description |
|---|---|
| protected abstract V | Returns: the input valuethe value to check value)Hook method called when a value is being set using |
| public Set | entrySet()
Overrides org. Implements java. Set view of the mappings contained in this map.
|
| protected boolean | Returns: true alwaysHook method called to determine if |
| AbstractInputCheckedMapDecorator | back to summary |
|---|---|
| protected AbstractInputCheckedMapDecorator() Constructor only used in deserialization, do not use otherwise. | |
| AbstractInputCheckedMapDecorator | back to summary |
|---|---|
| protected AbstractInputCheckedMapDecorator(final Map<K, V> map) Constructor that wraps (not copies).
| |
| checkSetValue | back to summary |
|---|---|
| protected abstract V checkSetValue(V value) Hook method called when a value is being set using An implementation may validate the value and throw an exception or it may transform the value into another object. This implementation returns the input value.
| |
| entrySet | back to summary |
|---|---|
| public Set Overrides org. Implements java. Doc from java. Returns a | |
| isSetValueChecking | back to summary |
|---|---|
| protected boolean isSetValueChecking() Hook method called to determine if
An implementation should return false if the
This implementation returns
| |
| Modifier and Type | Field and Description |
|---|---|
| private final AbstractInputCheckedMapDecorator | parent
The parent map |
| private static final long | serialVersionUID
Hides org. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public Iterator | iterator()
Overrides org. Implements java. |
| public Object[] | toArray()
Overrides org. Implements java. |
| public <T> T[] | toArray(final T[]
the array into which the elements of this set are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is allocated for this purpose. array)Overrides org. Implements java. |
| parent | back to summary |
|---|---|
| private final AbstractInputCheckedMapDecorator<K, V> parent The parent map | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides org. Generated serial version ID. | |
| EntrySet | back to summary |
|---|---|
| protected EntrySet(final Set<Map. | |
| iterator | back to summary |
|---|---|
| public Iterator Overrides org. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee). | |
| toArray | back to summary |
|---|---|
| public Object[] toArray() Overrides org. Implements java. Doc from java. Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. The returned array will be "safe" in that no references to it are maintained by this set. (In other words, this method must allocate a new array even if this set is backed by an array). The caller is thus free to modify the returned array. This method acts as bridge between array-based and collection-based APIs.
| |
| toArray | back to summary |
|---|---|
| public <T> T[] toArray(final T[] array) Overrides org. Implements java. Doc from java. Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set. If this set fits in the specified array with room to spare
(i.e., the array has more elements than this set), the element in
the array immediately following the end of the set is set to
If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. Like the Suppose
String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to
toArray().
| |
| Modifier and Type | Field and Description |
|---|---|
| private final AbstractInputCheckedMapDecorator | parent
The parent map |
| Access | Constructor and Description |
|---|---|
| protected | EntrySetIterator(final Iterator<Map.
|
| Modifier and Type | Method and Description |
|---|---|
| public Map. | next()
Overrides org. Implements java. |
| parent | back to summary |
|---|---|
| private final AbstractInputCheckedMapDecorator<K, V> parent The parent map | |
| EntrySetIterator | back to summary |
|---|---|
| protected EntrySetIterator(final Iterator<Map. | |
| next | back to summary |
|---|---|
| public Map. Overrides org. Implements java. Doc from org. Returns the next element in the iteration.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final AbstractInputCheckedMapDecorator | parent
The parent map |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public V | setValue(V
new value to be stored in this entry value)Overrides org. Implements java. |
| parent | back to summary |
|---|---|
| private final AbstractInputCheckedMapDecorator<K, V> parent The parent map | |
| MapEntry | back to summary |
|---|---|
| protected MapEntry(final Map. | |
| setValue | back to summary |
|---|---|
| public V setValue(V value) Overrides org. Implements java. Doc from java. Replaces the value corresponding to this entry with the specified
value (optional operation). (Writes through to the map.) The
behavior of this call is undefined if the mapping has already been
removed from the map (by the iterator's
| |