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

public Class FixedSizeSortedMap<K, V>

extends AbstractSortedMapDecorator<K, V>
implements BoundedMap<K, V>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.collections4.BoundedMap, org.apache.commons.collections4.IterableMap, org.apache.commons.collections4.IterableGet, org.apache.commons.collections4.Get, org.apache.commons.collections4.Put, java.util.Map
Type Parameters
<K>
the type of the keys in this map
<V>
the type of the values in this map
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.util.Collection, .Map, .Set, .SortedMap, org.apache.commons.collections4.BoundedMap, .CollectionUtils, org.apache.commons.collections4.collection.UnmodifiableCollection, org.apache.commons.collections4.set.UnmodifiableSet

Decorates another SortedMap to fix the size blocking add/remove.

Any action that would change the size of the map is disallowed. The put method is allowed to change the value associated with an existing key however.

If trying to remove or clear the map, an UnsupportedOperationException is thrown. If trying to put a new mapping into the map, an IllegalArgumentException is thrown. This is because the put method can succeed if the mapping's key already exists in the map, so the put method is not always unsupported.

Note that FixedSizeSortedMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. The simplest approach is to wrap this map using java.util.Collections#synchronizedSortedMap. This class may throw exceptions when accessed by concurrent threads without synchronization.

This class is Serializable from Commons Collections 3.1.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Serialization version

Constructor Summary

AccessConstructor and Description
protected
FixedSizeSortedMap(final SortedMap<K, V>
the map to decorate, must not be null
map
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public void
clear()

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

Implements java.util.Map.clear, org.apache.commons.collections4.Put.clear.

Removes all of the mappings from this map (optional operation).
public Set<Map.Entry<K, V>>
public static <
the key type
K
,
the value type
V
>
FixedSizeSortedMap<K, V>

Returns:

a new fixed size sorted map
fixedSizeSortedMap
(final SortedMap<K, V>
the map to decorate, must not be null
map
)

Factory method to create a fixed size sorted map.

protected SortedMap<K, V>

Returns:

the decorated map
getSortedMap
()

Gets the map being decorated.

public SortedMap<K, V>
headMap(final K
high endpoint (exclusive) of the keys in the returned map
toKey
)

Overrides org.apache.commons.collections4.map.AbstractSortedMapDecorator.headMap.

Implements java.util.SortedMap.headMap.

Returns a view of the portion of this map whose keys are strictly less than toKey.
public boolean
isFull()

Implements org.apache.commons.collections4.BoundedMap.isFull.

Returns true if this map is full and no new elements can be added.
public Set<K>
public int
maxSize()

Implements org.apache.commons.collections4.BoundedMap.maxSize.

Gets the maximum size of the map (the bound).
public V
put(final K
key with which the specified value is to be associated
key
,
final V
value to be associated with the specified key
value
)

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

Implements java.util.Map.put, org.apache.commons.collections4.Put.put.

Associates the specified value with the specified key in this map (optional operation).
public void
putAll(final Map<? extends K, ? extends V>
mappings to be stored in this map
mapToCopy
)

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

Implements java.util.Map.putAll, org.apache.commons.collections4.Put.putAll.

Copies all of the mappings from the specified map to this map (optional operation).
private void
readObject(final ObjectInputStream
the input stream
in
)

Read the map in using a custom routine.

public V
remove(final Object
key whose mapping is to be removed from the map
key
)

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

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

Removes the mapping for a key from this map if it is present (optional operation).
public SortedMap<K, V>
subMap(final K
low endpoint (inclusive) of the keys in the returned map
fromKey
,
final K
high endpoint (exclusive) of the keys in the returned map
toKey
)

Overrides org.apache.commons.collections4.map.AbstractSortedMapDecorator.subMap.

Implements java.util.SortedMap.subMap.

Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive.
public SortedMap<K, V>
tailMap(final K
low endpoint (inclusive) of the keys in the returned map
fromKey
)

Overrides org.apache.commons.collections4.map.AbstractSortedMapDecorator.tailMap.

Implements java.util.SortedMap.tailMap.

Returns a view of the portion of this map whose keys are greater than or equal to fromKey.
public Collection<V>
private void
writeObject(final ObjectOutputStream
the output stream
out
)

Write the map out using a custom routine.

Inherited from org.apache.commons.collections4.map.AbstractSortedMapDecorator:
comparatordecoratedfirstKeylastKeymapIteratornextKeypreviousKey

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version

Constructor Detail

FixedSizeSortedMapback to summary
protected FixedSizeSortedMap(final SortedMap<K, V> map)

Constructor that wraps (not copies).

Parameters
map:SortedMap<K, V>

the map to decorate, must not be null

Exceptions
NullPointerException:
if map is null

Method Detail

clearback to summary
public void clear()

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

Implements java.util.Map.clear, org.apache.commons.collections4.Put.clear.

Doc from java.util.Map.clear.

Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.

Annotations
@Override
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, java.util.SortedMap.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
fixedSizeSortedMapback to summary
public static <K, V> FixedSizeSortedMap<K, V> fixedSizeSortedMap(final SortedMap<K, V> map)

Factory method to create a fixed size sorted map.

Parameters
<K>
the key type
<V>
the value type
map:SortedMap<K, V>

the map to decorate, must not be null

Returns:FixedSizeSortedMap<K, V>

a new fixed size sorted map

Exceptions
NullPointerException:
if map is null
Since
4.0
getSortedMapback to summary
protected SortedMap<K, V> getSortedMap()

Gets the map being decorated.

Returns:SortedMap<K, V>

the decorated map

headMapback to summary
public SortedMap<K, V> headMap(final K toKey)

Overrides org.apache.commons.collections4.map.AbstractSortedMapDecorator.headMap.

Implements java.util.SortedMap.headMap.

Doc from java.util.SortedMap.headMap.

Returns a view of the portion of this map whose keys are strictly less than toKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

Parameters
toKey:K

high endpoint (exclusive) of the keys in the returned map

Returns:SortedMap<K, V>

a view of the portion of this map whose keys are strictly less than toKey

Annotations
@Override
isFullback to summary
public boolean isFull()

Implements org.apache.commons.collections4.BoundedMap.isFull.

Doc from org.apache.commons.collections4.BoundedMap.isFull.

Returns true if this map is full and no new elements can be added.

Returns:boolean

true if the map is full

Annotations
@Override
keySetback to summary
public Set<K> keySet()

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

Implements java.util.Map.keySet, org.apache.commons.collections4.Get.keySet, java.util.SortedMap.keySet.

Doc from java.util.Map.keySet.

Returns a Set view of the keys 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), 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<K>

