|
Scala Library
|
|
scala/collection/MapLike.scala]
trait
MapLike[A, +B, +This <: MapLike[A, B, This] with Map[A, B]]
extends PartialFunction[A, B] with IterableLike[(A, B), This] with Subtractable[A, This]
A generic template for maps from keys of type A to values
of type B.
To implement a concrete map, you need to provide implementations of the
following methods (where This is the type of the map in
question):
def get(key: A): Option[B]
def iterator: Iterator[(A, B)]
def + [B1 >: B](kv: (A, B1)): This
def -(key: A): This
If you wish that methods like, take, drop,
filter return the same kind of map, you should also override:
def empty: This
It is also good idea to override methods foreach and
size for efficiency.
| Method Summary | |
abstract def
|
+
[B1 >: B](kv : (A, B1)) : Map[A, B1]
Add a key/value pair to this map, returning a new map.
|
def
|
+
[B1 >: B](elem1 : (A, B1), elem2 : (A, B1), elems : (A, B1)*) : Map[A, B1]
Adds two or more elements to this collection and returns
a new collection.
|
def
|
++
[B1 >: B](iter : Iterator[(A, B1)]) : Map[A, B1]
Adds a number of elements provided by an iterator
and returns a new collection with the added elements.
|
def
|
++
[B1 >: B](elems : Traversable[(A, B1)]) : Map[A, B1]
Adds a number of elements provided by a traversable object
and returns a new collection with the added elements.
|
abstract def
|
-
(key : A) : This
Removes a key from this map, returning a new map
|
override def
|
addString
(b : StringBuilder, start : java.lang.String, sep : java.lang.String, end : java.lang.String) : StringBuilder
Creates a string representation for this map.
|
def
|
apply
(key : A) : B
Retrieve the value which is associated with the given key. This
method throws an exception if there is no mapping from the given
key to a value.
|
def
|
contains
(key : A) : Boolean
Is the given key mapped to a value by this map?
|
def
|
default
(key : A) : B
The default value for the map, returned when a key is not found
The method implemented here yields an error,
but it might be overridden in subclasses.
|
abstract def
|
empty : This |
override def
|
equals
(that : Any) : Boolean
Compares two maps structurally; i.e. checks if all mappings
contained in this map are also contained in the other map,
and vice versa.
|
def
|
filterKeys
(p : (A) => Boolean) : DefaultMap[A, B]
A map view consisting only of those key value pairs where the key satisfies a given
predicate `p`.
|
abstract def
|
get
(key : A) : Option[B]
Check if this map maps
key to a value and return the
value as an option if it exists, None if not. |
def
|
getOrElse
[B1 >: B](key : A, default : => B1) : B1
Check if this map maps
key to a value.
Return that value if it exists, otherwise return default. |
override def
|
hashCode
: Int
Returns a hash code value for the object.
|
def
|
isDefinedAt
(key : A) : Boolean
Does this map contain a mapping from the given key to a value?
|
override def
|
isEmpty
: Boolean
Is this an empty map?
|
abstract def
|
iterator
: Iterator[(A, B)]
An iterator yielding all key/value mappings of this map.
|
def
|
keySet : Set[A] |
def
|
keys
: Iterator[A]
Creates an iterator for all keys.
|
def
|
keysIterator
: Iterator[A]
Creates an iterator for all keys.
|
def
|
mapElements [C](f : (B) => C) : DefaultMap[A, C] |
def
|
mapValues
[C](f : (B) => C) : DefaultMap[A, C]
A map view resulting from applying a given function `f` to each value
associated with a key in this map.
|
protected[this] override def
|
newBuilder
: Builder[(A, B), This]
A common implementation of `newBuilder` for all maps in terms of `empty`.
Overridden for mutable maps in `mutable.MapLike`.
|
override def
|
stringPrefix
: java.lang.String
Defines the prefix of this object's
toString representation.
!!! todo: remove stringPrefix overrides where possible |
override def
|
toString
: java.lang.String
Need to override string, so that it's not the Function1's string that gets mixed in.
|
def
|
updated
[B1 >: B](key : A, value : B1) : Map[A, B1]
A new immutable map containing updating this map with a given key/value mapping.
|
def
|
values
: Iterator[B]
Creates an iterator for a contained values.
|
def
|
valuesIterable : Iterable[B] |
def
|
valuesIterator
: Iterator[B]
Creates an iterator for a contained values.
|
| Methods inherited from Subtractable | |
| -, --, -- |
| Methods inherited from IterableLike | |
| thisCollection, toCollection, elements, foreach, forall, exists, find, foldRight, reduceRight, toIterable, head, take, slice, takeWhile, takeRight, dropRight, copyToArray, zip, zipAll, zipWithIndex, sameElements, toStream, canEqual, view, view, first, firstOption, projection |
| Methods inherited from TraversableLike | |
| repr, nonEmpty, size, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, count, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, tail, last, lastOption, init, drop, dropWhile, span, splitAt, copyToBuffer, copyToArray, toArray, toList, toSeq, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, withFilter |
| Methods inherited from PartialFunction | |
| orElse, andThen |
| Methods inherited from Function1 | |
| compose |
| Methods inherited from AnyRef | |
| getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
| Methods inherited from Any | |
| ==, !=, isInstanceOf, asInstanceOf |
| Class Summary | |
protected class
|
DefaultKeySet
extends Set[A]
|
protected class
|
DefaultValuesIterable
extends Iterable[B]
|
| Method Details |
abstract
def
empty : This
key to a value and return the
value as an option if it exists, None if not.key - the key of the mapping of interest.kv - the key/value pairkey - the key to be removedkeyoverride
def
isEmpty : Boolean
true iff the map does not contain any key/value mapping.key to a value.
Return that value if it exists, otherwise return default.key - the key.default - a computation that yields a default value in case no binding for the key is found in the map.key - the keykey - the keytrue iff there is a mapping for key in this mapkey - the keytrue iff there is a mapping for key in this map
def
keys : Iterator[A]
def
values : Iterator[B]
key - the given key value
def
filterKeys(p : (A) => Boolean) : DefaultMap[A, B]
def
mapValues[C](f : (B) => C) : DefaultMap[A, C]
def
mapElements[C](f : (B) => C) : DefaultMap[A, C]
key - the keyvalue - the valueelem1 - the first element to add.elem2 - the second element to add.elems - the remaining elements to add.elems - the traversable object.iter - the iteratoroverride
def
addString(b : StringBuilder, start : java.lang.String, sep : java.lang.String, end : java.lang.String) : StringBuilder
override
def
stringPrefix : java.lang.String
toString representation.
!!! todo: remove stringPrefix overrides where possibleoverride
def
toString : java.lang.String
override
def
hashCode : Int
The default hashing algorithm is platform dependent.
Note that it is allowed for two objects to have identical hash
codes (o1.hashCode.equals(o2.hashCode)) yet not be
equal (o1.equals(o2) returns false). A
degenerate implementation could always return 0.
However, it is required that if two objects are equal
(o1.equals(o2) returns true) that they
have identical hash codes
(o1.hashCode.equals(o2.hashCode)). Therefore, when
overriding this method, be sure to verify that the behavior is
consistent with the equals method.
that - the other maptrue iff both maps contain exactly the same mappings.|
Scala Library
|
|