Top Description Fields Constructors Methods
org.eclipse.collections.impl.map.sorted.mutable

public Class SortedMapAdapter<K, V>

extends AbstractMutableSortedMap<K, V>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.Comparator, .Iterator, .Map, .SortedMap, java.util.function.BiFunction, org.eclipse.collections.api.block.predicate.Predicate, org.eclipse.collections.api.block.procedure.Procedure2, org.eclipse.collections.api.collection.MutableCollection, org.eclipse.collections.api.factory.SortedMaps, org.eclipse.collections.api.list.MutableList, org.eclipse.collections.api.map.sorted.MutableSortedMap, org.eclipse.collections.api.partition.list.PartitionMutableList, org.eclipse.collections.api.set.MutableSet, org.eclipse.collections.api.tuple.Pair, org.eclipse.collections.impl.block.factory.Functions, org.eclipse.collections.impl.block.procedure.MapCollectProcedure, org.eclipse.collections.impl.collection.mutable.CollectionAdapter, org.eclipse.collections.impl.set.mutable.SetAdapter, org.eclipse.collections.impl.utility.ArrayIterate, .MapIterate

This class provides a MutableSortedMap wrapper around a JDK Collections SortedMap interface instance. All the MutableSortedMap interface methods are supported in addition to the JDK SortedMap interface methods.

To create a new wrapper around an existing SortedMap instance, use the adapt(SortedMap) factory method.

Field Summary

Modifier and TypeField and Description
private final SortedMap<K, V>
private static final long

Constructor Summary

AccessConstructor and Description
protected
SortedMapAdapter(SortedMap<K, V> newDelegate)

Method Summary

Modifier and TypeMethod and Description
public static <K, V> MutableSortedMap<K, V>
adapt(SortedMap<K, V> map)

public void
clear()

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).

public MutableSortedMap<K, V>
public Comparator<? super K>
comparator()

Implements org.eclipse.collections.api.map.sorted.SortedMapIterable.comparator, java.util.SortedMap.comparator.

Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.

public boolean
containsKey(Object key)

Implements org.eclipse.collections.api.map.MapIterable.containsKey, java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean
containsValue(Object value)

Implements org.eclipse.collections.api.map.MapIterable.containsValue, java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

public MutableList<V>
distinct()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.distinct.

Returns a new OrderedIterable containing the distinct elements in this iterable.

public MutableSortedMap<K, V>
drop(int count)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.drop.

Returns an iterable after skipping the first count elements or an empty iterable if the count is greater than the length of the iterable.

public MutableSortedMap<K, V>
dropWhile(Predicate<? super V> predicate)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.dropWhile.

Returns the final elements that do not satisfy the Predicate.

public MutableSet<Map.Entry<K, V>>
entrySet()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.entrySet, java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public boolean
public K
firstKey()

Implements java.util.SortedMap.firstKey.

Returns the first (lowest) key currently in this map.

public void
forEachKeyValue(Procedure2<? super K, ? super V> procedure)

Implements org.eclipse.collections.api.map.MapIterable.forEachKeyValue.

Calls the procedure with each key-value pair of the map.

public V
get(Object key)

Implements org.eclipse.collections.api.map.MapIterable.get, java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

public int
public MutableSortedMap<K, V>
headMap(K toKey)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.headMap.

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

public boolean
public Iterator<V>
public MutableSet<K>
keySet()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.keySet, java.util.Map.keySet.

The underlying set for the keys is sorted in ascending order according to their natural ordering or a custom comparator.

public K
lastKey()

Implements java.util.SortedMap.lastKey.

Returns the last (highest) key currently in this map.

public V
merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction)

Overrides default java.util.Map.merge.

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value (optional operation).

public MutableSortedMap<K, V>
newEmpty()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.newEmpty, org.eclipse.collections.api.map.MutableMapIterable.newEmpty.

Deprecated use TreeSortedMap#newEmpty() instead (inlineable)

Creates a new instance of the same type with the same internal Comparator.

public PartitionMutableList<V>
partitionWhile(Predicate<? super V> predicate)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.partitionWhile.

Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements.

public V
put(K key, V value)

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).

public void
putAll(Map<? extends K, ? extends V> map)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).

public V
remove(Object key)

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).

public V
removeKey(K key)

Implements org.eclipse.collections.api.map.MutableMapIterable.removeKey.

Remove an entry from the map at the specified key.

public int
size()

Implements org.eclipse.collections.api.RichIterable.size, java.util.Map.size.

Returns the number of key-value mappings in this map.

public MutableSortedMap<K, V>
subMap(K fromKey, K toKey)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.subMap.

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

public MutableSortedMap<K, V>
tailMap(K fromKey)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.tailMap.

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

public MutableSortedMap<K, V>
take(int count)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.take.

Returns the first count elements of the iterable or all the elements in the iterable if count is greater than the length of the iterable.

public MutableSortedMap<K, V>
takeWhile(Predicate<? super V> predicate)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.takeWhile.

Returns the initial elements that satisfy the Predicate.

public MutableSortedMap<K, V>
toReversed()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.toReversed.

