IMap<K, V> class

An immutable, unordered map.

Inheritance
Annotations
  • @immutable

Constructors

IMap([Map<K, V>? map])
Create an IMap from a Map.
factory
IMap.fromEntries(Iterable<MapEntry<K, V>> entries, {ConfigMap? config})
Create an IMap from an Iterable of MapEntry. If multiple entries have the same key, later occurrences overwrite the earlier ones.
factory
IMap.fromIterables(Iterable<K> keys, Iterable<V> values, {ConfigMap? config})
Creates an IMap instance associating the given keys to values.
factory
IMap.fromJson(Map<String, Object?> json, K fromJsonK(Object?), V fromJsonV(Object?))
Converts from JSon. Json serialization support for json_serializable with @JsonSerializable.
factory
IMap.fromKeys({required Iterable<K> keys, required V valueMapper(K), ConfigMap? config})
Create an IMap from the given keys. The values will be the result of applying valueMapper to the keys. If a key repeats, later occurrences overwrite the earlier ones.
factory
IMap.fromValues({required K keyMapper(V), required Iterable<V> values, ConfigMap? config})
Create an IMap from the given values. The keys will be the result of applying keyMapper to the values. If a key repeats, later occurrences overwrite the earlier ones.
factory
IMap.unsafe(Map<K, V>? map, {required ConfigMap config})
Unsafe constructor. Use this at your own peril.
IMap.withConfig(Map<K, V>? map, ConfigMap config)
Create an IMap from a Map and a ConfigMap.
factory

Properties

comparableEntries Iterable<Entry<K, V>>
Returns an Iterable of the map entries of type Entry. Contrary to MapEntry, Entry is comparable and implements equals (==) and hashcode by using its key and value.
no setter
config ConfigMap
The map configuration.
final
entries Iterable<MapEntry<K, V>>
Returns an Iterable of the map entries of type MapEntry.
no setter
flush IMap<K, V>
Flushes the map, if necessary. Chainable method. If the map is already flushed, doesn't do anything.
no setteroverride
hashCode int
The hash code for this object.
no setteroverride
isDeepEquals bool
See also: ConfigList
no setter
isEmpty bool
Returns true if there are no elements in this collection.
no setteroverride
isFlushed bool
Whether this map is already flushed or not.
no setteroverride
isIdentityEquals bool
See also: ConfigList
no setter
isNotEmpty bool
Returns true if there is at least one element in this collection.
no setteroverride
iterator Iterator<MapEntry<K, V>>
Returns a new Iterator that allows iterating the entries of the IMap.
no setter
keys Iterable<K>
Returns an Iterable of the map keys.
no setter
length int
The number of objects in this list.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
unlock Map<K, V>
Unlocks the map, returning a regular (mutable, ordered) Map of type LinkedHashMap. This map is "safe", in the sense that is independent from the original IMap.
no setter
unlockLazy Map<K, V>
Unlocks the map, returning a safe, modifiable (mutable) Map.
no setter
unlockSorted Map<K, V>
Unlocks the map, returning a regular, mutable, ordered, sorted, Map of type LinkedHashMap. This map is "safe", in the sense that is independent from the original IMap.
no setter
unlockView Map<K, V>
Unlocks the map, returning a safe, unmodifiable (immutable) Map view. The word "view" means the set is backed by the original IMap.
no setter
values Iterable<V>
Returns an Iterable of the map values, in the same order as the keys. If you need to sort the values, please use toValueIList.
no setter
withDeepEquals IMap<K, V>
Creates a map with deepEquals (compares all map entries by equality).
no setter
withIdentityEquals IMap<K, V>
Creates a map with identityEquals (compares the internals by identity).
no setter

Methods

