Top Description Inners Fields Constructors Methods
org.apache.commons.collections4.map

pack-priv abstract Class AbstractInputCheckedMapDecorator<K, V>

extends AbstractMapDecorator<K, V>
Class Inheritance
Known Direct Subclasses
org.apache.commons.collections4.map.PredicatedMap, org.apache.commons.collections4.map.TransformedMap
Imports
java.lang.reflect.Array, java.util.Iterator, .Map, .Set, org.apache.commons.collections4.iterators.AbstractIteratorDecorator, org.apache.commons.collections4.keyvalue.AbstractMapEntryDecorator, org.apache.commons.collections4.set.AbstractSetDecorator

An abstract base class that simplifies the task of creating map decorators.

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.

Since
3.1

Nested and Inner Type Summary

Modifier and TypeClass 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.

Field Summary

Inherited from org.apache.commons.collections4.map.AbstractMapDecorator:
map

Constructor Summary

AccessConstructor and Description
protected
AbstractInputCheckedMapDecorator()

Constructor only used in deserialization, do not use otherwise.

protected
AbstractInputCheckedMapDecorator(final Map<K, V>
the map to decorate, must not be null
map
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
protected abstract V

Returns:

the input value
checkSetValue
(V
the value to check
value
)

Hook method called when a value is being set using setValue.

public Set<Map.Entry<K, V>>
protected boolean

Returns:

true always
isSetValueChecking
()

Hook method called to determine if checkSetValue has any effect.

Inherited from org.apache.commons.collections4.map.AbstractMapDecorator:
clearcontainsKeycontainsValuedecoratedequalsgethashCodeisEmptykeySetputputAllremovesizetoStringvalues

Constructor Detail

AbstractInputCheckedMapDecoratorback to summary
protected AbstractInputCheckedMapDecorator()

Constructor only used in deserialization, do not use otherwise.

AbstractInputCheckedMapDecoratorback to summary
protected AbstractInputCheckedMapDecorator(final Map<K, V> map)

Constructor that wraps (not copies).

Parameters
map:Map<K, V>

the map to decorate, must not be null

Exceptions
NullPointerException:
if map is null

Method Detail

checkSetValueback to summary
protected abstract V checkSetValue(V value)

Hook method called when a value is being set using setValue.

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.

Parameters
value:V

the value to check

Returns:V

the input value

Exceptions
UnsupportedOperationException:
if the map may not be changed by setValue
IllegalArgumentException:
if the specified value is invalid
ClassCastException:
if the class of the specified value is invalid
NullPointerException:
if the specified value is null and nulls are invalid
entrySetback to summary
public Set<Map.Entry<K, V>> entrySet()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.entrySet.

Implements java.util.Map.entrySet, org.apache.commons.collections4.Get.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<Map.Entry<K, V>>

a set view of the mappings contained in this map

Annotations
@Override
isSetValueCheckingback to summary
protected boolean isSetValueChecking()

Hook method called to determine if checkSetValue has any effect.

An implementation should return false if the checkSetValue method has no effect as this optimises the implementation.

This implementation returns true.

Returns:boolean

true always

org.apache.commons.collections4.map back to summary

private Class AbstractInputCheckedMapDecorator.EntrySet

extends AbstractSetDecorator<Map.Entry<K, V>>
Class Inheritance

Implementation of an entry set that checks additions via setValue.

Field Summary

Modifier and TypeField and Description
private final AbstractInputCheckedMapDecorator<K, V>
parent

The parent map

private static final long

Constructor Summary

AccessConstructor and Description
protected
EntrySet(final Set<Map.Entry<K, V>> set, final AbstractInputCheckedMapDecorator<K, V> parent)

Method Summary

Modifier and TypeMethod and Description
public Iterator<Map.Entry<K, V>>
public Object[]
toArray()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Returns an array containing all of the elements in this set.
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.apache.commons.collections4.collection.AbstractCollectionDecorator.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.
Inherited from org.apache.commons.collections4.set.AbstractSetDecorator:
decoratedequalshashCode

Field Detail

parentback to summary
private final AbstractInputCheckedMapDecorator<K, V> parent

The parent map

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.set.AbstractSetDecorator.serialVersionUID.

Generated serial version ID.

Constructor Detail

EntrySetback to summary
protected EntrySet(final Set<Map.Entry<K, V>> set, final AbstractInputCheckedMapDecorator<K, V> parent)

Method Detail

iteratorback to summary
public Iterator<Map.Entry<K, V>> iterator()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.iterator.

Implements java.util.Set.iterator, java.util.Collection.iterator.

Doc from java.util.Set.iterator.

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).

