Classes and utilities that supplement the collection support in dart:core.
A Queue
implementation based on a double-linked list.
Allows constant time add, remove-at-ends and peek operations.
Can do removeAll
and retainAll
in linear time.
Adds value
at the end of the queue.
Adds all elements of iterable
at the end of the queue. The length of the queue is extended by the length of iterable
.
Adds value
at the beginning of the queue.
Adds value
at the end of the queue.
Removes all elements in the queue. The size of the queue becomes zero.
Remove a single instance of value
from the queue.
Returns true
if a value was removed, or false
if the queue contained no element equal to value
.
Removes and returns the first element of this queue. Throws an StateError
exception if this queue is empty.
Removes and returns the last element of the queue. Throws an StateError
exception if this queue is empty.
Returns a string representation of this object.
An entry in a doubly linked list. It contains a pointer to the next entry, the previous entry, and the boxed element.
WARNING: This class is temporary located in dart:core. It'll be removed at some point in the near future.
The HasNextIterator
class wraps an Iterator
and provides methods to iterate over an object using hasNext
and next
.
An HasNextIterator
does not implement the Iterator
interface.
A hash-table based implementation of Map
.
The keys of a HashMap
must have consistent Object.operator==
and Object.hashCode
implementations. This means that the ==
operator must define a stable equivalence relation on the keys (reflexive, anti-symmetric, transitive, and consistent over time), and that hashCode
must be the same for objects that are considered equal by ==
.
The map allows null
as a key.
Creates a hash-table based Map
.
The created map is not ordered in any way. When iterating the keys or values, the iteration order is unspecified except that it will stay the same as long as the map isn't changed.
If equals
is provided, it is used to compare the keys in the table with new keys. If equals
is omitted, the key's own Object.operator==
is used instead.
Similar, if hashCode
is provided, it is used to produce a hash value for keys in order to place them in the hash table. If it is omitted, the key's own Object.hashCode
is used.
If using methods like operator[
], remove
and containsKey
together with a custom equality and hashcode, an extra isValidKey
function can be supplied. This function is called before calling equals
or hashCode
with an argument that may not be a K
instance, and if the call returns false, the key is assumed to not be in the set. The isValidKey
function defaults to just testing if the object is a K
instance.
The used equals
and hashCode
method should always be consistent, so that if equals(a, b)
then hashCode(a) == hashCode(b)
. The hash of an object, or what it compares equal to, should not change while the object is in the table. If it does change, the result is unpredictable.
It is generally the case that if you supply one of equals
and hashCode
, you also want to supply the other. The only common exception is to pass identical
as the equality and use the default hash code.
Creates a HashMap
that contains all key value pairs of other
.
Creates a HashMap
where the keys and values are computed from the iterable
.
For each element of the iterable
this constructor computes a key/value pair, by applying key
and value
respectively.
The keys of the key/value pairs do not need to be unique. The last occurrence of a key will simply overwrite any previous value.
If no values are specified for key
and value
the default is the identity function.
Creates a HashMap
associating the given keys
to values
.
This constructor iterates over keys
and values
and maps each element of keys
to the corresponding element of values
.
If keys
contains the same object multiple times, the last occurrence overwrites the previous value.
It is an error if the two Iterable
s don't have the same length.
A HashSet
is a hash-table based Set
implementation.
The elements of a HashSet
must have consistent equality and hashCode implementations. This means that the equals operation must define a stable equivalence relation on the elements (reflexive, anti-symmetric, transitive, and consistent over time), and that the hashCode must consistent with equality, so that the same for objects that are considered equal.
The set allows null
as an element.
Most simple operations on HashSet
are done in constant time: add
, contains
, remove
, and length
.
Create a hash set using the provided equals
as equality.
The provided equals
must define a stable equivalence relation, and hashCode
must be consistent with equals
. If the equals
or hashCode
methods won't work on all objects, but only to instances of E, the isValidKey
predicate can be used to restrict the keys that they are applied to. Any key for which isValidKey
returns false is automatically assumed to not be in the set.
If equals
, hashCode
and isValidKey
are omitted, the set uses the objects' intrinsic Object.operator==
and Object.hashCode
.
If isValidKey
is omitted, it defaults to testing if the object is an E
instance.
If equals
is identical
, this creates an identity set. Any hashCode is compatible with identical
, and it applies to all objects, so hashCode
and isValidKey
can safely be omitted.
Create a hash set containing the elements of iterable
.
Creates a hash set as by new HashSet<E>()
and adds each element of iterable
to this set in the order they are iterated.
Base class for implementing Iterable
.
This class implements all methods of Iterable
except Iterable.iterator
in terms of iterator
.
Returns true if one element of this collection satisfies the predicate test
. Returns false otherwise.
Returns true if the collection contains an element equal to element
.
Returns the index
th element.
If this
has fewer than index
elements throws a RangeError
.
Note: if this
does not have a deterministic iteration order then the function may simply return any element without any iteration if there are at least index
elements in this
.
Returns true if every elements of this collection satisify the predicate test
. Returns false
otherwise.
Expands each element of this Iterable
into zero or more elements.
The resulting Iterable runs through the elements returned by f
for each element of this, in order.
The returned Iterable
is lazy, and calls f
for each element of this every time it's iterated.
Returns the first element that satisfies the given predicate test
.
If none matches, the result of invoking the orElse
function is returned. By default, when orElse
is null
, a StateError
is thrown.
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value using the provided function.
Use initialValue
as the initial value, and the function combine
to create a new value from the previous one and an element.
Example of calculating the sum of an iterable:
iterable.fold(0, (prev, element) => prev + element);
Applies the function f
to each element of this collection.
Converts each element to a String
and concatenates the strings.
Converts each element to a String
by calling Object.toString
on it. Then concatenates the strings, optionally separated by the separator
string.
Returns the last element that satisfies the given predicate test
.
If none matches, the result of invoking the orElse
function is returned. By default, when orElse
is null
, a StateError
is thrown.
Returns a lazy Iterable
where each element e
of this
is replaced by the result of f(e)
.
This method returns a view of the mapped elements. As long as the returned Iterable
is not iterated over, the supplied function f
will not be invoked. The transformed elements will not be cached. Iterating multiple times over the the returned Iterable
will invoke the supplied function f
multiple times on the same element.
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
Example of calculating the sum of an iterable:
iterable.reduce((value, element) => value + element);
Returns the single element that satisfies test
. If no or more than one element match then a StateError
is thrown.
Returns an Iterable that skips the first n
elements.
If this
has fewer than n
elements, then the resulting Iterable is empty.
It is an error if n
is negative.
Returns an Iterable that skips elements while test
is satisfied.
The filtering happens lazily. Every new Iterator of the returned Iterable iterates over all elements of this
.
As long as the iterator's elements satisfy test
they are discarded. Once an element does not satisfy the test
the iterator stops testing and uses every later element unconditionally. That is, the elements of the returned Iterable are the elements of this
starting from the first element that does not satisfy test
.
Returns an Iterable
with at most n
elements.
The returned Iterable
may contain fewer than n
elements, if this
contains fewer than n
elements.
It is an error if n
is negative.
Returns an Iterable that stops once test
is not satisfied anymore.
The filtering happens lazily. Every new Iterator of the returned Iterable starts iterating over the elements of this
.
When the iterator encounters an element e
that does not satisfy test
, it discards e
and moves into the finished state. That is, it does not get or provide any more elements.
Creates a List
containing the elements of this Iterable
.
The elements are in iteration order. The list is fixed-length if growable
is false.
Creates a Set
containing the elements of this Iterable
.
Returns a lazy Iterable
with all elements that satisfy the predicate test
.
This method returns a view of the mapped elements. As long as the returned Iterable
is not iterated over, the supplied function test
will not be invoked. Iterating will not cache results, and thus iterating multiple times over the returned Iterable
will invoke the supplied function test
multiple times on the same element.
This Iterable
mixin implements all Iterable
members except iterator
.
All other methods are implemented in terms of iterator
.
Returns true if one element of this collection satisfies the predicate test
. Returns false otherwise.
Returns true if the collection contains an element equal to element
.
Returns the index
th element.
If this
has fewer than index
elements throws a RangeError
.
Note: if this
does not have a deterministic iteration order then the function may simply return any element without any iteration if there are at least index
elements in this
.
Returns true if every elements of this collection satisify the predicate test
. Returns false
otherwise.
Expands each element of this Iterable
into zero or more elements.
The resulting Iterable runs through the elements returned by f
for each element of this, in order.
The returned Iterable
is lazy, and calls f
for each element of this every time it's iterated.
Returns the first element that satisfies the given predicate test
.
If none matches, the result of invoking the orElse
function is returned. By default, when orElse
is null
, a StateError
is thrown.
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value using the provided function.
Use initialValue
as the initial value, and the function combine
to create a new value from the previous one and an element.
Example of calculating the sum of an iterable:
iterable.fold(0, (prev, element) => prev + element);
Applies the function f
to each element of this collection.
Converts each element to a String
and concatenates the strings.
Converts each element to a String
by calling Object.toString
on it. Then concatenates the strings, optionally separated by the separator
string.
Returns the last element that satisfies the given predicate test
.
If none matches, the result of invoking the orElse
function is returned. By default, when orElse
is null
, a StateError
is thrown.
Returns a lazy Iterable
where each element e
of this
is replaced by the result of f(e)
.
This method returns a view of the mapped elements. As long as the returned Iterable
is not iterated over, the supplied function f
will not be invoked. The transformed elements will not be cached. Iterating multiple times over the the returned Iterable
will invoke the supplied function f
multiple times on the same element.
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
Example of calculating the sum of an iterable:
iterable.reduce((value, element) => value + element);
Returns the single element that satisfies test
. If no or more than one element match then a StateError
is thrown.
Returns an Iterable that skips the first n
elements.
If this
has fewer than n
elements, then the resulting Iterable is empty.
It is an error if n
is negative.
Returns an Iterable that skips elements while test
is satisfied.
The filtering happens lazily. Every new Iterator of the returned Iterable iterates over all elements of this
.
As long as the iterator's elements satisfy test
they are discarded. Once an element does not satisfy the test
the iterator stops testing and uses every later element unconditionally. That is, the elements of the returned Iterable are the elements of this
starting from the first element that does not satisfy test
.
Returns an Iterable
with at most n
elements.
The returned Iterable
may contain fewer than n
elements, if this
contains fewer than n
elements.
It is an error if n
is negative.
Returns an Iterable that stops once test
is not satisfied anymore.
The filtering happens lazily. Every new Iterator of the returned Iterable starts iterating over the elements of this
.
When the iterator encounters an element e
that does not satisfy test
, it discards e
and moves into the finished state. That is, it does not get or provide any more elements.
Creates a List
containing the elements of this Iterable
.
The elements are in iteration order. The list is fixed-length if growable
is false.
Creates a Set
containing the elements of this Iterable
.
Returns a lazy Iterable
with all elements that satisfy the predicate test
.
This method returns a view of the mapped elements. As long as the returned Iterable
is not iterated over, the supplied function test
will not be invoked. Iterating will not cache results, and thus iterating multiple times over the returned Iterable
will invoke the supplied function test
multiple times on the same element.
A hash-table based implementation of Map
.
Keys insertion order is remembered, and keys are iterated in insertion order. Values are iterated in their corresponding key's order.
The keys of a LinkedHashMap
must have consistent Object.operator==
and Object.hashCode
implementations. This means that the ==
operator must define a stable equivalence relation on the keys (reflexive, anti-symmetric, transitive, and consistent over time), and that hashCode
must be the same for objects that are considered equal by ==
.
The map allows null
as a key.
Creates a LinkedHashMap
that contains all key value pairs of other
.
Creates a LinkedHashMap
where the keys and values are computed from the iterable
.
For each element of the iterable
this constructor computes a key/value pair, by applying key
and value
respectively.
The keys of the key/value pairs do not need to be unique. The last occurrence of a key will simply overwrite any previous value.
If no values are specified for key
and value
the default is the identity function.
Creates a LinkedHashMap
associating the given keys
to values
.
This constructor iterates over keys
and values
and maps each element of keys
to the corresponding element of values
.
If keys
contains the same object multiple times, the last occurrence overwrites the previous value.
It is an error if the two Iterable
s don't have the same length.
A LinkedHashSet
is a hash-table based Set
implementation.
The LinkedHashSet
also keep track of the order that elements were inserted in, and iteration happens in first-to-last insertion order.
The elements of a LinkedHashSet
must have consistent Object.operator==
and Object.hashCode
implementations. This means that the ==
operator must define a stable equivalence relation on the elements (reflexive, anti-symmetric, transitive, and consistent over time), and that hashCode
must be the same for objects that are considered equal by ==
.
The set allows null
as an element.
Most simple operations on HashSet
are done in constant time: add
, contains
, remove
, and length
.
A linked list implementation, providing O(1) removal(unlink) of elements and manual traversal through next
and previous
.
The list elements must extend LinkedListEntry
.
Construct a new empty linked list.
Add entry
to the end of the list.
Add entries
to the end of the list.
Add entry
to the beginning of the list.
Call action
with each entry in the list.
It's an error if action
modify the list.
Remove entry
from the list. This is the same as calling entry.unlink()
.
If entry
is not in the list, false
is returned.
Returns a string representation of this object.
Entry element for a LinkedList
. Any entry must extend this class.
Get the list containing this element.
Return the succeeding element in the list.
Return the preceeding element in the list.
insert an element after this.
Insert an element before this.
Unlink the element from the list.
Abstract implementation of a list.
All operations are defined in terms of length
, operatorListBase()
, operatorListBase()=
and length=
, which need to be implemented.
Base implementation of a List
class.
This class can be used as a mixin.
This implements all read operations using only the length
and operatorListMixin()
members. It implements write operations using those and length=
and operatorListMixin()=
Adds value
to the end of this list, extending the length by one.
Throws an UnsupportedError
if the list is fixed-length.
Appends all objects of iterable
to the end of this list.
Extends the length of the list by the number of objects in iterable
. Throws an UnsupportedError
if this list is fixed-length.
Returns true if one element of this collection satisfies the predicate test
. Returns false otherwise.
Returns an unmodifiable Map
view of this
.
The map uses the indices of this list as keys and the corresponding objects as values. The Map.keys
Iterable
iterates the indices of this list in numerical order.
Removes all objects from this list; the length of the list becomes zero.
Throws an UnsupportedError
, and retains all objects, if this is a fixed-length list.
Returns true if the collection contains an element equal to element
.
Returns the index
th element.
If this
has fewer than index
elements throws a RangeError
.
Note: if this
does not have a deterministic iteration order then the function may simply return any element without any iteration if there are at least index
elements in this
.
Returns true if every elements of this collection satisify the predicate test
. Returns false
otherwise.
Expands each element of this Iterable
into zero or more elements.
The resulting Iterable runs through the elements returned by f
for each element of this, in order.
The returned Iterable
is lazy, and calls f
for each element of this every time it's iterated.
Sets the objects in the range start
inclusive to end
exclusive to the given fillValue
.
An error occurs if start
..end
is not a valid range for this
.
Returns the first element that satisfies the given predicate test
.
If none matches, the result of invoking the orElse
function is returned. By default, when orElse
is null
, a StateError
is thrown.
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value using the provided function.
Use initialValue
as the initial value, and the function combine
to create a new value from the previous one and an element.
Example of calculating the sum of an iterable:
iterable.fold(0, (prev, element) => prev + element);
Applies the function f
to each element of this collection.
Returns an Iterable
that iterates over the objects in the range start
inclusive to end
exclusive.
An error occurs if end
is before start
.
An error occurs if the start
and end
are not valid ranges at the time of the call to this method. The returned Iterable
behaves like skip(start).take(end - start)
. That is, it does not throw exceptions if this
changes size.
Example:
var list = [1, 2, 3, 4, 5]; var range = list.getRange(1, 4); print(range.join(', ')); // => 2, 3, 4 list.length = 3; print(range.join(', ')); // => 2, 3
Returns the first index of element
in this list.
Searches the list from index start
to the length of the list. The first time an object o
is encountered so that o == element
, the index of o
is returned. Returns -1 if element
is not found.
Inserts the object at position index
in this list.
This increases the length of the list by one and shifts all objects at or after the index towards the end of the list.
An error occurs if the index
is less than 0 or greater than length. An UnsupportedError
occurs if the list is fixed-length.
Inserts all objects of iterable
at position index
in this list.
This increases the length of the list by the length of iterable
and shifts all later objects towards the end of the list.
An error occurs if the index
is less than 0 or greater than length. An UnsupportedError
occurs if the list is fixed-length.
Converts each element to a String
and concatenates the strings.
Converts each element to a String
by calling Object.toString
on it. Then concatenates the strings, optionally separated by the separator
string.
Returns the last index in the list a
of the given element
, starting the search at index startIndex
to 0. Returns -1 if element
is not found.
Returns the last element that satisfies the given predicate test
.
If none matches, the result of invoking the orElse
function is returned. By default, when orElse
is null
, a StateError
is thrown.
Returns a lazy Iterable
where each element e
of this
is replaced by the result of f(e)
.
This method returns a view of the mapped elements. As long as the returned Iterable
is not iterated over, the supplied function f
will not be invoked. The transformed elements will not be cached. Iterating multiple times over the the returned Iterable
will invoke the supplied function f
multiple times on the same element.
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
Example of calculating the sum of an iterable:
iterable.reduce((value, element) => value + element);
Removes the first occurence of value
from this list.
Returns true if value
was in the list. Returns false otherwise.
The method has no effect if value
was not in the list.
An UnsupportedError
occurs if the list is fixed-length.
Removes the object at position index
from this list.
This method reduces the length of this
by one and moves all later objects down by one position.
Returns the removed object.
ArgumentError
if index
is not an int
.RangeError
if the index
is out of range for this list.UnsupportedError
, and doesn't remove the object,Pops and returns the last object in this list.
Throws an UnsupportedError
if this is a fixed-length list.
Removes the objects in the range start
inclusive to end
exclusive.
An error occurs if start
..end
is not a valid range for this
. Throws an UnsupportedError
if this is a fixed-length list.
Removes all objects from this list that satisfy test
.
An object o
satisfies test
if test(o)
is true.
Throws an UnsupportedError
if this is a fixed-length list.
Removes the objects in the range start
inclusive to end
exclusive and replaces them with the contents of the iterable
.
An error occurs if start
..end
is not a valid range for this
.
Example:
var list = [1, 2, 3, 4, 5]; list.replaceRange(1, 3, [6, 7, 8, 9]); print(list); // [1, 6, 7, 8, 9, 4, 5]
Removes all objects from this list that fail to satisfy test
.
An object o
satisfies test
if test(o)
is true.
Throws an UnsupportedError
if this is a fixed-length list.
Overwrites objects of this
with the objects of iterable
, starting at position index
in this list.
This operation does not increase the length of this
.
An error occurs if the index
is less than 0 or greater than length. An error occurs if the iterable
is longer than length
- index
.
Copies the objects of iterable
, skipping skipCount
objects first, into the range start
inclusive to end
exclusive of this
.
If start
equals end
and start
..end
represents a legal range, this method has no effect.
An error occurs if start
..end
is not a valid range for this
. An error occurs if the iterable
does not have enough objects after skipping skipCount
objects.
Example:
var list = [1, 2, 3, 4]; var list2 = [5, 6, 7, 8, 9]; list.setRange(1, 3, list2, 3); print(list); // => [1, 8, 9, 4]
Returns the single element that satisfies test
. If no or more than one element match then a StateError
is thrown.
Returns an Iterable that skips the first n
elements.
If this
has fewer than n
elements, then the resulting Iterable is empty.
It is an error if n
is negative.
Returns an Iterable that skips elements while test
is satisfied.
The filtering happens lazily. Every new Iterator of the returned Iterable iterates over all elements of this
.
As long as the iterator's elements satisfy test
they are discarded. Once an element does not satisfy the test
the iterator stops testing and uses every later element unconditionally. That is, the elements of the returned Iterable are the elements of this
starting from the first element that does not satisfy test
.
Sorts this list according to the order specified by the compare
function.
The compare
function must act as a Comparator
.
The default List implementations use Comparable.compare
if compare
is omitted.
Returns a new list containing the objects from start
inclusive to end
exclusive.
If end
is omitted, the length
of this
is used.
An error occurs if start
is outside the range 0
.. length
or if end
is outside the range start
.. length
.
Returns an Iterable
with at most n
elements.
The returned Iterable
may contain fewer than n
elements, if this
contains fewer than n
elements.
It is an error if n
is negative.
Returns an Iterable that stops once test
is not satisfied anymore.
The filtering happens lazily. Every new Iterator of the returned Iterable starts iterating over the elements of this
.
When the iterator encounters an element e
that does not satisfy test
, it discards e
and moves into the finished state. That is, it does not get or provide any more elements.
Creates a List
containing the elements of this Iterable
.
The elements are in iteration order. The list is fixed-length if growable
is false.
Creates a Set
containing the elements of this Iterable
.
Returns a string representation of this object.
Returns a lazy Iterable
with all elements that satisfy the predicate test
.
This method returns a view of the mapped elements. As long as the returned Iterable
is not iterated over, the supplied function test
will not be invoked. Iterating will not cache results, and thus iterating multiple times over the returned Iterable
will invoke the supplied function test
multiple times on the same element.
List based Queue
.
Keeps a cyclic buffer of elements, and grows to a larger buffer when it fills up. This guarantees constant time peek and remove operations, and amortized constant time add operations.
The structure is efficient for any queue or stack usage.
Operations like removeAll
and removeWhere() are very inefficient. If those are needed, use a DoubleLinkedQueue
instead.
Create an empty queue.
If initialCapacity
is given, prepare the queue for at least that many elements.
Create a queue initially containing the elements of source
.
Adds value
at the end of the queue.
Adds all elements of iterable
at the end of the queue. The length of the queue is extended by the length of iterable
.
Adds value
at the beginning of the queue.
Adds value
at the end of the queue.
Removes all elements in the queue. The size of the queue becomes zero.
Returns the index
th element.
If this
has fewer than index
elements throws a RangeError
.
Note: if this
does not have a deterministic iteration order then the function may simply return any element without any iteration if there are at least index
elements in this
.
Applies the function f
to each element of this collection.
Remove a single instance of value
from the queue.
Returns true
if a value was removed, or false
if the queue contained no element equal to value
.
Removes and returns the first element of this queue. Throws an StateError
exception if this queue is empty.
Removes and returns the last element of the queue. Throws an StateError
exception if this queue is empty.
Remove all elements matched by test
.
This method is inefficient since it works by repeatedly removing single elements, each of which can take linear time.
Remove all elements not matched by test
.
This method is inefficient since it works by repeatedly removing single elements, each of which can take linear time.
Creates a List
containing the elements of this Iterable
.
The elements are in iteration order. The list is fixed-length if growable
is false.
Returns a string representation of this object.
Returns a string representing the specified map. The returned string looks like this: '{key0: value0, key1: value1, ... keyN: valueN}'
. The value returned by its toString
method is used to represent each key or value.
If the map collection contains a reference to itself, either directly as a key or value, or indirectly through other collections or maps, the contained reference is rendered as '{...}'
. This prevents the infinite regress that would otherwise occur. So, for example, calling this method on a map whose sole entry maps the string key 'me' to a reference to the map would return '{me: {...}}'
.
A typical implementation of a map's toString
method will simply return the results of this method applied to the collection.
A Queue
is a collection that can be manipulated at both ends. One can iterate over the elements of a queue through forEach
or with an Iterator
.
Creates a queue.
Creates a queue with the elements of other
. The order in the queue will be the order provided by the iterator of other
.
Adds value
at the end of the queue.
Adds all elements of iterable
at the end of the queue. The length of the queue is extended by the length of iterable
.
Adds value
at the beginning of the queue.
Adds value
at the end of the queue.
Removes all elements in the queue. The size of the queue becomes zero.
Remove a single instance of value
from the queue.
Returns true
if a value was removed, or false
if the queue contained no element equal to value
.
Removes and returns the first element of this queue. Throws an StateError
exception if this queue is empty.
Removes and returns the last element of the queue. Throws an StateError
exception if this queue is empty.
Creates a SplayTreeMap
that contains all key value pairs of other
.
Creates a SplayTreeMap
where the keys and values are computed from the iterable
.
For each element of the iterable
this constructor computes a key/value pair, by applying key
and value
respectively.
The keys of the key/value pairs do not need to be unique. The last occurrence of a key will simply overwrite any previous value.
If no values are specified for key
and value
the default is the identity function.
Creates a SplayTreeMap
associating the given keys
to values
.
This constructor iterates over keys
and values
and maps each element of keys
to the corresponding element of values
.
If keys
contains the same object multiple times, the last occurrence overwrites the previous value.
It is an error if the two Iterable
s don't have the same length.
Returns the value for the given key
or null if key
is not in the map. Because null values are supported, one should either use containsKey
to distinguish between an absent key and a null value, or use the putIfAbsent
method.
Associates the key
with the given value
.
Adds all key-value pairs of other
to this map.
If a key of other
is already in this map, its value is overwritten.
The operation is equivalent to doing this
for each key and associated value in other. It iterates over key
= valueother
, which must therefore not change during the iteration.
Removes all pairs from the map.
Returns true if this map contains the given key.
Returns true if this map contains the given value.
Get the first key in the map. Returns null
if the map is empty.
Get the first key in the map that is strictly larger than key
. Returns null
if no key was not found.
Applies f
to each {key, value} pair of the map.
It is an error to add or remove keys from the map during iteration.
Get the last key in the map. Returns null
if the map is empty.
Get the last key in the map that is strictly smaller than key
. Returns null
if no key was not found.
If key
is not associated to a value, calls ifAbsent
and updates the map by mapping key
to the value returned by ifAbsent
. Returns the value in the map.
It is an error to add or remove keys from the map during the call to ifAbsent
.
Removes the association for the given key
. Returns the value for key
in the map or null if key
is not in the map. Note that values can be null and a returned null value does not always imply that the key is absent.
Returns a string representation of this object.
An unmodifiable List
view of another List.
The source of the elements may be a List
or any Iterable
with efficient Iterable.length
and Iterable.elementAt
.
Create an unmodifiable list backed by source
.