a set view of the keys contained in this map

Annotations
@Override
maxSizeback to summary
public int maxSize()

Implements org.apache.commons.collections4.BoundedMap.maxSize.

Doc from org.apache.commons.collections4.BoundedMap.maxSize.

Gets the maximum size of the map (the bound).

Returns:int

the maximum number of elements the map can hold

Annotations
@Override
putback to summary
public V put(final K key, final V value)

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

Implements java.util.Map.put, org.apache.commons.collections4.Put.put.

Doc from java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters
key:K

key with which the specified value is to be associated

value:V

value to be associated with the specified key

Returns:V

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

Annotations
@Override
putAllback to summary
public void putAll(final Map<? extends K, ? extends V> mapToCopy)

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

Implements java.util.Map.putAll, org.apache.commons.collections4.Put.putAll.

Doc from java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. If the specified map has a defined encounter order, processing of its mappings generally occurs in that order.

Parameters
mapToCopy:Map<? extends K, ? extends V>

mappings to be stored in this map

Annotations
@Override
readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException

Read the map in using a custom routine.

Parameters
in:ObjectInputStream

the input stream

Annotations
@SuppressWarnings:unchecked
Exceptions
IOException:
if an error occurs while reading from the stream
ClassNotFoundException:
if an object read from the stream can not be loaded
removeback to summary
public V remove(final Object key)

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

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

Doc from java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that Objects.equals(key, k), that mapping is removed. (The map can contain at most one such mapping.)

Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.

If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.

The map will not contain a mapping for the specified key once the call returns.

Parameters
key:Object

key whose mapping is to be removed from the map

Returns:V

the previous value associated with key, or null if there was no mapping for key.

Annotations
@Override
subMapback to summary
public SortedMap<K, V> subMap(final K fromKey, final K toKey)

Overrides org.apache.commons.collections4.map.AbstractSortedMapDecorator.subMap.

Implements java.util.SortedMap.subMap.

Doc from java.util.SortedMap.subMap.

Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive. (If fromKey and toKey are equal, the returned map is empty.) The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

Parameters
fromKey:K

low endpoint (inclusive) of the keys in the returned map

toKey:K

high endpoint (exclusive) of the keys in the returned map

Returns:SortedMap<K, V>

a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive

Annotations
@Override
tailMapback to summary
public SortedMap<K, V> tailMap(final K fromKey)

Overrides org.apache.commons.collections4.map.AbstractSortedMapDecorator.tailMap.

Implements java.util.SortedMap.tailMap.

Doc from java.util.SortedMap.tailMap.

Returns a view of the portion of this map whose keys are greater than or equal to fromKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

Parameters
fromKey:K

low endpoint (inclusive) of the keys in the returned map

Returns:SortedMap<K, V>

a view of the portion of this map whose keys are greater than or equal to fromKey

Annotations
@Override
valuesback to summary
public Collection<V> values()

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

Implements java.util.Map.values, org.apache.commons.collections4.Get.values, java.util.SortedMap.values.

Doc from java.util.Map.values.

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

Returns:Collection<V>

a collection view of the values contained in this map

Annotations
@Override
writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException

Write the map out using a custom routine.

Parameters
out:ObjectOutputStream

the output stream

Exceptions
IOException:
if an error occurs while writing to the stream