Returns a new ReversibleIterable in reverse order.

public String
toString()

Overrides org.eclipse.collections.impl.AbstractRichIterable.toString.

Implements org.eclipse.collections.api.map.MapIterable.toString, org.eclipse.collections.api.RichIterable.toString.

Returns a string with the keys and values of this map separated by commas with spaces and enclosed in curly braces.

public MutableCollection<V>
values()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.values, java.util.Map.values.

Returns a Collection view of the values contained in this map.

public MutableSortedMap<K, V>
Inherited from org.eclipse.collections.impl.map.sorted.mutable.AbstractMutableSortedMap:
asSynchronizedasUnmodifiablecollectcollectBooleancollectBytecollectCharcollectDoublecollectFloatcollectIfcollectIntcollectKeysAndValuescollectKeysUniquecollectLongcollectShortcollectValuescollectWithcorrespondsdetectIndexdetectLastIndexflatCollectflipforEachforEachWithIndexgroupBygroupByEachgroupByUniqueKeypartitionpartitionWithrejectrejectrejectWithselectselectselectInstancesOfselectWithtaptoImmutabletoStackwithAllKeyValueArgumentswithAllKeyValueswithKeyValuewithoutAllKeyswithoutKeyzipzipWithIndex

Field Detail

delegateback to summary
private final SortedMap<K, V> delegate
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

SortedMapAdapterback to summary
protected SortedMapAdapter(SortedMap<K, V> newDelegate)

Method Detail

adaptback to summary
public static <K, V> MutableSortedMap<K, V> adapt(SortedMap<K, V> map)
clearback to summary
public void clear()

Implements java.util.Map.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
cloneback to summary
public MutableSortedMap<K, V> clone()

Implements abstract org.eclipse.collections.impl.map.sorted.mutable.AbstractMutableSortedMap.clone.

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Annotations
@Override
comparatorback to summary
public Comparator<? super K> comparator()

Implements org.eclipse.collections.api.map.sorted.SortedMapIterable.comparator, java.util.SortedMap.comparator.

Doc from java.util.SortedMap.comparator.

Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.

Annotations
@Override
containsKeyback to summary
public boolean containsKey(Object key)

Implements org.eclipse.collections.api.map.MapIterable.containsKey, java.util.Map.containsKey.

Doc from java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that Objects.equals(key, k). (There can be at most one such mapping.)

Annotations
@Override
containsValueback to summary
public boolean containsValue(Object value)

Implements org.eclipse.collections.api.map.MapIterable.containsValue, java.util.Map.containsValue.

Doc from java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that Objects.equals(value, v). This operation will probably require time linear in the map size for most implementations of the Map interface.

Annotations
@Override
distinctback to summary
public MutableList<V> distinct()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.distinct.

Doc from org.eclipse.collections.api.ordered.OrderedIterable.distinct.

Returns a new OrderedIterable containing the distinct elements in this iterable.

Conceptually similar to toSet().toList() but retains the original order. If an element appears multiple times in this iterable, the first one will be copied into the result.

Annotations
@Override
dropback to summary
public MutableSortedMap<K, V> drop(int count)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.drop.

Doc from org.eclipse.collections.api.ordered.ReversibleIterable.drop.

Returns an iterable after skipping the first count elements or an empty iterable if the count is greater than the length of the iterable.

Annotations
@Override
dropWhileback to summary
public MutableSortedMap<K, V> dropWhile(Predicate<? super V> predicate)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.dropWhile.

Doc from org.eclipse.collections.api.ordered.ReversibleIterable.dropWhile.

Returns the final elements that do not satisfy the Predicate. Short circuits at the first element which does satisfy the Predicate.

Annotations
@Override
entrySetback to summary
public MutableSet<Map.Entry<K, V>> entrySet()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.entrySet, java.util.Map.entrySet.

Doc from java.util.SortedMap.entrySet.

Returns a Set view of the mappings contained in this map. The set's iterator returns the entries in ascending key order. 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.

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Implements org.eclipse.collections.api.map.MapIterable.equals, java.util.Map.equals.

Doc from org.eclipse.collections.api.map.MapIterable.equals.

Follows the same general contract as Map#equals(Object).

Annotations
@Override
firstKeyback to summary
public K firstKey()

Implements java.util.SortedMap.firstKey.

Doc from java.util.SortedMap.firstKey.

Returns the first (lowest) key currently in this map.

Annotations
@Override
forEachKeyValueback to summary
public void forEachKeyValue(Procedure2<? super K, ? super V> procedure)

Implements org.eclipse.collections.api.map.MapIterable.forEachKeyValue.

Doc from org.eclipse.collections.api.map.MapIterable.forEachKeyValue.

Calls the procedure with each key-value pair of the map.

    final Collection<String> collection = new ArrayList<String>();
    MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three");
    map.forEachKeyValue((Integer key, String value) -> collection.add(String.valueOf(key) + value));
    Verify.assertContainsAll(collection, "1One", "2Two", "3Three");
Annotations
@Override
getback to summary
public V get(Object key)

Implements org.eclipse.collections.api.map.MapIterable.get, java.util.Map.get.

