Class SingletonMap<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.mutable.AbstractMutableMap<K,V>
org.eclipse.collections.impl.map.fixed.AbstractMemoryEfficientMutableMap<K,V>
org.eclipse.collections.impl.map.fixed.SingletonMap<K,V>
- All Implemented Interfaces:
Externalizable
,Serializable
,Cloneable
,Iterable<V>
,Map<K,
,V> InternalIterable<V>
,FixedSizeMap<K,
,V> MapIterable<K,
,V> MutableMap<K,
,V> MutableMapIterable<K,
,V> UnsortedMapIterable<K,
,V> RichIterable<V>
final class SingletonMap<K,V>
extends AbstractMemoryEfficientMutableMap<K,V>
implements Externalizable
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMap
AbstractMutableMap.ValuesCollectionCommon<V>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
<K2,
V2> FixedSizeMap <K2, V2> For each key and value of the map the function is evaluated.<R> FixedSizeMap
<K, R> collectValues
(Function2<? super K, ? super V, ? extends R> function) For each key and value of the map the function is evaluated.boolean
containsKey
(Object key) boolean
containsValue
(Object value) detect
(Predicate2<? super K, ? super V> predicate) Return the first key and value of the map for which the predicate evaluates to true when they are given as arguments.entrySet()
boolean
Follows the same general contract asMap.equals(Object)
.MutableMap
<V, K> Return the MapIterable that is obtained by flipping the direction of this map and making the associations from value to key.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.(package private) K
getKey1()
getOnly()
Returns the element if the iterable has exactly one element.int
hashCode()
Follows the same general contract asMap.hashCode()
.keySet()
void
reject
(Predicate2<? super K, ? super V> predicate) For each key and value of the map the predicate is evaluated, if the result of the evaluation is false, that key and value are returned in a new map.select
(Predicate2<? super K, ? super V> predicate) For each key and value of the map the predicate is evaluated, if the result of the evaluation is true, that key and value are returned in a new map.int
size()
Returns the number of items in this iterable.Returns an immutable copy of this map.toString()
Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.values()
MutableMap
<K, V> withKeyValue
(K addKey, V addValue) This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements.MutableMap
<K, V> withoutKey
(K key) This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements.void
Methods inherited from class org.eclipse.collections.impl.map.fixed.AbstractMemoryEfficientMutableMap
clear, collectKeysAndValues, newEmpty, newEmpty, put, putAll, remove, removeAllKeys, removeIf, removeKey, tap, updateValue, updateValueWith, withAllKeyValueArguments, withAllKeyValues, withoutAllKeys
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMap
asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, flatCollect, flip, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, rejectWith, select, selectInstancesOf, selectWith, zip, zipWithIndex
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable
aggregateBy, countBy, countByEach, countByWith, detectOptional, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, iterator, keysView, keyValuesView, sumByDouble, sumByFloat, sumByInt, sumByLong, 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, getFirst, getIfAbsent, getIfAbsentValue, getIfAbsentWith, getLast, 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, 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 class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.collections.api.map.FixedSizeMap
putAllMapIterable, withMap, withMapIterable
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll
Methods inherited from interface org.eclipse.collections.api.map.MapIterable
detectOptional, getIfAbsent, getIfAbsentValue, getIfAbsentWith, ifPresentApply, injectIntoKeyValue, keysView, keyValuesView, parallelStream, spliterator, stream, valuesView
Methods inherited from interface org.eclipse.collections.api.map.MutableMap
aggregateBy, aggregateBy, aggregateInPlaceBy, asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, flatCollect, flatCollectWith, flip, groupBy, groupByEach, groupByUniqueKey, partition, partitionWith, reject, rejectWith, select, selectInstancesOf, selectWith, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.map.MutableMapIterable
add, countBy, countByEach, countByWith, getIfAbsentPut, getIfAbsentPut, getIfAbsentPutWith, getIfAbsentPutWithKey, getOrDefault, putPair, sumByDouble, sumByFloat, sumByInt, sumByLong
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, getFirst, getLast, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, isEmpty, makeString, 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, 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, zip, zipWithIndex
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
key1
-
value1
-
-
Constructor Details
-
SingletonMap
public SingletonMap() -
SingletonMap
-
-
Method Details
-
size
public int size()Description copied from interface:RichIterable
Returns the number of items in this iterable. -
getKey1
K getKey1() -
withKeyValue
Description copied from interface:MutableMapIterable
This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original plus the additional key and value. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:map = map.withKeyValue("new key", "new value");
In the case of FixedSizeMap, a new instance will be returned by withKeyValue, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling put on themselves.- Specified by:
withKeyValue
in interfaceMutableMap<K,
V> - Specified by:
withKeyValue
in interfaceMutableMapIterable<K,
V> - Overrides:
withKeyValue
in classAbstractMutableMap<K,
V> - See Also:
-
withoutKey
Description copied from interface:MutableMapIterable
This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original minus the key and value to be removed. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:map = map.withoutKey("key");
In the case of FixedSizeMap, a new instance will be returned by withoutKey, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling remove on themselves.- Specified by:
withoutKey
in interfaceMutableMap<K,
V> - Specified by:
withoutKey
in interfaceMutableMapIterable<K,
V> - Overrides:
withoutKey
in classAbstractMutableMap<K,
V> - See Also:
-
clone
- Specified by:
clone
in interfaceMutableMap<K,
V> - Specified by:
clone
in classAbstractMutableMap<K,
V>
-
toImmutable
Description copied from interface:MutableMapIterable
Returns an immutable copy of this map. If the map is immutable, it returns itself.- Specified by:
toImmutable
in interfaceMapIterable<K,
V> - Specified by:
toImmutable
in interfaceMutableMapIterable<K,
V> - Specified by:
toImmutable
in interfaceUnsortedMapIterable<K,
V> - Overrides:
toImmutable
in classAbstractMutableMap<K,
V>
-
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V> - Specified by:
containsKey
in interfaceMapIterable<K,
V> - See Also:
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V> - Specified by:
containsValue
in interfaceMapIterable<K,
V> - See Also:
-
get
-
keySet
-
values
-
entrySet
-
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:
-
hashCode
public int hashCode()Description copied from interface:MapIterable
Follows the same general contract asMap.hashCode()
. -
equals
Description copied from interface:MapIterable
Follows the same general contract asMap.equals(Object)
. -
flipUniqueValues
Description copied from interface:MapIterable
Return the MapIterable that is obtained by flipping the direction of this map and making the associations from value to key.MapIterable<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3"); MapIterable<String, Integer> result = map.flipUniqueValues(); Assert.assertTrue(result.equals(UnifiedMap.newWithKeysValues("1", 1, "2", 2, "3", 3)));
- Specified by:
flipUniqueValues
in interfaceMapIterable<K,
V> - Specified by:
flipUniqueValues
in interfaceMutableMap<K,
V> - Specified by:
flipUniqueValues
in interfaceMutableMapIterable<K,
V> - Specified by:
flipUniqueValues
in interfaceUnsortedMapIterable<K,
V> - Overrides:
flipUniqueValues
in classAbstractMutableMapIterable<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>
-
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>
-
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>
-
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>
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
select
Description copied from interface:MapIterable
For each key and value of the map the predicate is evaluated, if the result of the evaluation is true, that key and value are returned in a new map.MapIterable<City, Person> selected = peopleByCity.select((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
- Specified by:
select
in interfaceMapIterable<K,
V> - Specified by:
select
in interfaceMutableMap<K,
V> - Specified by:
select
in interfaceMutableMapIterable<K,
V> - Specified by:
select
in interfaceUnsortedMapIterable<K,
V> - Specified by:
select
in classAbstractMemoryEfficientMutableMap<K,
V>
-
collectValues
Description copied from interface:MapIterable
For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.MapIterable<City, String> collected = peopleByCity.collectValues((City city, Person person) -> person.getFirstName() + " " + person.getLastName());
- Specified by:
collectValues
in interfaceMapIterable<K,
V> - Specified by:
collectValues
in interfaceMutableMap<K,
V> - Specified by:
collectValues
in interfaceMutableMapIterable<K,
V> - Specified by:
collectValues
in interfaceUnsortedMapIterable<K,
V> - Specified by:
collectValues
in classAbstractMemoryEfficientMutableMap<K,
V>
-
collect
Description copied from interface:MapIterable
For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.MapIterable<String, String> collected = peopleByCity.collect((City city, Person person) -> Pair.of(city.getCountry(), person.getAddress().getCity()));
- Specified by:
collect
in interfaceMapIterable<K,
V> - Specified by:
collect
in interfaceMutableMap<K,
V> - Specified by:
collect
in interfaceMutableMapIterable<K,
V> - Specified by:
collect
in interfaceUnsortedMapIterable<K,
V> - Specified by:
collect
in classAbstractMemoryEfficientMutableMap<K,
V>
-
reject
Description copied from interface:MapIterable
For each key and value of the map the predicate is evaluated, if the result of the evaluation is false, that key and value are returned in a new map.MapIterable<City, Person> rejected = peopleByCity.reject((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
- Specified by:
reject
in interfaceMapIterable<K,
V> - Specified by:
reject
in interfaceMutableMap<K,
V> - Specified by:
reject
in interfaceMutableMapIterable<K,
V> - Specified by:
reject
in interfaceUnsortedMapIterable<K,
V> - Specified by:
reject
in classAbstractMemoryEfficientMutableMap<K,
V>
-
detect
Description copied from interface:MapIterable
Return the first key and value of the map for which the predicate evaluates to true when they are given as arguments. The predicate will only be evaluated until such pair is found or until all the keys and values of the map have been used as arguments. That is, there may be keys and values of the map that are never used as arguments to the predicate. The result is null if predicate does not evaluate to true for any key/value combination.Pair<City, Person> detected = peopleByCity.detect((City city, Person person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
- Specified by:
detect
in interfaceMapIterable<K,
V> - Overrides:
detect
in classAbstractMutableMapIterable<K,
V>
-
getOnly
Description copied from interface:RichIterable
Returns the element if the iterable has exactly one element. Otherwise, throwIllegalStateException
.- Specified by:
getOnly
in interfaceRichIterable<K>
- Overrides:
getOnly
in classAbstractMapIterable<K,
V> - Returns:
- an element of an iterable.
-