IMapOfSets<K, V> class
An immutable, unordered, map of sets.
- Inheritance
-
- Object
- ImmutableCollection<
IMapOfSets< K, V> > - IMapOfSets
- Annotations
Constructors
-
IMapOfSets([Map<
K, Iterable< ? mapOfSets])V> > -
factory
-
IMapOfSets.from(IMap<
K, ISet< imap, {ConfigMapOfSets? config})V> > -
Creates an IMapOfSets from an
IMap
of sets. The resulting map and its sets will be sorted according toconfig
, or, if not provided, according to the default configuration for ConfigMapOfSets. -
IMapOfSets.withConfig(Map<
K, Iterable< ? mapOfSets, ConfigMapOfSets config)V> > -
Create an IMapOfSets from a map of sets and a ConfigMapOfSets.
factory
Properties
- config → ConfigMapOfSets
-
The map-of-sets configuration.
final
- configMap → ConfigMap
-
The internal IMap configuration.
no setter
- configSet → ConfigSet
-
The internal ISet configuration.
no setter
-
entries
→ Iterable<
MapEntry< K, ISet< >V> > -
Return iterable of entries, where each entry is the key:set pair.
no setter
-
entriesAsSet
→ ISet<
MapEntry< K, ISet< >V> > -
Returns an ISet of the MapEntry's.
no setter
-
flush
→ IMapOfSets<
K, V> -
Flushes this collection, if necessary. Chainable method.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setteroverride
- isDeepEquals → bool
-
See also: ConfigMapOfSets
no setter
- isEmpty → bool
-
Returns
true
if there are no elements in this collection.no setteroverride - isFlushed → bool
-
Whether this collection is already flushed or not.
no setteroverride
- isIdentityEquals → bool
-
See also: ConfigMapOfSets
no setter
- isNotEmpty → bool
-
Returns
true
if there is at least one element in this collection.no setteroverride -
keys
→ Iterable<
K> -
Returns an Iterable of the map keys.
no setter
-
keysAsList
→ IList<
K> -
Return all keys.
no setter
-
keysAsSet
→ ISet<
K> -
Returns an ISet of the keys.
no setter
- lengthOfKeys → int
-
The number of keys.
no setter
- lengthOfNonRepeatingValues → int
-
The sum of the number of unique values of all sets.
no setter
- lengthOfValues → int
-
The sum of the number of values of all sets.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
sets
→ Iterable<
ISet< V> > -
Returns an Iterable of the map values.
no setter
-
setsAsList
→ IList<
ISet< V> > -
Returns a list of the internal sets.
no setter
-
setsAsSet
→ ISet<
ISet< V> > -
Returns an ISet of the internal sets.
no setter
-
unlock
→ Map<
K, Set< V> > -
Unlocks the map, returning a regular (mutable, ordered)
Map<K, Set<V>
of type LinkedHashMap. This map is "safe", in the sense that is independent from the original IMap.no setter -
values
→ Iterable<
V> -
Return all values of all sets, in order, including duplicates.
no setter
-
valuesAsSet
→ ISet<
V> -
Return all values of all sets, removing duplicates.
no setter
Methods
-
add(
K key, V value) → IMapOfSets< K, V> -
Find the
key
/set
entry, and add thevalue
to theset
. If thekey
doesn't exist, will first create it with an emptyset
, and then add thevalue
to it. If thevalue
already exists in theset
, nothing happens. -
addEntries(
Iterable< MapEntry< entries) → IMapOfSets<K, Set< >V> >K, V> - Adds all set values to this map.
-
addIMap(
IMap< K, Set< map) → IMapOfSets<V> >K, V> - Adds all set values to this map.
-
addMap(
Map< K, Set< map) → IMapOfSets<V> >K, V> - Adds all set values to this map.
-
addValues(
K key, Iterable< V> values) → IMapOfSets<K, V> -
Find the
key
/set
entry, and add all thevalues
to theset
. If thekey
doesn't exist, will first create it with an emptyset
, and then add thevalues
to it. -
addValuesToKeys(
Iterable< K> keys, Iterable<V> values) → IMapOfSets<K, V> -
Add all
values
to eachset
of all givenkeys
. If thekey
doesn't exist, it will first create it with an emptyset
, and then add thevalues
to it. -
allEntriesWithValue(
V value) → Set< MapEntry< K, ISet< >V> > -
Return any
key:set
entry where the value exists in the set. If that entry doesn't exist, returnnull
. -
allKeysWithValue(
V value) → Set< K> -
Returns a Set of the keys which contain
value
. -
asIMap(
) → IMap< K, ISet< V> > -
Returns this
IMapOfSets<K, V>
as anIMap<K, ISet<V>>
. -
cast<
RK, RV> () → IMapOfSets< RK, RV> -
Provides a view of this map of sets as having
RK
keys andRV
instances, if necessary. -
clear(
) → IMapOfSets< K, V> -
If
removeEmptySets
istrue
, returns an empty map of sets with the same configuration. However, ifremoveEmptySets
isfalse
, keep the keys, but make their sets empty. -
clearSet(
K key) → IMapOfSets< K, V> -
When
removeEmptySets
istrue
, the givenkey
and its correspondingset
will be removed. This is the same as calling removeSet. -
contains(
K key, V value) → bool -
Return
true
if the givenkey
entry exists, and its set contains the givenvalue
. -
containsKey(
K? key) → bool -
Return
true
if the givenkey
exists. -
containsValue(
V value) → bool -
Return
true
if the value exists in any of the sets. -
entry(
K key) → MapEntry< K, ISet< V> ?> -
Return the MapEntry for the given
key
. For key/value pairs that don't exist, it will returnMapEntry(key, null);
. -
entryOrNull(
K key) → MapEntry< K, ISet< ?V> > -
Return the MapEntry for the given
key
. For key/value pairs that don't exist, it will return null. -
equalItems(
covariant Iterable< MapEntry> other) → bool -
Will return
true
only if the ISet has the same number of items as the iterable, and the ISet items are equal to the iterable items, in whatever order. This may be slow for very large sets, since it compares each item, one by one.override -
equalItemsAndConfig(
IMapOfSets other) → bool -
Will return
true
only if the list items are equal, and the map of sets configurations (ConfigMapOfSets) are equal. This may be slow for very large maps, since it compares each item, one by one.override -
equalItemsToIMap<
RK, RV> (IMap< RK, ISet< other) → boolRV> > -
Will return
true
only if the two maps have the same number of entries, and if the entries of the two maps are pairwise equal on both key and value. -
equalItemsToIMapOfSets(
IMapOfSets other) → bool -
Will return
true
only if the two maps have the same number of entries, and if the entries of the two maps are pairwise equal on both key and value. -
firstValueWhere(
bool test(V), {V orElse()?}) → V -
Iterates through all values of all sets, and returns the first value
it finds that satisfies
test
. -
firstValueWhereOrNull(
bool test(V), {V? orElse()?}) → V? -
Iterates through all values of all sets, and returns the first value
it finds that satisfies
test
. -
flatten(
) → Iterable< MapEntry< K, V> > -
Return a flattened iterable of <K, V> entries (including eventual duplicates),
where each entry is a key:value pair.
For example, if the map is
{1: {a, b}, 2: {x, y}}
, it will return(1:a), (1:b), (2:x), (2:y)
. -
forEach(
void f(K key, ISet< V> set)) → void -
Applies the function
f
to each element. -
get(
K key) → ISet< V> -
Return the
set
for the givenkey
. If thekey
doesn't exist, return an empty set (never returnnull
). -
getEntryWithValue(
V value) → MapEntry< K, ISet< ?V> > -
Return any
key:set
entry where the value exists in the set. If that entry doesn't exist, returnnull
. -
getKeyWithValue(
V value) → K? -
Return any key entry where the value exists in its set.
If it doesn't find the value, return
null
. -
getOrNull(
K key) → ISet< V> ? -
Return the
set
for the givenkey
. If thekey
doesn't exist, returnnull
. -
invertKeysAndValues(
[ConfigMapOfSets? config]) → IMapOfSets< V, K> -
Return a map where the keys are the values, and the values are the keys.
Keys of empty sets will be removed.
You can pass a new
config
for the map. -
invertKeysAndValuesKeepingNullKeys(
[ConfigMapOfSets? config]) → IMapOfSets< V?, K> -
Return a map where the keys are the values, and the values are the keys.
Empty sets will become the key
null
. You can pass a newconfig
for the map. -
isEmptyForKey(
K key) → bool -
Return
true
if the value set is empty ornull
, for the givenkey
. Returnfalse
if there are 1 or more values, for the givenkey
. -
isNotEmptyForKey(
K key) → bool -
Return
true
if there are 1 or more values, for the givenkey
. Returnfalse
if the value set is empty ornull
, for the givenkey
. -
keyList(
{ConfigList? config}) → IList< K> -
Returns an IList of the map keys.
Optionally, you may provide a
config
for the list. -
map<
RK, RV> (MapEntry< RK, ISet< mapper(K key, ISet<RV> >V> set), {ConfigMapOfSets? config}) → IMapOfSets<RK, RV> -
Returns a new map where all entries of this map are transformed by the given
mapper
function. You may provide aconfig
, otherwise it will be the same as the original map. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
K key, V value) → IMapOfSets< K, V> -
Find the
key
/set
entry, and remove thevalue
from theset
. If thekey
doesn't exist, don't do anything. If theset
becomes empty andremoveEmptySets
istrue
, thekey
will be removed entirely. Otherwise, thekey
will be kept and theset
will be empty (notnull
). -
removeSet(
K key) → IMapOfSets< K, V> -
Remove the given
key
, if it exists, and its correspondingset
. If thekey
doesn't exist, don't do anything. -
removeValues(
List< V> values, {Output<int> ? numberOfRemovedValues}) → IMapOfSets<K, V> -
Remove all given
values
from all sets. If aset
becomes empty andremoveEmptySets
istrue
, itskey
will be removed entirely. Otherwise, itskey
will be kept and theset
will be empty (notnull
). If you want, you can passnumberOfRemovedValues
to get the number of removed values. -
removeValuesFromKeyWhere(
K key, bool test(V value)) → IMapOfSets< K, V> -
Remove, from the given
key
set, all values that satisfy the giventest
. If the set becomes empty, thekey
will be removed entirely. -
removeValuesWhere(
bool test(K key, V value), {Output< int> ? numberOfRemovedValues}) → IMapOfSets<K, V> -
Remove, from all sets, all given values that satisfy the given
test
. If aset
becomes empty, itskey
will be removed entirely. If you want, you can passnumberOfRemovedValues
to get the number of removed values. -
removeWhere(
bool predicate(K key, ISet< V> set)) → IMapOfSets<K, V> -
Removes all entries (key:set pair) of this map that satisfy the given
predicate
. -
replaceSet(
K key, ISet< V> set) → IMapOfSets<K, V> -
When
removeEmptySets
istrue
: If the givenset
is not empty, add thekey
/set
entry. If thekey
already exists, replace it with the newset
entirely. If the givenset
is empty, thekey
/set
entry will be removed (same as calling removeSet).When
removeEmptySets
isfalse
: Add thekey
/set
entry. If thekey
already exists, replace it with the newset
entirely. -
same(
IMapOfSets< K, V> other) → bool -
Will return
true
only if the maps internals are the same instances (comparing by identity). This will be fast even for very large maps, since it doesn't compare each entry.override -
toggle(
K key, V value, {bool? state}) → IMapOfSets< K, V> -
Removes the
value
from the set of the correspondingkey
, if it exists in the set. Otherwise, adds it to the set. If thekey
doesn't exist, it will be created and then have the new value added to the new, corresponding set. -
toString(
[bool? prettyPrint]) → String -
Returns a string representation of (some of) the elements of
this
.override -
update(
K key, ISet< V> update(ISet<V> set), {ISet<V> ifAbsent()?, Output<ISet< ? previousSet}) → IMapOfSets<V> >K, V> -
Updates the
set
for the providedkey
. -
updateAll(
ISet< V> update(K key, ISet<V> set)) → IMapOfSets<K, V> - Updates all sets.
-
valueList(
{ConfigList? config}) → IList< V> - Returns an IList of the all values in all sets.
-
withConfig(
ConfigMapOfSets config) → IMapOfSets< K, V> -
Creates a new map-of-sets with the given
config
(ConfigMapOfSets).
Operators
-
operator ==(
Object other) → bool -
If isDeepEquals configuration is
true
: Will returntrue
only if the map entries are equal (not necessarily in the same order), and the map configurations are equal. This may be slow for very large maps, since it compares each entry, one by one.If isDeepEquals configuration is
false
: Will returntrue
only if the maps internals are the same instances (comparing by identity). This will be fast even for very large maps, since it doesn't compare each entry.override -
operator [](
K key) → ISet< V> ? -
Return the
set
for the givenkey
. If thekey
doesn't exist, returnnull
.
Static Properties
- defaultConfig ↔ ConfigMapOfSets
-
Global configuration that specifies if, by default, the
IMapOfSet
s use equality or identity for their operator ==.getter/setter pair
Static Methods
-
empty<
K, V> ([ConfigMapOfSets? config]) → IMapOfSets< K, V> - Returns an empty IMapOfSets, with the given configuration. If a configuration is not provided, it will use the default configuration.
-
fromIterable<
K, V, I> (Iterable< I> iterable, {K keyMapper(I)?, V valueMapper(I)?, bool ignore(I)?, ConfigMapOfSets? config}) → IMapOfSets<K, V> -
Creates a map of sets instance in which the keys and values are
computed from the
iterable
. -
orNull<
K, V> (Map< K, Iterable< ? map, [ConfigMapOfSets? config]) → IMapOfSets<V> >K, V> ? -
If
mapOfSets
isnull
, returnnull
.