Returns:Iterator<Map.Entry<K, V>>

an iterator over the elements in this set

Annotations
@Override
toArrayback to summary
public Object[] toArray()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Doc from java.util.Set.toArray.

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.

Returns:Object[]

an array containing all the elements in this set

Annotations
@Override
@SuppressWarnings:unchecked
toArrayback to summary
public <T> T[] toArray(final T[] array)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.toArray.

Implements java.util.Set.toArray, java.util.Collection.toArray.

Doc from java.util.Set.toArray.

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 null. (This is useful in determining the length of this set only if the caller knows that this set does not contain any null elements.)

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 toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

Suppose x is a set known to contain only strings. The following code can be used to dump the set into a newly allocated array of String:

    String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to toArray().
Parameters
<T>

Doc from java.util.Collection.toArray. the component type of the array to contain the collection

array: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.

Returns:T[]

an array containing all the elements in this set

Annotations
@Override
@SuppressWarnings:unchecked
org.apache.commons.collections4.map back to summary

private Class AbstractInputCheckedMapDecorator.EntrySetIterator

extends AbstractIteratorDecorator<Map.Entry<K, V>>
Class Inheritance

Implementation of an entry set iterator that checks additions via setValue.

Field Summary

Modifier and TypeField and Description
private final AbstractInputCheckedMapDecorator<K, V>
parent

The parent map

Constructor Summary

AccessConstructor and Description
protected
EntrySetIterator(final Iterator<Map.Entry<K, V>> iterator, final AbstractInputCheckedMapDecorator<K, V> parent)

Method Summary

Modifier and TypeMethod and Description
public Map.Entry<K, V>
next()

Overrides org.apache.commons.collections4.iterators.AbstractIteratorDecorator.next.

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Field Detail

parentback to summary
private final AbstractInputCheckedMapDecorator<K, V> parent

The parent map

Constructor Detail

EntrySetIteratorback to summary
protected EntrySetIterator(final Iterator<Map.Entry<K, V>> iterator, final AbstractInputCheckedMapDecorator<K, V> parent)

Method Detail

nextback to summary
public Map.Entry<K, V> next()

Overrides org.apache.commons.collections4.iterators.AbstractIteratorDecorator.next.

Implements java.util.Iterator.next.

Doc from org.apache.commons.collections4.iterators.AbstractIteratorDecorator.next.

Returns the next element in the iteration.

Returns:Map.Entry<K, V>

Doc from java.util.Iterator.next.

the next element in the iteration

Annotations
@Override
org.apache.commons.collections4.map back to summary

private Class AbstractInputCheckedMapDecorator.MapEntry

extends AbstractMapEntryDecorator<K, V>
Class Inheritance

Implementation of a map entry that checks additions via setValue.

Field Summary

Modifier and TypeField and Description
private final AbstractInputCheckedMapDecorator<K, V>
parent

The parent map

Constructor Summary

AccessConstructor and Description
protected
MapEntry(final Map.Entry<K, V> entry, final AbstractInputCheckedMapDecorator<K, V> parent)

Method Summary

Modifier and TypeMethod and Description
public V
setValue(V
new value to be stored in this entry
value
)

Overrides org.apache.commons.collections4.keyvalue.AbstractMapEntryDecorator.setValue.

Implements java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation).
Inherited from org.apache.commons.collections4.keyvalue.AbstractMapEntryDecorator:
equalsgetKeygetMapEntrygetValuehashCodetoString

Field Detail

parentback to summary
private final AbstractInputCheckedMapDecorator<K, V> parent

The parent map

Constructor Detail

MapEntryback to summary
protected MapEntry(final Map.Entry<K, V> entry, final AbstractInputCheckedMapDecorator<K, V> parent)

Method Detail

setValueback to summary
public V setValue(V value)

Overrides org.apache.commons.collections4.keyvalue.AbstractMapEntryDecorator.setValue.

Implements java.util.Map.Entry.setValue.

Doc from java.util.Map.Entry.setValue.

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 remove operation).

Parameters
value:V

new value to be stored in this entry

Returns:V

old value corresponding to the entry

Annotations
@Override