Class SortedMapAdapter<K,V>
- java.lang.Object
-
- org.eclipse.collections.impl.AbstractRichIterable<V>
-
- org.eclipse.collections.impl.map.AbstractMapIterable<K,V>
-
- org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable<K,V>
-
- org.eclipse.collections.impl.map.sorted.mutable.AbstractMutableSortedMap<K,V>
-
- org.eclipse.collections.impl.map.sorted.mutable.SortedMapAdapter<K,V>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<V>,java.util.Map<K,V>,java.util.SortedMap<K,V>,InternalIterable<V>,MapIterable<K,V>,MutableMapIterable<K,V>,MutableSortedMap<K,V>,SortedMapIterable<K,V>,OrderedIterable<V>,ReversibleIterable<V>,RichIterable<V>
public class SortedMapAdapter<K,V> extends AbstractMutableSortedMap<K,V> implements java.io.Serializable
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.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.SortedMap<K,V>delegateprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description protectedSortedMapAdapter(java.util.SortedMap<K,V> newDelegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <K,V>
MutableSortedMap<K,V>adapt(java.util.SortedMap<K,V> map)voidclear()MutableSortedMap<K,V>clone()java.util.Comparator<? super K>comparator()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)MutableList<V>distinct()Returns a newOrderedIterablecontaining the distinct elements in this iterable.MutableSortedMap<K,V>drop(int count)Returns an iterable after skipping the firstcountelements or an empty iterable if thecountis greater than the length of the iterable.MutableSortedMap<K,V>dropWhile(Predicate<? super V> predicate)Returns the final elements that do not satisfy the Predicate.MutableSet<java.util.Map.Entry<K,V>>entrySet()booleanequals(java.lang.Object o)Follows the same general contract asMap.equals(Object).KfirstKey()voidforEachKeyValue(Procedure2<? super K,? super V> procedure)Calls theprocedurewith each key-value pair of the map.Vget(java.lang.Object key)inthashCode()Follows the same general contract asMap.hashCode().MutableSortedMap<K,V>headMap(K toKey)booleanisEmpty()Returns true if this iterable has zero items.java.util.Iterator<V>iterator()MutableSet<K>keySet()The underlying set for the keys is sorted in ascending order according to their natural ordering or a custom comparator.KlastKey()Vmerge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)MutableSortedMap<K,V>newEmpty()Deprecated.useTreeSortedMap.newEmpty()instead (inlineable)PartitionMutableList<V>partitionWhile(Predicate<? super V> predicate)Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements.Vput(K key, V value)voidputAll(java.util.Map<? extends K,? extends V> map)Vremove(java.lang.Object key)VremoveKey(K key)Remove an entry from the map at the specifiedkey.intsize()Returns the number of items in this iterable.MutableSortedMap<K,V>subMap(K fromKey, K toKey)MutableSortedMap<K,V>tailMap(K fromKey)MutableSortedMap<K,V>take(int count)Returns the firstcountelements of the iterable or all the elements in the iterable ifcountis greater than the length of the iterable.MutableSortedMap<K,V>takeWhile(Predicate<? super V> predicate)Returns the initial elements that satisfy the Predicate.MutableSortedMap<K,V>toReversed()Returns a new ReversibleIterable in reverse order.java.lang.StringtoString()Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.MutableCollection<V>values()MutableSortedMap<K,V>with(Pair<K,V>... pairs)-
Methods inherited from class org.eclipse.collections.impl.map.sorted.mutable.AbstractMutableSortedMap
asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectKeysAndValues, collectKeysUnique, collectLong, collectShort, collectValues, collectWith, corresponds, detectIndex, detectLastIndex, flatCollect, flip, forEach, forEachWithIndex, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, reject, rejectWith, select, select, selectInstancesOf, selectWith, tap, toImmutable, toStack, withAllKeyValueArguments, withAllKeyValues, withKeyValue, withoutAllKeys, withoutKey, zip, zipWithIndex
-
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable
aggregateBy, collect, countBy, countByEach, countByWith, detect, detectOptional, flipUniqueValues, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, keysView, keyValuesView, reduceBy, sumByDouble, sumByFloat, sumByInt, sumByLong, updateValue, updateValueWith, valuesView
-
Methods inherited from class org.eclipse.collections.impl.map.AbstractMapIterable
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, asLazy, chunk, contains, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, forEachKey, forEachValue, forEachWith, forEachWithIndex, getFirst, getIfAbsent, getIfAbsentValue, getIfAbsentWith, getLast, getOnly, getOrDefault, ifPresentApply, isAbsent, keyAndValueEquals, keyAndValueHashCode, noneSatisfy, noneSatisfyWith, toArray, toArray
-
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, collect, collectIf, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countWith, flatCollect, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, max, max, maxBy, min, min, minBy, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toBiMap, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach, forEachWith
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, putIfAbsent, remove, replace, replace, replaceAll
-
Methods inherited from interface org.eclipse.collections.api.map.MapIterable
detect, detectOptional, forEachKey, forEachValue, getIfAbsent, getIfAbsentValue, getIfAbsentWith, ifPresentApply, injectIntoKeyValue, keysView, keyValuesView, parallelStream, spliterator, stream, valuesView
-
Methods inherited from interface org.eclipse.collections.api.map.MutableMapIterable
add, aggregateBy, aggregateBy, aggregateInPlaceBy, countBy, countByEach, countByWith, flipUniqueValues, forEach, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWithKey, getOrDefault, putAllMapIterable, putPair, reduceBy, removeAllKeys, removeIf, sumByDouble, sumByFloat, sumByInt, sumByLong, updateValue, updateValueWith
-
Methods inherited from interface org.eclipse.collections.api.map.sorted.MutableSortedMap
collect, collectWithIndex, flatCollectWith, getIfAbsentPutWith, withMap, withMapIterable
-
Methods inherited from interface org.eclipse.collections.api.ordered.OrderedIterable
collectWithIndex, forEachWithIndex, getFirst, getFirstOptional, getLast, getLastOptional, indexOf, max, min, rejectWithIndex, selectWithIndex, zip, zipWithIndex
-
Methods inherited from interface org.eclipse.collections.api.ordered.ReversibleIterable
asReversed, reverseForEach, reverseForEachWithIndex
-
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, makeString, makeString, makeString, makeString, max, maxBy, maxByOptional, maxOptional, maxOptional, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reduceBy, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
adapt
public static <K,V> MutableSortedMap<K,V> adapt(java.util.SortedMap<K,V> map)
-
forEachKeyValue
public void forEachKeyValue(Procedure2<? super K,? super V> procedure)
Description copied from interface:MapIterableCalls theprocedurewith 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");- Specified by:
forEachKeyValuein interfaceMapIterable<K,V>
-
newEmpty
@Deprecated public MutableSortedMap<K,V> newEmpty()
Deprecated.useTreeSortedMap.newEmpty()instead (inlineable)Description copied from interface:MutableSortedMapCreates a new instance of the same type with the same internal Comparator.- Specified by:
newEmptyin interfaceMutableMapIterable<K,V>- Specified by:
newEmptyin interfaceMutableSortedMap<K,V>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKeyin interfacejava.util.Map<K,V>- Specified by:
containsKeyin interfaceMapIterable<K,V>- See Also:
Map.containsKey(Object)
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValuein interfacejava.util.Map<K,V>- Specified by:
containsValuein interfaceMapIterable<K,V>- See Also:
Map.containsValue(Object)
-
comparator
public java.util.Comparator<? super K> comparator()
- Specified by:
comparatorin interfacejava.util.SortedMap<K,V>- Specified by:
comparatorin interfaceSortedMapIterable<K,V>
-
size
public int size()
Description copied from interface:RichIterableReturns the number of items in this iterable.- Specified by:
sizein interfacejava.util.Map<K,V>- Specified by:
sizein interfaceRichIterable<K>
-
isEmpty
public boolean isEmpty()
Description copied from interface:RichIterableReturns true if this iterable has zero items.- Specified by:
isEmptyin interfacejava.util.Map<K,V>- Specified by:
isEmptyin interfaceRichIterable<K>- Overrides:
isEmptyin classAbstractRichIterable<V>
-
iterator
public java.util.Iterator<V> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<K>- Overrides:
iteratorin classAbstractMutableMapIterable<K,V>
-
values
public MutableCollection<V> values()
-
entrySet
public MutableSet<java.util.Map.Entry<K,V>> entrySet()
-
keySet
public MutableSet<K> keySet()
Description copied from interface:MutableSortedMapThe 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.
-
headMap
public MutableSortedMap<K,V> headMap(K toKey)
-
tailMap
public MutableSortedMap<K,V> tailMap(K fromKey)
-
subMap
public MutableSortedMap<K,V> subMap(K fromKey, K toKey)
-
get
public V get(java.lang.Object key)
-
merge
public V merge(K key, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
-
removeKey
public V removeKey(K key)
Description copied from interface:MutableMapIterableRemove an entry from the map at the specifiedkey.- Specified by:
removeKeyin interfaceMutableMapIterable<K,V>- Returns:
- The value removed from entry at key, or null if not found.
- See Also:
Map.remove(Object)
-
with
public MutableSortedMap<K,V> with(Pair<K,V>... pairs)
- Specified by:
within interfaceMutableSortedMap<K,V>
-
toString
public java.lang.String toString()
Description copied from class:AbstractRichIterableReturns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.Assert.assertEquals("[]", Lists.mutable.empty().toString()); Assert.assertEquals("[1]", Lists.mutable.with(1).toString()); Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());- Specified by:
toStringin interfaceMapIterable<K,V>- Specified by:
toStringin interfaceRichIterable<K>- Overrides:
toStringin classAbstractRichIterable<V>- Returns:
- a string representation of this collection.
- See Also:
AbstractCollection.toString()
-
clone
public MutableSortedMap<K,V> clone()
- Specified by:
clonein interfaceMutableSortedMap<K,V>- Specified by:
clonein classAbstractMutableSortedMap<K,V>
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:MapIterableFollows the same general contract asMap.equals(Object).
-
hashCode
public int hashCode()
Description copied from interface:MapIterableFollows the same general contract asMap.hashCode().
-
toReversed
public MutableSortedMap<K,V> toReversed()
Description copied from interface:ReversibleIterableReturns a new ReversibleIterable in reverse order.- Specified by:
toReversedin interfaceMutableSortedMap<K,V>- Specified by:
toReversedin interfaceReversibleIterable<K>- Specified by:
toReversedin interfaceSortedMapIterable<K,V>
-
take
public MutableSortedMap<K,V> take(int count)
Description copied from interface:ReversibleIterableReturns the firstcountelements of the iterable or all the elements in the iterable ifcountis greater than the length of the iterable.- Specified by:
takein interfaceMutableSortedMap<K,V>- Specified by:
takein interfaceReversibleIterable<K>- Specified by:
takein interfaceSortedMapIterable<K,V>- Parameters:
count- the number of items to take.
-
takeWhile
public MutableSortedMap<K,V> takeWhile(Predicate<? super V> predicate)
Description copied from interface:ReversibleIterableReturns the initial elements that satisfy the Predicate. Short circuits at the first element which does not satisfy the Predicate.- Specified by:
takeWhilein interfaceMutableSortedMap<K,V>- Specified by:
takeWhilein interfaceOrderedIterable<K>- Specified by:
takeWhilein interfaceReversibleIterable<K>- Specified by:
takeWhilein interfaceSortedMapIterable<K,V>
-
drop
public MutableSortedMap<K,V> drop(int count)
Description copied from interface:ReversibleIterableReturns an iterable after skipping the firstcountelements or an empty iterable if thecountis greater than the length of the iterable.- Specified by:
dropin interfaceMutableSortedMap<K,V>- Specified by:
dropin interfaceReversibleIterable<K>- Specified by:
dropin interfaceSortedMapIterable<K,V>- Parameters:
count- the number of items to drop.
-
dropWhile
public MutableSortedMap<K,V> dropWhile(Predicate<? super V> predicate)
Description copied from interface:ReversibleIterableReturns the final elements that do not satisfy the Predicate. Short circuits at the first element which does satisfy the Predicate.- Specified by:
dropWhilein interfaceMutableSortedMap<K,V>- Specified by:
dropWhilein interfaceOrderedIterable<K>- Specified by:
dropWhilein interfaceReversibleIterable<K>- Specified by:
dropWhilein interfaceSortedMapIterable<K,V>
-
partitionWhile
public PartitionMutableList<V> partitionWhile(Predicate<? super V> predicate)
Description copied from interface:OrderedIterableReturns 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.- Specified by:
partitionWhilein interfaceMutableSortedMap<K,V>- Specified by:
partitionWhilein interfaceOrderedIterable<K>- Specified by:
partitionWhilein interfaceReversibleIterable<K>- Specified by:
partitionWhilein interfaceSortedMapIterable<K,V>
-
distinct
public MutableList<V> distinct()
Description copied from interface:OrderedIterableReturns a newOrderedIterablecontaining the distinct elements in this iterable.Conceptually similar to
RichIterable.toSet().RichIterable.toList()but retains the original order. If an element appears multiple times in this iterable, the first one will be copied into the result.- Specified by:
distinctin interfaceMutableSortedMap<K,V>- Specified by:
distinctin interfaceOrderedIterable<K>- Specified by:
distinctin interfaceReversibleIterable<K>- Specified by:
distinctin interfaceSortedMapIterable<K,V>- Returns:
OrderedIterableof distinct elements
-
-