Class UnifiedMap<K,V>
- All Implemented Interfaces:
Externalizable
,Serializable
,Cloneable
,Iterable<V>
,Map<K,V>
,InternalIterable<V>
,MapIterable<K,V>
,MutableMap<K,V>
,MutableMapIterable<K,V>
,UnsortedMapIterable<K,V>
,RichIterable<V>
,BatchIterable<V>
public class UnifiedMap<K,V> extends AbstractMutableMap<K,V> implements Externalizable, BatchIterable<V>
The final result is a Map implementation that's leaner than java.util.HashMap and faster than Trove's THashMap. The best of both approaches unified together, and thus the name UnifiedMap.
- See Also:
- Serialized Form
-
Nested Class Summary
-
Constructor Summary
Constructors Constructor Description UnifiedMap()
UnifiedMap(int initialCapacity)
UnifiedMap(int initialCapacity, float loadFactor)
UnifiedMap(Map<? extends K,? extends V> map)
UnifiedMap(Pair<K,V>... pairs)
-
Method Summary
Modifier and Type Method Description boolean
allSatisfy(Predicate<? super V> predicate)
Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty.<P> boolean
allSatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)
Returns true if the predicate evaluates to true for every element of the collection, or returns false.boolean
anySatisfy(Predicate<? super V> predicate)
Returns true if the predicate evaluates to true for any element of the iterable.<P> boolean
anySatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)
Returns true if the predicate evaluates to true for any element of the collection, or return false.void
batchForEach(Procedure<? super V> procedure, int sectionIndex, int sectionCount)
void
clear()
UnifiedMap<K,V>
clone()
<E> MutableMap<K,V>
collectKeysAndValues(Iterable<E> iterable, Function<? super E,? extends K> keyFunction, Function<? super E,? extends V> valueFunction)
Adds all the entries derived fromiterable
tothis
.<R> MutableMap<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)
V
detect(Predicate<? super V> predicate)
Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true.Pair<K,V>
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.V
detectIfNone(Predicate<? super V> predicate, Function0<? extends V> function)
Returns the first element of the iterable for which the predicate evaluates to true.Optional<V>
detectOptional(Predicate<? super V> predicate)
Returns the first element of the iterable for which the predicate evaluates to true as an Optional.Optional<Pair<K,V>>
detectOptional(Predicate2<? super K,? super V> predicate)
Return the first key and value of the map as an Optional for which the predicate evaluates to true when they are given as arguments.<P> V
detectWith(Predicate2<? super V,? super P> predicate, P parameter)
Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.<P> V
detectWithIfNone(Predicate2<? super V,? super P> predicate, P parameter, Function0<? extends V> function)
Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter, or returns the value of evaluating the specified function.<P> Optional<V>
detectWithOptional(Predicate2<? super V,? super P> predicate, P parameter)
Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.Set<Map.Entry<K,V>>
entrySet()
boolean
equals(Object object)
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)
int
getCollidingBuckets()
V
getFirst()
Returns the first element of an iterable.V
getIfAbsentPut(K key, Function0<? extends V> function)
Get and return the value in the Map at the specified key.V
getIfAbsentPut(K key, V value)
Get and return the value in the Map at the specified key.<P> V
getIfAbsentPutWith(K key, Function<? super P,? extends V> function, P parameter)
Get and return the value in the Map at the specified key.int
getMapMemoryUsedInWords()
Returns the number of JVM words that is used by this map.int
hashCode()
Follows the same general contract asMap.hashCode()
.boolean
isEmpty()
Returns true if this iterable has zero items.Set<K>
keySet()
MutableMap<K,V>
newEmpty()
Creates a new instance of the same type, using the default capacity and growth parameters.MutableMap<K,V>
newEmpty(int capacity)
Creates a new instance of the same type, using the given capacity and the default growth parameters.static <K, V> UnifiedMap<K,V>
newMap()
static <K, V> UnifiedMap<K,V>
newMap(int size)
static <K, V> UnifiedMap<K,V>
newMap(int size, float loadFactor)
static <K, V> UnifiedMap<K,V>
newMap(Map<? extends K,? extends V> map)
static <K, V> UnifiedMap<K,V>
newMapWith(Iterable<Pair<K,V>> inputIterable)
static <K, V> UnifiedMap<K,V>
newMapWith(Pair<K,V>... pairs)
static <K, V> UnifiedMap<K,V>
newWithKeysValues(K key, V value)
static <K, V> UnifiedMap<K,V>
newWithKeysValues(K key1, V value1, K key2, V value2)
static <K, V> UnifiedMap<K,V>
newWithKeysValues(K key1, V value1, K key2, V value2, K key3, V value3)
static <K, V> UnifiedMap<K,V>
newWithKeysValues(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
boolean
noneSatisfy(Predicate<? super V> predicate)
Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty.<P> boolean
noneSatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)
Returns true if the predicate evaluates to false for every element of the collection, or return false.V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> map)
void
readExternal(ObjectInput in)
V
remove(Object key)
boolean
removeIf(Predicate2<? super K,? super V> predicate)
Remove an entry from the map if thepredicate
evaluates to true.V
removeKey(K key)
Remove an entry from the map at the specifiedkey
.int
size()
Returns the number of items in this iterable.ImmutableMap<K,V>
toImmutable()
Returns an immutable copy of this map.String
toString()
Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.boolean
trimToSize()
V
updateValue(K key, Function0<? extends V> factory, Function<? super V,? extends V> function)
Looks up the value associated withkey
, applies thefunction
to it, and replaces the value.<P> V
updateValueWith(K key, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter)
Same asMutableMapIterable.updateValue(Object, Function0, Function)
with a Function2 and specified parameter which is passed to the function.Collection<V>
values()
UnifiedMap<K,V>
withKeysValues(K key, V value)
UnifiedMap<K,V>
withKeysValues(K key1, V value1, K key2, V value2)
UnifiedMap<K,V>
withKeysValues(K key1, V value1, K key2, V value2, K key3, V value3)
UnifiedMap<K,V>
withKeysValues(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
void
writeExternal(ObjectOutput out)
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, reject, rejectWith, select, select, selectInstancesOf, selectWith, tap, withAllKeyValueArguments, withAllKeyValues, withKeyValue, withoutAllKeys, withoutKey, zip, zipWithIndex
Methods inherited from class org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable
aggregateBy, aggregateInPlaceBy, collect, countBy, countByEach, countByWith, flipUniqueValues, getIfAbsentPutWithKey, iterator, keysView, keyValuesView, sumByDouble, sumByFloat, sumByInt, sumByLong, valuesView
Methods inherited from class org.eclipse.collections.impl.map.AbstractMapIterable
asLazy, chunk, contains, each, getIfAbsent, getIfAbsentValue, getIfAbsentWith, getLast, getOnly, getOrDefault, ifPresentApply, 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, 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 java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
Methods inherited from interface org.eclipse.collections.api.map.MapIterable
getIfAbsent, getIfAbsentValue, getIfAbsentWith, ifPresentApply, keysView, keyValuesView, parallelStream, spliterator, stream, valuesView
Methods inherited from interface org.eclipse.collections.api.map.MutableMap
aggregateBy, aggregateBy, aggregateInPlaceBy, collect, flatCollectWith, flipUniqueValues, withMap
Methods inherited from interface org.eclipse.collections.api.map.MutableMapIterable
add, countBy, countByEach, countByWith, getIfAbsentPutWithKey, getOrDefault, putPair, removeAllKeys, sumByDouble, sumByFloat, sumByInt, sumByLong
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, 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, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getLast, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, 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
-
UnifiedMap
public UnifiedMap() -
UnifiedMap
public UnifiedMap(int initialCapacity) -
UnifiedMap
public UnifiedMap(int initialCapacity, float loadFactor) -
UnifiedMap
-
UnifiedMap
-
-
Method Details
-
newMap
-
newMap
-
newMap
-
newMap
-
newMapWith
-
newMapWith
-
newWithKeysValues
-
newWithKeysValues
-
newWithKeysValues
public static <K, V> UnifiedMap<K,V> newWithKeysValues(K key1, V value1, K key2, V value2, K key3, V value3) -
newWithKeysValues
public static <K, V> UnifiedMap<K,V> newWithKeysValues(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) -
withKeysValues
-
withKeysValues
-
withKeysValues
-
withKeysValues
-
clone
- Specified by:
clone
in interfaceMutableMap<K,V>
- Specified by:
clone
in classAbstractMutableMap<K,V>
-
newEmpty
Description copied from interface:MutableMapIterable
Creates a new instance of the same type, using the default capacity and growth parameters.- Specified by:
newEmpty
in interfaceMutableMap<K,V>
- Specified by:
newEmpty
in interfaceMutableMapIterable<K,V>
-
newEmpty
Description copied from class:AbstractMutableMap
Creates a new instance of the same type, using the given capacity and the default growth parameters.- Specified by:
newEmpty
in classAbstractMutableMap<K,V>
-
clear
public void clear() -
put
-
updateValue
public V updateValue(K key, Function0<? extends V> factory, Function<? super V,? extends V> function)Description copied from interface:MutableMapIterable
Looks up the value associated withkey
, applies thefunction
to it, and replaces the value. If there is no value associated withkey
, starts it off with a value supplied byfactory
.- Specified by:
updateValue
in interfaceMutableMapIterable<K,V>
- Overrides:
updateValue
in classAbstractMutableMapIterable<K,V>
-
updateValueWith
public <P> V updateValueWith(K key, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter)Description copied from interface:MutableMapIterable
Same asMutableMapIterable.updateValue(Object, Function0, Function)
with a Function2 and specified parameter which is passed to the function.- Specified by:
updateValueWith
in interfaceMutableMapIterable<K,V>
- Overrides:
updateValueWith
in classAbstractMutableMapIterable<K,V>
-
getIfAbsentPut
Description copied from interface:MutableMapIterable
Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map at the key, return the result of evaluating the specified Function0, and put that value in the map at the specified key.- Specified by:
getIfAbsentPut
in interfaceMutableMapIterable<K,V>
- Overrides:
getIfAbsentPut
in classAbstractMutableMapIterable<K,V>
-
getIfAbsentPut
Description copied from interface:MutableMapIterable
Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map at the key, return the specified value, and put that value in the map at the specified key.- Specified by:
getIfAbsentPut
in interfaceMutableMapIterable<K,V>
- Overrides:
getIfAbsentPut
in classAbstractMutableMapIterable<K,V>
-
getIfAbsentPutWith
Description copied from interface:MutableMapIterable
Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map for that key return the result of evaluating the specified Function using the specified parameter, and put that value in the map at the specified key.- Specified by:
getIfAbsentPutWith
in interfaceMutableMapIterable<K,V>
- Overrides:
getIfAbsentPutWith
in classAbstractMutableMapIterable<K,V>
-
getCollidingBuckets
public int getCollidingBuckets() -
getMapMemoryUsedInWords
public int getMapMemoryUsedInWords()Returns the number of JVM words that is used by this map. A word is 4 bytes in a 32bit VM and 8 bytes in a 64bit VM. Each array has a 2 word header, thus the formula is: words = (internal table length + 2) + sum (for all chains (chain length + 2))- Returns:
- the number of JVM words that is used by this map.
-
get
- Specified by:
get
in interfaceMap<K,V>
- Specified by:
get
in interfaceMapIterable<K,V>
- See Also:
Map.get(Object)
-
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)
-
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>
-
getFirst
Description copied from interface:RichIterable
Returns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.
- Specified by:
getFirst
in interfaceRichIterable<K>
- Overrides:
getFirst
in classAbstractMapIterable<K,V>
-
collectKeysAndValues
public <E> MutableMap<K,V> collectKeysAndValues(Iterable<E> iterable, Function<? super E,? extends K> keyFunction, Function<? super E,? extends V> valueFunction)Description copied from interface:MutableMap
Adds all the entries derived fromiterable
tothis
. The key and value for each entry is determined by applying thekeyFunction
andvalueFunction
to each item incollection
. Any entry inmap
that has the same key as an entry inthis
will have its value replaced by that inmap
.- Specified by:
collectKeysAndValues
in interfaceMutableMap<K,V>
-
removeKey
Description copied from interface:MutableMapIterable
Remove an entry from the map at the specifiedkey
.- Specified by:
removeKey
in interfaceMutableMapIterable<K,V>
- Returns:
- The value removed from entry at key, or null if not found.
- See Also:
Map.remove(Object)
-
removeIf
Description copied from interface:MutableMapIterable
Remove an entry from the map if thepredicate
evaluates to true.- Specified by:
removeIf
in interfaceMutableMapIterable<K,V>
- Returns:
- true if any entry is removed.
-
getBatchCount
public int getBatchCount(int batchSize)- Specified by:
getBatchCount
in interfaceBatchIterable<K>
-
batchForEach
- Specified by:
batchForEach
in interfaceBatchIterable<K>
-
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>
-
isEmpty
public boolean isEmpty()Description copied from interface:RichIterable
Returns true if this iterable has zero items.- Specified by:
isEmpty
in interfaceMap<K,V>
- Specified by:
isEmpty
in interfaceRichIterable<K>
- Overrides:
isEmpty
in classAbstractRichIterable<V>
-
putAll
-
remove
-
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>
-
entrySet
-
keySet
-
values
-
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()
-
trimToSize
public boolean trimToSize() -
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
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>
-
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>
- Overrides:
collectValues
in classAbstractMutableMap<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 of 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>
-
detect
Description copied from interface:RichIterable
Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true. This method is commonly called find.Example using a Java 8 lambda expression:
Person person = people.detect(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
Example using an anonymous inner class:
Person person = people.detect(new Predicate<Person>() { public boolean accept(Person person) { return person.getFirstName().equals("John") && person.getLastName().equals("Smith"); } });
- Specified by:
detect
in interfaceRichIterable<K>
- Overrides:
detect
in classAbstractMapIterable<K,V>
-
detectWith
Description copied from interface:RichIterable
Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.Example using a Java 8 lambda expression:
Person person = people.detectWith((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
Example using an anonymous inner class:
Person person = people.detectWith(new Predicate2<Person, String>() { public boolean accept(Person person, String fullName) { return person.getFullName().equals(fullName); } }, "John Smith");
- Specified by:
detectWith
in interfaceRichIterable<K>
- Overrides:
detectWith
in classAbstractMapIterable<K,V>
-
detectOptional
Description copied from interface:MapIterable
Return the first key and value of the map as an Optional 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 of 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.Optional<Pair<City, Person>> detected = peopleByCity.detectOptional((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
- Specified by:
detectOptional
in interfaceMapIterable<K,V>
- Overrides:
detectOptional
in classAbstractMutableMapIterable<K,V>
-
detectOptional
Description copied from interface:RichIterable
Returns the first element of the iterable for which the predicate evaluates to true as an Optional. This method is commonly called find.Example using a Java 8 lambda expression:
Person person = people.detectOptional(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
- Specified by:
detectOptional
in interfaceRichIterable<K>
- Overrides:
detectOptional
in classAbstractMapIterable<K,V>
-
detectWithOptional
Description copied from interface:RichIterable
Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.Example using a Java 8 lambda expression:
Optional<Person> person = people.detectWithOptional((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
- Specified by:
detectWithOptional
in interfaceRichIterable<K>
- Overrides:
detectWithOptional
in classAbstractMapIterable<K,V>
-
detectIfNone
Description copied from interface:RichIterable
Returns the first element of the iterable for which the predicate evaluates to true. If no element matches the predicate, then returns the value of applying the specified function.- Specified by:
detectIfNone
in interfaceRichIterable<K>
- Overrides:
detectIfNone
in classAbstractMapIterable<K,V>
-
detectWithIfNone
public <P> V detectWithIfNone(Predicate2<? super V,? super P> predicate, P parameter, Function0<? extends V> function)Description copied from interface:RichIterable
Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter, or returns the value of evaluating the specified function.- Specified by:
detectWithIfNone
in interfaceRichIterable<K>
- Overrides:
detectWithIfNone
in classAbstractMapIterable<K,V>
-
anySatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for any element of the iterable. Returns false if the iterable is empty, or if no element returned true when evaluating the predicate.- Specified by:
anySatisfy
in interfaceRichIterable<K>
- Overrides:
anySatisfy
in classAbstractMapIterable<K,V>
-
anySatisfyWith
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for any element of the collection, or return false. Returns false if the collection is empty.- Specified by:
anySatisfyWith
in interfaceRichIterable<K>
- Overrides:
anySatisfyWith
in classAbstractMapIterable<K,V>
-
allSatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
allSatisfy
in interfaceRichIterable<K>
- Overrides:
allSatisfy
in classAbstractMapIterable<K,V>
-
allSatisfyWith
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for every element of the collection, or returns false.- Specified by:
allSatisfyWith
in interfaceRichIterable<K>
- Overrides:
allSatisfyWith
in classAbstractMapIterable<K,V>
-
noneSatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
noneSatisfy
in interfaceRichIterable<K>
- Overrides:
noneSatisfy
in classAbstractMapIterable<K,V>
-
noneSatisfyWith
Description copied from interface:RichIterable
Returns true if the predicate evaluates to false for every element of the collection, or return false. Returns true if the collection is empty.- Specified by:
noneSatisfyWith
in interfaceRichIterable<K>
- Overrides:
noneSatisfyWith
in classAbstractMapIterable<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>
-