scala.collection.mutable

class ImmutableMapAdaptor

[source: scala/collection/mutable/ImmutableMapAdaptor.scala]

@serializable

class ImmutableMapAdaptor[A, B](protected val imap : Map[A, B])
extends Map[A, B]
This class can be used as an adaptor to create mutable maps from immutable map implementations. Only method empty has to be redefined if the immutable map on which this mutable map is originally based is not empty. empty is supposed to return the representation of an empty map.
Author
Matthias Zenger
Martin Odersky
Version
2.0, 01/01/2007
Since
1
Method Summary
def += (kv : (A, B)) : ImmutableMapAdaptor[A, B]
Add a new key/value mapping this map.
def -= (key : A) : ImmutableMapAdaptor[A, B]
Delete a key from this map if it is present.
override 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.
override def clear : Unit
Removes all elements from the set. After this operation is completed, the set will be empty.
override def contains (key : A) : Boolean
Is the given key mapped to a value by this map?
override def elements : Iterator[(A, B)]
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.
override 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?
def iterator : Iterator[(A, B)]
An iterator yielding all key/value mappings of this map.
override def keySet : Set[A]
override def keys : Iterator[A]
Creates an iterator for all keys.
override def keysIterator : Iterator[A]
Creates an iterator for all keys.
override def retain (p : (A, B) => Boolean) : ImmutableMapAdaptor[A, B]
Retain only those mappings for which the predicate p returns true.
override def size : Int
The number of elements in this collection
override def toList : List[(A, B)]
Returns a list with all elements of this traversable object.
override def toString : java.lang.String
Need to override string, so that it's not the Function1's string that gets mixed in.
override def transform (f : (A, B) => B) : ImmutableMapAdaptor[A, B]
This function transforms all the values of mappings contained in this map with function f.
override def update (key : A, value : B) : Unit
Adds a new mapping from key to value to the map. If the map already contains a mapping for key, it will be overridden.
override def values : Iterator[B]
Creates an iterator for a contained values.
override def valuesIterable : Iterable[B]
override def valuesIterator : Iterator[B]
Creates an iterator for a contained values.
Methods inherited from Map
empty
Methods inherited from MapLike
newBuilder, put, updated, cached, +, +, ++, ++, remove, -, removeKey, getOrElseUpdate, clone, result, -, --, --
Methods inherited from Shrinkable
-=, --=, --=
Methods inherited from Builder
sizeHint, mapResult
Methods inherited from Growable
+=, ++=, ++=
Methods inherited from MapLikeBase
+
Methods inherited from MapLike
getOrElse, default, filterKeys, mapValues, mapElements, +, ++, ++, addString, stringPrefix, hashCode, equals
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from Iterable
companion
Methods inherited from IterableLike
thisCollection, toCollection, 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 GenericTraversableTemplate
genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableLike
repr, nonEmpty, 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, toSeq, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, withFilter
Methods inherited from AnyRef
getClass, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
override def size : Int
The number of elements in this collection

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.
Parameters
key - the key of the mapping of interest.
Returns
the value of the mapping as an option, if it exists, or None.

override def isEmpty : Boolean
Is this an empty map?
Returns
true iff the map does not contain any key/value mapping.

override 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.
Parameters
key - the key
Returns
the value associated with the given key.

override def contains(key : A) : Boolean
Is the given key mapped to a value by this map?
Parameters
key - the key
Returns
true iff there is a mapping for key in this map

override def isDefinedAt(key : A) : Boolean
Does this map contain a mapping from the given key to a value?
Parameters
key - the key
Returns
true iff there is a mapping for key in this map

override def keySet : Set[A]
Returns
the keys of this map as a set.

override def keysIterator : Iterator[A]
Creates an iterator for all keys.
Returns
an iterator over all keys.

@deprecated("use `keysIterator' instead")

override def keys : Iterator[A]
Creates an iterator for all keys.
Returns
an iterator over all keys.

override def valuesIterable : Iterable[B]
Returns
the values of this map as an iterable.

override def valuesIterator : Iterator[B]
Creates an iterator for a contained values.
Returns
an iterator over all values.

@deprecated("use `valuesIterator' instead")

override def values : Iterator[B]
Creates an iterator for a contained values.
Returns
an iterator over all values.

def iterator : Iterator[(A, B)]
An iterator yielding all key/value mappings of this map.

@deprecated("use `iterator' instead")

override def elements : Iterator[(A, B)]

override def toList : List[(A, B)]
Returns a list with all elements of this traversable object.
Notes
Will not terminate for infinite-sized collections.

override def update(key : A, value : B) : Unit
Adds a new mapping from key to value to the map. If the map already contains a mapping for key, it will be overridden.
Parameters
key - The key to update
value - The new value
Returns
An option consisting of value associated previously associated with `key` in the map, or None if `key` was not yet defined in the map.

def -=(key : A) : ImmutableMapAdaptor[A, B]
Delete a key from this map if it is present.
Parameters
key - the key to be removed
Notes
same as `delete`.

def +=(kv : (A, B)) : ImmutableMapAdaptor[A, B]
Add a new key/value mapping this map.
Parameters
kv - the key/value pair.
Returns
the map itself

override def clear : Unit
Removes all elements from the set. After this operation is completed, the set will be empty.

override def transform(f : (A, B) => B) : ImmutableMapAdaptor[A, B]
This function transforms all the values of mappings contained in this map with function f.
Parameters
f - The transformation to apply

override def retain(p : (A, B) => Boolean) : ImmutableMapAdaptor[A, B]
Retain only those mappings for which the predicate p returns true.
Parameters
p - The test predicate

override def toString : java.lang.String
Need to override string, so that it's not the Function1's string that gets mixed in.