add(K key, V value) IMap<K, V>
Returns a new map containing the current map plus the given key:value. (if necessary, the given key:value pair will override the current).
addAll(IMap<K, V> imap, {bool keepOrder = false}) IMap<K, V>
Returns a new map containing the current map plus the ones in the given imap.
addEntries(Iterable<MapEntry<K, V>> entries) IMap<K, V>
Returns a new map containing the current map plus the given entries. Note: entries that already exist in the original map will overwrite those of the original map, in place (keeping order).
addEntry(MapEntry<K, V> entry) IMap<K, V>
Returns a new map containing the current map plus the given key:value. (if necessary, the given entry will override the current one).
addMap(Map<K, V> map) IMap<K, V>
Returns a new map containing the current map plus the given map entries. Note: map entries that already exist in the original map will overwrite those of the original map, in place (keeping order).
any(bool test(K key, V value)) bool
Checks whether any key-value pair of this map satisfies test.
anyEntry(bool test(MapEntry<K, V>)) bool
Checks whether any entry of this iterable satisfies test.
cast<RK, RV>() IMap<RK, RV>
Provides a view of this map as having RK keys and RV instances, if necessary.
clear() IMap<K, V>
Returns an empty map with the same configuration.
contains(K key, V value) bool
Returns true if the map contains an element equal to the key-value pair, false otherwise.
containsEntry(MapEntry<K, V> entry) bool
Returns true if the map contains the entry, false otherwise.
containsKey(K? key) bool
Returns true if the map contains the key, false otherwise.
containsValue(V? value) bool
Returns true if the map contains the value, false otherwise.
entry(K key) MapEntry<K, V?>
Return the MapEntry for the given key. For key/value pairs that don't exist, it will return MapEntry(key, null);.
entryOrNull(K key) MapEntry<K, 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 IMap entries are equal to the entries in the Iterable. Order is irrelevant. This may be slow for very large maps, since it compares each entry, one by one. To compare with a map, use method equalItemsToMap or equalItemsToIMap.
override
equalItemsAndConfig(IMap other) bool
Will return true only if the list items are equal, and the map configurations are equal. This may be slow for very large maps, since it compares each item, one by one.
override
equalItemsToIMap(IMap 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.
equalItemsToMap(Map 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.
everyEntry(bool test(MapEntry<K, V>)) bool
Checks whether every entry of this iterable satisfies test.
forEach(void f(K key, V value)) → void
Applies the function f to each element.
get(K k) → V?
Returns the value for the given key or null if key is not in the map.
map<RK, RV>(MapEntry<RK, RV> mapper(K key, V value), {bool ifRemove(RK key, RV value)?, ConfigMap? config}) IMap<RK, RV>
Returns a new map where all entries of this map are transformed by the given mapper function. However, if ifRemove is provided, the mapped value will first be tested with it and, if ifRemove returns true, the value will be removed from the result map.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
putIfAbsent(K key, V ifAbsent(), {Output<V>? previousValue}) IMap<K, V>
Look up the value of key, or add a new value if it isn't there.
remove(K key) IMap<K, V>
Returns a new map containing the current map minus the given key and its value. However, if the current map doesn't contain the key, it will return the current map (same instance).
removeWhere(bool predicate(K key, V value)) IMap<K, V>
Returns a new map containing the current map minus the entries that satisfy the given predicate. However, if nothing is removed, it will return the current map (same instance).
same(IMap<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
toEntryIList({int compare(MapEntry<K, V>? a, MapEntry<K, V>? b)?, ConfigList? config}) IList<MapEntry<K, V>>
Returns an IList of the map entries.
toEntryISet({ConfigSet? config}) ISet<MapEntry<K, V>>
Returns an ISet of the map entries. Optionally, you may provide a config for the set.
toEntryList({int compare(MapEntry<K, V> a, MapEntry<K, V> b)?}) List<MapEntry<K, V>>
Returns a List of the map entries.
toEntrySet({int compare(MapEntry<K, V> a, MapEntry<K, V> b)?}) Set<MapEntry<K, V>>
Returns a Set of the map entries. The set will be sorted if the map's sort configuration is true, or if you explicitly provide a compare method.
toJson(Object? toJsonK(K), Object? toJsonV(V)) Object
Converts to JSon. Json serialization support for json_serializable with @JsonSerializable.
toKeyIList({int compare(K? a, K? b)?, ConfigList? config}) IList<K>
Returns an IList of the map keys.
toKeyISet({ConfigSet? config}) ISet<K>
Returns an ISet of the map keys. Optionally, you may provide a config for the set.
toKeyList({int compare(K a, K b)?}) List<K>
Returns a List of the map keys.
toKeySet({int compare(K a, K b)?}) Set<K>
Returns a Set of the map keys. The set will be sorted if the map's sort configuration is true, or if you explicitly provide a compare method.
toString([bool? prettyPrint]) String
Returns a string representation of (some of) the elements of this.
override
toValueIList({bool sort = false, int compare(V a, V b)?, ConfigList? config}) IList<V>
Returns an IList of the map values.
toValueISet({ConfigSet? config}) ISet<V>
Returns an ISet of the map values. Optionally, you may provide a config for the set.
toValueList({bool sort = false, int compare(V a, V b)?}) List<V>
Returns a List of the map values.
toValueSet({int compare(V a, V b)?}) Set<V>
Returns a Set of the map values. The set will be sorted if the map's sortValues configuration is true, or if you explicitly provide a compare method.
update(K key, V update(V value), {bool ifRemove(K key, V value)?, V ifAbsent()?, Output<V>? previousValue}) IMap<K, V>
Updates the value for the provided key.
updateAll(V update(K key, V value), {bool ifRemove(K key, V value)?}) IMap<K, V>
Updates all values.
where(bool test(K key, V value)) IMap<K, V>
Returns an IMap with all elements that satisfy the predicate test.
withConfig(ConfigMap config) IMap<K, V>
Creates a new map with the given config.
withConfigFrom(IMap<K, V> other) IMap<K, V>
Returns a new map with the contents of the present IMap, but the config of other.

Operators

operator ==(Object other) bool
  • If isDeepEquals configuration is true: Will return true 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 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
    operator [](K k) → V?
    Returns the value for the given key or null if key is not in the map.

    Static Properties

    defaultConfig ConfigMap
    Global configuration that specifies if, by default, the IMaps use equality or identity for their operator ==. By default isDeepEquals: true (maps are compared by equality), and sortKeys: true and sortValues: true (certain map outputs are sorted).
    getter/setter pair
    flushFactor int
    Indicates the number of operations an IMap may perform before it is eligible for auto-flush. Must be larger than 0.
    getter/setter pair

    Static Methods

    empty<K, V>([ConfigMap? config]) IMap<K, V>
    Returns an empty IMap, 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)?, ConfigMap? config}) IMap<K, V>
    Creates an IMap instance in which the keys and values are computed from the iterable.
    orNull<K, V>(Map<K, V>? map, [ConfigMap? config]) IMap<K, V>?
    If Map is null, return null.
    resetAllConfigurations() → void
    See also: ImmutableCollection, ImmutableCollection.lockConfig, ImmutableCollection.isConfigLocked,flushFactor, defaultConfig
    override