Package org.javimmutable.collections
Interface IListMap<K,V>
- All Superinterfaces:
ICollection<IMapEntry<K,
,IList<V>>> InvariantCheckable
,IStreamable<IMapEntry<K,
,IList<V>>> Iterable<IMapEntry<K,
,IList<V>>> Mapped<K,
,IList<V>> Serializable
,SplitableIterable<IMapEntry<K,
IList<V>>>
- All Known Implementing Classes:
HashListMap
,OrderedListMap
,TreeListMap
@Immutable
public interface IListMap<K,V>
extends ICollection<IMapEntry<K,IList<V>>>, Mapped<K,IList<V>>, InvariantCheckable, Serializable
Interface for maps that map keys to lists of values.
-
Method Summary
Modifier and TypeMethodDescriptionSets the list associated with a specific key.Deletes the entry for the specified key (if any).Deletes the list for every key in keys.Deletes the list for every key in keys.IStreamable
<IMapEntry<K, IList<V>>> entries()
Creates an IStreamable to access all of the Map's entries.default void
Processes every key/list pair in this map using the provided function.default <E extends Exception>
voidforEachThrows
(Proc2Throws<K, IList<V>, E> proc) Processes every key/list pair in this map using the provided function.Return the list associated with key or an empty list if no list is associated.Add value to the list for the specified key.Add key/value entry to the map, replacing any existing entry with same key.Add all values to the container in some manner appropriate to the implementation.Add all values to the container in some manner appropriate to the implementation.Adds all of the elements of the specified collection to the List for the specified key.Adds all of the elements of the specified collection to the List for the specified key.keys()
Creates an IStreamable to access all of the Map's keys.Returns a Collector that creates a listMap of the same type as this containing all of the collected values inserted over whatever starting values this already contained.Apply the specified transform function to the List assigned to the specified key and assign the result to the key in this map.Apply the specified transform function to the List assigned to the specified key and assign the result to the key in this map.Creates an IStreamable to access all of the specified key's list.Methods inherited from interface org.javimmutable.collections.ICollection
isEmpty, isNonEmpty, size
Methods inherited from interface org.javimmutable.collections.InvariantCheckable
checkInvariants
Methods inherited from interface org.javimmutable.collections.IStreamable
getSpliteratorCharacteristics, iterator, parallelStream, spliterator, stream
Methods inherited from interface org.javimmutable.collections.Mapped
find, get, getValueOr
Methods inherited from interface org.javimmutable.collections.SplitableIterable
forEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Method Details
-
insertAll
Description copied from interface:ICollection
Add all values to the container in some manner appropriate to the implementation.- Specified by:
insertAll
in interfaceICollection<K>
-
insertAll
@Nonnull default IListMap<K,V> insertAll(@Nonnull Iterable<? extends IMapEntry<K, IList<V>>> iterable) Description copied from interface:ICollection
Add all values to the container in some manner appropriate to the implementation.- Specified by:
insertAll
in interfaceICollection<K>
-
getList
Return the list associated with key or an empty list if no list is associated.- Parameters:
key
- identifies the value to retrieve- Returns:
- list associated with key or an empty list if no value is associated
-
assign
Sets the list associated with a specific key. Key and value must be non-null. If the key already has a list in the map the old list is discarded and the new list is stored in its place. Returns a newIListMap
reflecting any changes. The original map is always left unchanged.- Parameters:
key
- non-null keyvalue
- list of possibly null values to use for this key- Returns:
- new map reflecting the change
-
insert
Add key/value entry to the map, replacing any existing entry with same key.- Specified by:
insert
in interfaceICollection<K>
-
insert
Add value to the list for the specified key. Note that this can create duplicate values in the list. -
insertAll
Adds all of the elements of the specified collection to the List for the specified key. -
insertAll
Adds all of the elements of the specified collection to the List for the specified key. -
delete
Deletes the entry for the specified key (if any). Returns a new map if the value was deleted or the current map if the key was not contained in the map.- Parameters:
key
- non-null key- Returns:
- same or different map depending on whether key was removed
-
deleteAll
Deletes the list for every key in keys. Returns a new map if the keys were deleted or the current map if the keys were contained in the map. -
deleteAll
Deletes the list for every key in keys. Returns a new map if the keys were deleted or the current map if the keys were contained in the map. -
transform
Apply the specified transform function to the List assigned to the specified key and assign the result to the key in this map. If no List is currently assigned to the key the transform function is called with an empty list.- Parameters:
key
- key holding list to be updatedtransform
- function to update the list- Returns:
- new map with update applied to list associated with key
-
transformIfPresent
default IListMap<K,V> transformIfPresent(@Nonnull K key, @Nonnull Func1<IList<V>, IList<V>> transform) Apply the specified transform function to the List assigned to the specified key and assign the result to the key in this map. If no list is currently assigned to the key the transform function is never called and this map is returned unchanged.- Parameters:
key
- key holding list to be updatedtransform
- function to update the list- Returns:
- new map with update applied to list associated with key
-
deleteAll
- Specified by:
deleteAll
in interfaceICollection<K>
- Returns:
- an equivalent collection with no values
-
keys
Creates an IStreamable to access all of the Map's keys. -
values
Creates an IStreamable to access all of the specified key's list. If no list exists for key an empty IStreamable is returned.- Returns:
- a (possibly empty) IStreamable for traversing the values associated with key
-
entries
Creates an IStreamable to access all of the Map's entries. -
forEach
Processes every key/list pair in this map using the provided function. -
forEachThrows
Processes every key/list pair in this map using the provided function.- Throws:
E
-
listMapCollector
Returns a Collector that creates a listMap of the same type as this containing all of the collected values inserted over whatever starting values this already contained.
-