Doc from java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements org.eclipse.collections.api.map.MapIterable.hashCode, java.util.Map.hashCode.

Doc from org.eclipse.collections.api.map.MapIterable.hashCode.

Follows the same general contract as Map#hashCode().

Annotations
@Override
headMapback to summary
public MutableSortedMap<K, V> headMap(K toKey)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.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.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Overrides org.eclipse.collections.impl.AbstractRichIterable.isEmpty.

Implements org.eclipse.collections.api.RichIterable.isEmpty, java.util.Map.isEmpty.

Doc from java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

Annotations
@Override
iteratorback to summary
public Iterator<V> iterator()

Overrides org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable.iterator.

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

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

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.keySet, java.util.Map.keySet.

Doc from org.eclipse.collections.api.map.sorted.MutableSortedMap.keySet.

The underlying set for the keys is sorted in ascending order according to their natural ordering or a custom comparator. However, Java 5 TreeMap returns a keySet that does not inherit from SortedSet therefore we have decided to return the keySet simply as a MutableSet to maintain Java 5 compatibility.

Annotations
@Override
lastKeyback to summary
public K lastKey()

Implements java.util.SortedMap.lastKey.

Doc from java.util.SortedMap.lastKey.

Returns the last (highest) key currently in this map.

Annotations
@Override
mergeback to summary
public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction)

Overrides default java.util.Map.merge.

Doc from java.util.Map.merge.

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value (optional operation). Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null. This method may be of use when combining multiple mapped values for a key. For example, to either create or append a String msg to a value mapping:

 map.merge(key, msg, String::concat)

If the remapping function returns null, the mapping is removed. If the remapping function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.

The remapping function should not modify this map during computation.

Annotations
@Override
newEmptyback to summary
public MutableSortedMap<K, V> newEmpty()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.newEmpty, org.eclipse.collections.api.map.MutableMapIterable.newEmpty.

Doc from org.eclipse.collections.api.map.sorted.MutableSortedMap.newEmpty.

Deprecated

use TreeSortedMap#newEmpty() instead (inlineable)

Creates a new instance of the same type with the same internal Comparator.

Annotations
@Override
@Deprecated
partitionWhileback to summary
public PartitionMutableList<V> partitionWhile(Predicate<? super V> predicate)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.partitionWhile.

Doc from org.eclipse.collections.api.ordered.OrderedIterable.partitionWhile.

Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements. Short circuits at the first element which does satisfy the Predicate.

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

Implements java.util.Map.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.)

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

Implements java.util.Map.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.

Annotations
@Override
removeback to summary
public V remove(Object key)

Implements java.util.Map.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.

Annotations
@Override
removeKeyback to summary
public V removeKey(K key)

Implements org.eclipse.collections.api.map.MutableMapIterable.removeKey.

Doc from org.eclipse.collections.api.map.MutableMapIterable.removeKey.

Remove an entry from the map at the specified key.

Annotations
@Override
sizeback to summary
public int size()

Implements org.eclipse.collections.api.RichIterable.size, java.util.Map.size.

Doc from java.util.Map.size.

Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

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

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.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.

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

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.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.

Annotations
@Override
takeback to summary
public MutableSortedMap<K, V> take(int count)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.take.

Doc from org.eclipse.collections.api.ordered.ReversibleIterable.take.

Returns the first count elements of the iterable or all the elements in the iterable if count is greater than the length of the iterable.

Annotations
@Override
takeWhileback to summary
public MutableSortedMap<K, V> takeWhile(Predicate<? super V> predicate)

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.takeWhile.

Doc from org.eclipse.collections.api.ordered.ReversibleIterable.takeWhile.

Returns the initial elements that satisfy the Predicate. Short circuits at the first element which does not satisfy the Predicate.

Annotations
@Override
toReversedback to summary
public MutableSortedMap<K, V> toReversed()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.toReversed.

Doc from org.eclipse.collections.api.ordered.ReversibleIterable.toReversed.

Returns a new ReversibleIterable in reverse order.

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.eclipse.collections.impl.AbstractRichIterable.toString.

Implements org.eclipse.collections.api.map.MapIterable.toString, org.eclipse.collections.api.RichIterable.toString.

Doc from org.eclipse.collections.api.map.MapIterable.toString.

Returns a string with the keys and values of this map separated by commas with spaces and enclosed in curly braces. Each key and value is separated by an equals sign.

Assert.assertEquals("{1=1, 2=2, 3=3}", Maps.mutable.with(1, 1, 2, 2, 3, 3).toString());
Annotations
@Override
valuesback to summary
public MutableCollection<V> values()

Implements org.eclipse.collections.api.map.sorted.MutableSortedMap.values, java.util.Map.values.

Doc from java.util.SortedMap.values.

Returns a Collection view of the values contained in this map. The collection's iterator returns the values in ascending order of the corresponding keys. 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.

Annotations
@Override
withback to summary
public MutableSortedMap<K, V> with(Pair<K, V>... pairs)

Overrides default org.eclipse.collections.api.map.sorted.MutableSortedMap.with.

Annotations
@Override