Class ImmutableUnifiedMap<K,V>
java.lang.Object
org.eclipse.collections.impl.AbstractRichIterable<V>
org.eclipse.collections.impl.map.AbstractMapIterable<K,V>
org.eclipse.collections.impl.map.immutable.AbstractImmutableMap<K,V>
org.eclipse.collections.impl.map.immutable.ImmutableUnifiedMap<K,V>
- All Implemented Interfaces:
Serializable
,Iterable<V>
,Map<K,V>
,InternalIterable<V>
,ImmutableMap<K,V>
,ImmutableMapIterable<K,V>
,MapIterable<K,V>
,UnsortedMapIterable<K,V>
,RichIterable<V>
,BatchIterable<V>
public class ImmutableUnifiedMap<K,V> extends AbstractImmutableMap<K,V> implements BatchIterable<V>, Serializable
- See Also:
ImmutableMap
, Serialized Form
-
Nested Class Summary
-
Constructor Summary
Constructors Constructor Description ImmutableUnifiedMap(Map<K,V> delegate)
ImmutableUnifiedMap(Pair<K,V>... pairs)
-
Method Summary
Modifier and Type Method Description void
batchForEach(Procedure<? super V> procedure, int sectionIndex, int sectionCount)
boolean
containsKey(Object key)
boolean
containsValue(Object value)
boolean
equals(Object o)
Follows the same general contract asMap.equals(Object)
.void
forEachKey(Procedure<? super K> procedure)
Calls theprocedure
with each key of the map.void
forEachKeyValue(Procedure2<? super K,? super V> procedure)
Calls theprocedure
with each key-value pair of the map.void
forEachValue(Procedure<? super V> procedure)
Calls the procedure with each value of the map.<P> void
forEachWith(Procedure2<? super V,? super P> procedure, P parameter)
The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.void
forEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)
Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.V
get(Object key)
int
getBatchCount(int batchSize)
V
getIfAbsent(K key, Function0<? extends V> function)
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified Function0.V
getIfAbsentValue(K key, V value)
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, returnvalue
.<P> V
getIfAbsentWith(K key, Function<? super P,? extends V> function, P parameter)
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified function and parameter.int
hashCode()
Follows the same general contract asMap.hashCode()
.<A> A
ifPresentApply(K key, Function<? super V,? extends A> function)
If there is a value in the Map that corresponds to the specified key return the result of applying the specified Function on the value, otherwise return null.Set<K>
keySet()
RichIterable<K>
keysView()
Returns an unmodifiable lazy iterable wrapped around the keySet for the map.RichIterable<Pair<K,V>>
keyValuesView()
Returns an unmodifiable lazy iterable of key/value pairs wrapped around the entrySet for the map.int
size()
Returns the number of items in this iterable.String
toString()
Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.Collection<V>
values()
RichIterable<V>
valuesView()
Returns an unmodifiable lazy iterable wrapped around the values for the map.Methods inherited from class org.eclipse.collections.impl.map.immutable.AbstractImmutableMap
aggregateBy, aggregateInPlaceBy, castToMap, clear, collect, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectValues, collectWith, countBy, countByEach, countByWith, detect, detectOptional, entrySet, flatCollect, flip, flipUniqueValues, groupBy, groupByEach, groupByUniqueKey, iterator, newWithAllKeyValueArguments, newWithAllKeyValues, newWithKeyValue, newWithoutAllKeys, newWithoutKey, partition, partitionWith, put, putAll, reject, reject, rejectWith, remove, select, select, selectInstancesOf, selectWith, sumByDouble, sumByFloat, sumByInt, sumByLong, tap, toImmutable, toMap, zip, zipWithIndex
Methods inherited from class org.eclipse.collections.impl.map.AbstractMapIterable
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, asLazy, chunk, contains, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, getFirst, getLast, getOnly, getOrDefault, noneSatisfy, noneSatisfyWith, toArray, toArray
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countWith, flatCollect, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, 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 interface org.eclipse.collections.api.map.ImmutableMap
aggregateBy, flatCollectWith
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll
Methods inherited from interface org.eclipse.collections.api.map.MapIterable
getOrDefault, parallelStream, spliterator, stream
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, containsBy, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getFirst, getLast, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndex
-
Constructor Details
-
Method Details
-
equals
Description copied from interface:MapIterable
Follows the same general contract asMap.equals(Object)
. -
hashCode
public int hashCode()Description copied from interface:MapIterable
Follows the same general contract asMap.hashCode()
. -
toString
Description copied from class:AbstractRichIterable
Returns 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:
toString
in interfaceMapIterable<K,V>
- Specified by:
toString
in interfaceRichIterable<K>
- Overrides:
toString
in classAbstractRichIterable<V>
- Returns:
- a string representation of this collection.
- See Also:
AbstractCollection.toString()
-
size
public int size()Description copied from interface:RichIterable
Returns the number of items in this iterable.- Specified by:
size
in interfaceBatchIterable<K>
- Specified by:
size
in interfaceMap<K,V>
- Specified by:
size
in interfaceRichIterable<K>
-
containsKey
- Specified by:
containsKey
in interfaceMap<K,V>
- Specified by:
containsKey
in interfaceMapIterable<K,V>
- See Also:
Map.containsKey(Object)
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,V>
- Specified by:
containsValue
in interfaceMapIterable<K,V>
- See Also:
Map.containsValue(Object)
-
get
- Specified by:
get
in interfaceMap<K,V>
- Specified by:
get
in interfaceMapIterable<K,V>
- See Also:
Map.get(Object)
-
getBatchCount
public int getBatchCount(int batchSize)- Specified by:
getBatchCount
in interfaceBatchIterable<K>
-
batchForEach
- Specified by:
batchForEach
in interfaceBatchIterable<K>
-
forEachValue
Description copied from interface:MapIterable
Calls the procedure with each value of the map.Set<String> result = UnifiedSet.newSet(); MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four"); map.forEachValue(new CollectionAddProcedure<String>(result)); Verify.assertSetsEqual(UnifiedSet.newSetWith("One", "Two", "Three", "Four"), result);
- Specified by:
forEachValue
in interfaceMapIterable<K,V>
- Overrides:
forEachValue
in classAbstractMapIterable<K,V>
-
forEachKey
Description copied from interface:MapIterable
Calls theprocedure
with each key of the map.final Collection<Integer> result = new ArrayList<Integer>(); MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3"); map.forEachKey(new CollectionAddProcedure<Integer>(result)); Verify.assertContainsAll(result, 1, 2, 3);
- Specified by:
forEachKey
in interfaceMapIterable<K,V>
- Overrides:
forEachKey
in classAbstractMapIterable<K,V>
-
forEachKeyValue
Description copied from interface:MapIterable
Calls theprocedure
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");
- Specified by:
forEachKeyValue
in interfaceMapIterable<K,V>
-
keySet
-
values
-
keysView
Description copied from interface:MapIterable
Returns an unmodifiable lazy iterable wrapped around the keySet for the map.- Specified by:
keysView
in interfaceMapIterable<K,V>
-
valuesView
Description copied from interface:MapIterable
Returns an unmodifiable lazy iterable wrapped around the values for the map.- Specified by:
valuesView
in interfaceMapIterable<K,V>
-
keyValuesView
Description copied from interface:MapIterable
Returns an unmodifiable lazy iterable of key/value pairs wrapped around the entrySet for the map.- Specified by:
keyValuesView
in interfaceMapIterable<K,V>
-
forEachWithIndex
Description copied from interface:InternalIterable
Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.Example using a Java 8 lambda:
people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
Example using an anonymous inner class:
people.forEachWithIndex(new ObjectIntProcedure<Person>() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });
- Specified by:
forEachWithIndex
in interfaceInternalIterable<K>
- Overrides:
forEachWithIndex
in classAbstractMapIterable<K,V>
-
forEachWith
Description copied from interface:InternalIterable
The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.Example using a Java 8 lambda:
people.forEachWith((Person person, Person other) -> { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } }, fred);
Example using an anonymous inner class:
people.forEachWith(new Procedure2<Person, Person>() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);
- Specified by:
forEachWith
in interfaceInternalIterable<K>
- Overrides:
forEachWith
in classAbstractMapIterable<K,V>
-
ifPresentApply
Description copied from interface:MapIterable
If there is a value in the Map that corresponds to the specified key return the result of applying the specified Function on the value, otherwise return null.- Specified by:
ifPresentApply
in interfaceMapIterable<K,V>
- Overrides:
ifPresentApply
in classAbstractMapIterable<K,V>
-
getIfAbsent
Description copied from interface:MapIterable
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified Function0.- Specified by:
getIfAbsent
in interfaceMapIterable<K,V>
- Overrides:
getIfAbsent
in classAbstractMapIterable<K,V>
-
getIfAbsentValue
Description copied from interface:MapIterable
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, returnvalue
.- Specified by:
getIfAbsentValue
in interfaceMapIterable<K,V>
- Overrides:
getIfAbsentValue
in classAbstractMapIterable<K,V>
-
getIfAbsentWith
Description copied from interface:MapIterable
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified function and parameter.- Specified by:
getIfAbsentWith
in interfaceMapIterable<K,V>
- Overrides:
getIfAbsentWith
in classAbstractMapIterable<K,V>
-