KEYTYPE
- Map key typeVALUETYPE
- Map value typepublic interface ICommonsMap<KEYTYPE,VALUETYPE> extends Map<KEYTYPE,VALUETYPE>, ICloneable<ICommonsMap<KEYTYPE,VALUETYPE>>, Serializable
Map
interface with extended functionalityModifier and Type | Method and Description |
---|---|
default void |
addAll(Map<? extends KEYTYPE,? extends VALUETYPE> aValues)
Add all provided values.
|
default boolean |
containsAnyEntry(Predicate<? super Map.Entry<KEYTYPE,VALUETYPE>> aFilter)
Check if at least one entry matches the passed filter.
|
default boolean |
containsAnyKey(Predicate<? super KEYTYPE> aFilter)
Check if at least one key matches the passed filter.
|
default boolean |
containsAnyValue(Predicate<? super VALUETYPE> aFilter)
Check if at least one value matches the passed filter.
|
default ICommonsSet<Map.Entry<KEYTYPE,VALUETYPE>> |
copyOfEntrySet() |
default ICommonsSet<KEYTYPE> |
copyOfKeySet() |
default ICommonsSet<KEYTYPE> |
copyOfKeySet(Predicate<? super KEYTYPE> aFilter)
Create a copy of all values matching the passed filter.
|
default ICommonsList<VALUETYPE> |
copyOfValues() |
default ICommonsList<VALUETYPE> |
copyOfValues(Predicate<? super VALUETYPE> aFilter)
Create a copy of all values matching the passed filter.
|
default <DSTTYPE> ICommonsList<DSTTYPE> |
copyOfValuesMapped(Function<? super VALUETYPE,? extends DSTTYPE> aMapper)
Create a copy of all values after applying the passed mapping function.
|
default <DSTTYPE> ICommonsList<DSTTYPE> |
copyOfValuesMapped(Predicate<? super VALUETYPE> aFilter,
Function<? super VALUETYPE,? extends DSTTYPE> aMapper)
Create a copy of all values matching the passed filter which are then
converted using the provided function.
|
default <K,V> ICommonsMap<K,V> |
createInstance()
Create a new empty map.
|
default Map.Entry<KEYTYPE,VALUETYPE> |
findFirstEntry(Predicate<? super Map.Entry<KEYTYPE,VALUETYPE>> aFilter)
Find the first entry that matches the passed filter.
|
default KEYTYPE |
findFirstKey(Predicate<? super Map.Entry<KEYTYPE,VALUETYPE>> aFilter)
Find the first key that matches the passed filter.
|
default VALUETYPE |
findFirstValue(Predicate<? super Map.Entry<KEYTYPE,VALUETYPE>> aFilter)
Find the first value that matches the passed filter.
|
default void |
forEach(BiPredicate<? super KEYTYPE,? super VALUETYPE> aFilter,
BiConsumer<? super KEYTYPE,? super VALUETYPE> aConsumer)
Invoke the provided consumer on each entry (pair of key and value) that
matches the provided filter.
|
default void |
forEachKey(Consumer<? super KEYTYPE> aConsumer)
Invoke the provided consumer on each key.
|
default void |
forEachKey(Predicate<? super KEYTYPE> aFilter,
Consumer<? super KEYTYPE> aConsumer)
Invoke the provided consumer on each key that matches the provided filter.
|
default void |
forEachValue(Consumer<? super VALUETYPE> aConsumer)
Invoke the provided consumer on each value.
|
default void |
forEachValue(Predicate<? super VALUETYPE> aFilter,
Consumer<? super VALUETYPE> aConsumer)
Invoke the provided consumer on each value that matches the provided
filter.
|
default Map<KEYTYPE,VALUETYPE> |
getAsUnmodifiable() |
default Map.Entry<KEYTYPE,VALUETYPE> |
getFirstEntry()
Get the first element of this map or
null . |
default Map.Entry<KEYTYPE,VALUETYPE> |
getFirstEntry(Map.Entry<KEYTYPE,VALUETYPE> aDefault)
Get the first element of this map or the provided default value.
|
default KEYTYPE |
getFirstKey()
Get the first key of this map or
null . |
default KEYTYPE |
getFirstKey(KEYTYPE aDefault)
Get the first key of this map or the provided default value.
|
default VALUETYPE |
getFirstValue()
Get the first value of this map or
null . |
default VALUETYPE |
getFirstValue(VALUETYPE aDefault)
Get the first value of this map or the provided default value.
|
default ICommonsOrderedMap<KEYTYPE,VALUETYPE> |
getSortedByKey(Comparator<? super KEYTYPE> aKeyComparator)
Get the map sorted by its keys.
|
default ICommonsOrderedMap<KEYTYPE,VALUETYPE> |
getSortedByValue(Comparator<? super VALUETYPE> aValueComparator)
Get the map sorted by its values.
|
default ICommonsMap<VALUETYPE,KEYTYPE> |
getSwappedKeyValues()
Get a map where keys and values are exchanged.
|
default boolean |
isNotEmpty() |
default VALUETYPE |
put(Map.Entry<? extends KEYTYPE,? extends VALUETYPE> aEntry)
Special put overload that takes an entry and should simplify copying from
other maps.
|
default void |
putAll(Iterable<? extends Map.Entry<KEYTYPE,VALUETYPE>> aIterable)
Add all passed entries to this map.
|
default void |
putAll(Map<KEYTYPE,VALUETYPE> aMap,
Predicate<? super Map.Entry<? extends KEYTYPE,? extends VALUETYPE>> aFilter)
Add all items from the passed map that match the filter to this map.
|
default <ELEMENTTYPE> |
putAllMapped(ELEMENTTYPE[] aElements,
Function<? super ELEMENTTYPE,? extends KEYTYPE> aKeyMapper,
Function<? super ELEMENTTYPE,? extends VALUETYPE> aValueMapper)
Add all items from the passed array to this map using the provided key and
value mapper.
|
default <ELEMENTTYPE> |
putAllMapped(Iterable<? extends ELEMENTTYPE> aElements,
Function<? super ELEMENTTYPE,? extends KEYTYPE> aKeyMapper,
Function<? super ELEMENTTYPE,? extends VALUETYPE> aValueMapper)
Add all items from the passed iterable to this map using the provided key
and value mapper.
|
default <SRCKEYTYPE,SRCVALUETYPE> |
putAllMapped(Map<? extends SRCKEYTYPE,? extends SRCVALUETYPE> aMap,
Function<? super SRCKEYTYPE,? extends KEYTYPE> aKeyMapper,
Function<? super SRCVALUETYPE,? extends VALUETYPE> aValueMapper)
Add all items from the passed map to this map using the provided key and
value mapper.
|
default void |
putIf(KEYTYPE aKey,
VALUETYPE aValue,
Predicate<? super VALUETYPE> aFilter)
Put the passed value into the map if the provided predicate is fulfilled.
|
default void |
putIfNotNull(KEYTYPE aKey,
VALUETYPE aValue)
Put the passed value into the map if it is not
null . |
default EChange |
removeAll()
Remove all elements from this collection.
|
default EChange |
removeIf(Predicate<? super Map.Entry<? extends KEYTYPE,? extends VALUETYPE>> aFilter) |
default EChange |
removeIfKey(Predicate<? super KEYTYPE> aFilter) |
default EChange |
removeIfValue(Predicate<? super VALUETYPE> aFilter) |
default EChange |
removeObject(KEYTYPE aKey)
Remove the object with the passed key from this map.
|
default EChange |
setAll(Map<? extends KEYTYPE,? extends VALUETYPE> aValues)
Clear and add all provided values.
|
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
getClone
@Nonnull @ReturnsMutableCopy default <K,V> ICommonsMap<K,V> createInstance()
CommonsHashMap
.K
- Map key typeV
- Map value typenull
.@Nonnull @ReturnsMutableCopy default ICommonsSet<KEYTYPE> copyOfKeySet()
null
set with all keys.Map.keySet()
,
copyOfKeySet(Predicate)
@Nonnull @ReturnsMutableCopy default ICommonsSet<KEYTYPE> copyOfKeySet(@Nullable Predicate<? super KEYTYPE> aFilter)
aFilter
- The filter to be applied. May be null
.null
set with all matching keys.Map.keySet()
,
copyOfKeySet()
@Nonnull @ReturnsMutableCopy default ICommonsList<VALUETYPE> copyOfValues()
null
set with all values.Map.values()
,
copyOfValues(Predicate)
,
copyOfValuesMapped(Function)
,
copyOfValuesMapped(Predicate, Function)
@Nonnull @ReturnsMutableCopy default ICommonsList<VALUETYPE> copyOfValues(@Nullable Predicate<? super VALUETYPE> aFilter)
aFilter
- The filter to be applied. May be null
.copyOfValues()
Map.values()
,
copyOfValues()
,
copyOfValuesMapped(Function)
,
copyOfValuesMapped(Predicate, Function)
@Nonnull @ReturnsMutableCopy default <DSTTYPE> ICommonsList<DSTTYPE> copyOfValuesMapped(@Nonnull Function<? super VALUETYPE,? extends DSTTYPE> aMapper)
DSTTYPE
- The destination type to be mapped toaMapper
- The mapping function to be applied. May not be null
.Map.values()
,
copyOfValues()
,
copyOfValuesMapped(Function)
,
copyOfValuesMapped(Predicate, Function)
@Nonnull @ReturnsMutableCopy default <DSTTYPE> ICommonsList<DSTTYPE> copyOfValuesMapped(@Nullable Predicate<? super VALUETYPE> aFilter, @Nonnull Function<? super VALUETYPE,? extends DSTTYPE> aMapper)
DSTTYPE
- The destination type to be mapped toaFilter
- The filter to be applied. May be null
.aMapper
- The mapping function to be applied. May not be null
.copyOfValuesMapped(Function)
Map.values()
,
copyOfValues()
,
copyOfValues(Predicate)
,
copyOfValuesMapped(Predicate, Function)
@Nonnull @ReturnsMutableCopy default ICommonsSet<Map.Entry<KEYTYPE,VALUETYPE>> copyOfEntrySet()
null
copy of the entry set.default boolean isNotEmpty()
true
if the map is not empty, false
otherwise.@Nullable default Map.Entry<KEYTYPE,VALUETYPE> getFirstEntry()
null
.null
if the map is empty, the first element otherwise.getFirstEntry(java.util.Map.Entry)
@Nullable default Map.Entry<KEYTYPE,VALUETYPE> getFirstEntry(@Nullable Map.Entry<KEYTYPE,VALUETYPE> aDefault)
aDefault
- The default value to be returned if this map is empty. May be
null
.getFirstEntry()
@Nullable default KEYTYPE getFirstKey()
null
.null
if the map is empty, the first key otherwise.getFirstKey(Object)
@Nullable default KEYTYPE getFirstKey(@Nullable KEYTYPE aDefault)
aDefault
- The default value to be returned if this map is empty. May be
null
.getFirstKey()
@Nullable default VALUETYPE getFirstValue()
null
.null
if the map is empty, the first value otherwise.getFirstValue(Object)
@Nullable default VALUETYPE getFirstValue(@Nullable VALUETYPE aDefault)
aDefault
- The default value to be returned if this map is empty. May be
null
.getFirstValue()
@Nullable default Map.Entry<KEYTYPE,VALUETYPE> findFirstEntry(@Nullable Predicate<? super Map.Entry<KEYTYPE,VALUETYPE>> aFilter)
aFilter
- The filter to be applied. May be null
.null
if no matching element was found. I no filter was
provided, the result is the same as getFirstEntry()
.@Nullable default KEYTYPE findFirstKey(@Nullable Predicate<? super Map.Entry<KEYTYPE,VALUETYPE>> aFilter)
aFilter
- The filter to be applied. May be null
.null
if no matching element was found. I no filter was
provided, the result is the same as getFirstKey()
.@Nullable default VALUETYPE findFirstValue(@Nullable Predicate<? super Map.Entry<KEYTYPE,VALUETYPE>> aFilter)
aFilter
- The filter to be applied. May be null
.null
if no matching element was found. I no filter was
provided, the result is the same as getFirstValue()
.default boolean containsAnyEntry(@Nullable Predicate<? super Map.Entry<KEYTYPE,VALUETYPE>> aFilter)
aFilter
- The filter to be applied. May be null
.true
if the map is not empty and contains at least one
element matching the filter, false
otherwise. If no
filter is provided the return value is identical to
isNotEmpty()
.default boolean containsAnyKey(@Nullable Predicate<? super KEYTYPE> aFilter)
aFilter
- The filter to be applied. May be null
.true
if the map is not empty and contains at least one
key matching the filter, false
otherwise. If no filter
is provided the return value is identical to isNotEmpty()
.default boolean containsAnyValue(@Nullable Predicate<? super VALUETYPE> aFilter)
aFilter
- The filter to be applied. May be null
.true
if the map is not empty and contains at least one
value matching the filter, false
otherwise. If no
filter is provided the return value is identical to
isNotEmpty()
.default void forEachKey(@Nonnull Consumer<? super KEYTYPE> aConsumer)
aConsumer
- The consumer to be invoked. May not be null
.default void forEachValue(@Nonnull Consumer<? super VALUETYPE> aConsumer)
aConsumer
- The consumer to be invoked. May not be null
.default void forEach(@Nullable BiPredicate<? super KEYTYPE,? super VALUETYPE> aFilter, @Nonnull BiConsumer<? super KEYTYPE,? super VALUETYPE> aConsumer)
aFilter
- The filter to be applied. May be null
.aConsumer
- The consumer to be invoked. May not be null
.Map.forEach(BiConsumer)
default void forEachKey(@Nullable Predicate<? super KEYTYPE> aFilter, @Nonnull Consumer<? super KEYTYPE> aConsumer)
aFilter
- The filter to be applied. May be null
.aConsumer
- The consumer to be invoked. May not be null
.forEachKey(Consumer)
,
forEach(BiPredicate, BiConsumer)
default void forEachValue(@Nullable Predicate<? super VALUETYPE> aFilter, @Nonnull Consumer<? super VALUETYPE> aConsumer)
aFilter
- The filter to be applied. May be null
.aConsumer
- The consumer to be invoked. May not be null
.forEachValue(Consumer)
,
forEach(BiPredicate, BiConsumer)
@Nonnull @ReturnsMutableCopy default ICommonsOrderedMap<KEYTYPE,VALUETYPE> getSortedByKey(@Nonnull Comparator<? super KEYTYPE> aKeyComparator)
aKeyComparator
- The comparator to be used. May not be null
.null
.@Nonnull @ReturnsMutableCopy default ICommonsOrderedMap<KEYTYPE,VALUETYPE> getSortedByValue(@Nonnull Comparator<? super VALUETYPE> aValueComparator)
aValueComparator
- The comparator to be used. May not be null
.null
.@Nullable @ReturnsMutableCopy default ICommonsMap<VALUETYPE,KEYTYPE> getSwappedKeyValues()
createInstance()
.@Nullable default VALUETYPE put(@Nonnull Map.Entry<? extends KEYTYPE,? extends VALUETYPE> aEntry)
aEntry
- Entry to be added. May not be null
.Map.put(Object, Object)
. May be
null
.default void putIf(@Nonnull KEYTYPE aKey, @Nullable VALUETYPE aValue, @Nonnull Predicate<? super VALUETYPE> aFilter)
aKey
- Key to use. May not be null
for certain map types.aValue
- The value to be added. May be null
in which case
nothing happens.aFilter
- The value predicate to be checked before insertion. May not be
null
.default void putIfNotNull(@Nonnull KEYTYPE aKey, @Nullable VALUETYPE aValue)
null
.aKey
- Key to use. May not be null
for certain map types.aValue
- The value to be added. May be null
in which case
nothing happens.default void putAll(@Nullable Iterable<? extends Map.Entry<KEYTYPE,VALUETYPE>> aIterable)
aIterable
- Source map entries. May be null
.default void putAll(@Nullable Map<KEYTYPE,VALUETYPE> aMap, @Nullable Predicate<? super Map.Entry<? extends KEYTYPE,? extends VALUETYPE>> aFilter)
aMap
- Source Map. May be null
.aFilter
- The filter to use. May be null
.default <ELEMENTTYPE> void putAllMapped(@Nullable ELEMENTTYPE[] aElements, @Nonnull Function<? super ELEMENTTYPE,? extends KEYTYPE> aKeyMapper, @Nonnull Function<? super ELEMENTTYPE,? extends VALUETYPE> aValueMapper)
ELEMENTTYPE
- Array element typeaElements
- Source collection. May be null
.aKeyMapper
- The key mapper. May not be null
.aValueMapper
- The value mapper. May not be null
.default <ELEMENTTYPE> void putAllMapped(@Nullable Iterable<? extends ELEMENTTYPE> aElements, @Nonnull Function<? super ELEMENTTYPE,? extends KEYTYPE> aKeyMapper, @Nonnull Function<? super ELEMENTTYPE,? extends VALUETYPE> aValueMapper)
ELEMENTTYPE
- Collection element typeaElements
- Source collection. May be null
.aKeyMapper
- The key mapper. May not be null
.aValueMapper
- The value mapper. May not be null
.default <SRCKEYTYPE,SRCVALUETYPE> void putAllMapped(@Nullable Map<? extends SRCKEYTYPE,? extends SRCVALUETYPE> aMap, @Nonnull Function<? super SRCKEYTYPE,? extends KEYTYPE> aKeyMapper, @Nonnull Function<? super SRCVALUETYPE,? extends VALUETYPE> aValueMapper)
SRCKEYTYPE
- Source map key typeSRCVALUETYPE
- Source map value typeaMap
- Source map. May be null
.aKeyMapper
- The key mapper. May not be null
.aValueMapper
- The value mapper. May not be null
.default void addAll(@Nullable Map<? extends KEYTYPE,? extends VALUETYPE> aValues)
aValues
- The values to be added. May be null
.@Nonnull default EChange setAll(@Nullable Map<? extends KEYTYPE,? extends VALUETYPE> aValues)
aValues
- The values to be added. May be null
.EChange
@Nonnull default EChange removeAll()
Map.clear()
but it returns a different value whether something was
cleared or not.EChange.CHANGED
if the collection was not empty and
something was removed, EChange.UNCHANGED
otherwise.Map.clear()
@Nonnull default EChange removeObject(@Nullable KEYTYPE aKey)
EChange.UNCHANGED
even if removal was
successful if the value was null
.aKey
- The key to be removed. May be null
.EChange.CHANGED
if the removal was successful,
EChange.UNCHANGED
if removal fails.Map.remove(Object)
@Nonnull default EChange removeIf(@Nonnull Predicate<? super Map.Entry<? extends KEYTYPE,? extends VALUETYPE>> aFilter)
@Nonnull @CodingStyleguideUnaware default Map<KEYTYPE,VALUETYPE> getAsUnmodifiable()
null
.Collections
Copyright © 2014–2019 Philip Helger. All rights reserved.