ListMap<K, V> class
A ListMap is a mutable, fixed-sized, and ordered map.
Compared to a LinkedHashMap, a ListMap is also ordered and has a slightly worse performance. But a ListMap takes less memory, and has some List methods like sort and shuffle. Also, you can efficiently read its information by index, by using the entryAt, keyAt and valueAt methods.
The disadvantage, of course, is that ListMap has a fixed size, while a LinkedHashMap does not.
- Implemented types
-
- Map<
K, V>
- Map<
- Available extensions
Constructors
- ListMap.empty()
-
ListMap.fromEntries(Iterable<
MapEntry< entries, {bool sort = false, int compare(K a, K b)?})K, V> > -
Creates a ListMap from
entries. Ifentriescontains the same keys multiple times, the last occurrence overwrites the previous value.factory -
ListMap.fromIterables(Iterable<
K> keys, Iterable<V> values, {bool sort = false, int compare(K a, K b)?}) -
Creates a ListMap from the provided
keysandvalues. If a key is repeated, the last occurrence overwrites the previous value.factory -
ListMap.of(Map<
K, V> map, {bool sort = false, int compare(K a, K b)?}) -
Create a ListMap from the
map. -
ListMap.unsafe(Map<
K, V> _map, {bool sort = false, int compare(K a, K b)?}) - Creates a ListMap backed by the provided map. No defensive copy will be made, so you have to make sure that the original map won't change after the ListMap is created, since this will render the ListMap in an invalid state.
-
ListMap.unsafeFrom({required Map<
K, V> map, required List<K> list}) -
Creates a ListMap backed by the provided
mapandlist. No defensive copies will be made, so you have to make sure that:
Properties
-
entries
→ Iterable<
MapEntry< K, V> > -
The map entries of this Map.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Whether there is no key/value pair in the map.
no setteroverride
- isNotEmpty → bool
-
Whether there is at least one key/value pair in the map.
no setteroverride
-
keys
→ Iterable<
K> -
The keys of this Map.
no setteroverride
- length → int
-
The number of key/value pairs in the map.
no setteroverride
-
lock
→ IMap<
K, V> -
Available on Map<
Locks the map, returning an immutable map (IMap).K, V> , provided by the FicMapExtension extensionno setter -
lock
→ IMapOfSets<
K, V> -
Available on Map<
Locks the map of sets, returning an immutable map (IMapOfSets).K, Set< , provided by the FicMapOfSetsExtension extensionV> >no setter -
lockUnsafe
→ IMap<
K, V> -
Available on Map<
Locks the map, returning an immutable map (IMap).K, V> , provided by the FicMapExtension extensionno setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
values
→ Iterable<
V> -
The values of this Map.
no setteroverride
Methods
-
addAll(
Map< K, V> other) → void -
Adds all key/value pairs of
otherto this map.override -
addEntries(
Iterable< MapEntry< newEntries) → voidK, V> > -
Adds all key/value pairs of
newEntriesto this map.override -
cast<
RK, RV> () → ListMap< RK, RV> -
Provides a view of this map as having
RKkeys andRVinstances, if necessary.override -
clear(
) → void -
Removes all entries from the map.
override
-
containsKey(
Object? key) → bool -
Whether this map contains the given
key.override -
containsValue(
Object? value) → bool -
Whether this map contains the given
value.override -
entry(
K key) → MapEntry< K, V> -
Return the key/value entry for the given
key, or throws ifkeyis not in the map. -
entryAt(
int index) → MapEntry< K, V> -
Returns the
indexth entry. Theindexmust be non-negative and less than length. Index zero represents the first entry. -
entryOrNull(
K key) → MapEntry< K, V> ? -
Return the key/value entry for the given
key, ornullifkeyis not in the map. -
entryOrNullValue(
K key) → MapEntry< K, V?> -
Return the key/value entry for the given
key. If thekeyis not in the map, returnMapEntry(key, null). -
extract<
T> (K key) → Option< T> -
Available on Map<
Return an Option that conditionally accesses map keys, if they match the given type. Useful for accessing nested JSON.K, V> , provided by the MapExtension extension -
extractMap(
K key) → Option< Map< K, dynamic> > -
Available on Map<
Return an Option that conditionally accesses map keys, if they contain a map with the same key type. Useful for accessing nested JSON.K, V> , provided by the MapExtension extension -
forEach(
void f(K key, V value)) → void -
Applies
actionto each key/value pair of the map.override -
get(
covariant K key) → V? -
The value for the given
key, ornullifkeyis not in the map. -
getOrThrow(
K key) → V -
Returns the value if it exists, otherwise throws a
StateError. -
indexOfKey(
K key, [int start = 0]) → int -
The first index of
keyin this list. -
insert(
int index, K key, V value) → void -
Inserts
key/valueat positionindex. -
keyAt(
int index) → K -
Returns the
indexth key. Theindexmust be non-negative and less than length. Index zero represents the first key. -
lookup(
K key) → Option< V> -
Available on Map<
Return an Option that conditionally accesses map keys.K, V> , provided by the MapExtension extension -
map<
K2, V2> (MapEntry< K2, V2> f(K key, V value)) → Map<K2, V2> -
Returns a new map where all entries of this map are transformed by
the given
convertfunction.override -
mapTo<
T> (T mapper(K key, V value)) → Iterable< T> -
Available on Map<
Returns a new lazy Iterable with elements that are created by callingK, V> , provided by the FicMapExtension extensionmapperon each entry of thisMapin iteration order. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
putIfAbsent(
K key, V ifAbsent()) → V -
Look up the value of
key, or add a new entry if it isn't there.override -
remove(
Object? key) → V? -
Removes
keyand its associated value, if present, from the map.override -
removeWhere(
bool predicate(K key, V value)) → void -
Removes all entries of this map that satisfy the given
test.override -
shuffle(
[Random? random]) → void - Shuffles the keys of this map randomly.
-
sort(
[int compare(K a, K b)?]) → void - Sorts the keys of this map.
-
toIMap(
[ConfigMap? config]) → IMap< K, V> -
Available on Map<
Creates an immutable map (IMap) from the map.K, V> , provided by the FicMapExtension extension -
toIMapOfSets(
[ConfigMapOfSets? config]) → IMapOfSets< K, V> ? -
Available on Map<
Creates an immutable map of sets (IMapOfSets) from the map.K, Set< , provided by the FicMapOfSetsExtension extensionV> > -
toString(
) → String -
A string representation of this object.
inherited
-
update(
K key, V update(V value), {V ifAbsent()?}) → V -
Updates the value for the provided
key.override -
updateAll(
V update(K key, V value)) → void -
Updates all values.
override
-
valueAt(
int index) → V -
Returns the
indexth value. Theindexmust be non-negative and less than length. Index zero represents the first value.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
covariant K key) → V? -
The value for the given
key, ornullifkeyis not in the map.override -
operator []=(
K key, V value) → void -
Replaces the
valueof akeythat already exists in the map. However, if the key is not already present, this will throw an error.override
Static Methods
-
unsafeView<
K, V> (Map< K, V> map) → ListMap<K, V> -
Creates a ListMap form the given
map. If themapis already of type ListMap, return the same instance. This is unsafe because a ListMapView is fixed size, but the givenmapmay not.