in scala/collection
trait Map

trait Map[A,+B]()
extends Object
with ScalaObject
with PartialFunction[A,B]
with Iterable[Tuple2[A,B]]
Implementing classes or objects:
trait MapProxy[A,+B]()
trait Map[A,B]() in scala/collection/mutable
trait Map[A,B]() in scala/collection/immutable

This trait defines the interface of collections that unambiguously map keys to values (i.e. a key is mapped to at least one value). Trait Map may only be used for accessing elements from map implementations. Two different extensions of trait Map in the package scala.collections.mutable and scala.collections.immutable provide functionality for adding new key/value mappings to a map. The trait in the first package is implemented by maps that are modified destructively, whereas the trait in the second package is used by functional map implementations that rely on immutable data structures.
Author:
Matthias Zenger
Version:
1.1, 02/05/2004

Method Summary
  def apply(key: A): B
     Retrieve the value which is associated with the given key.
  def contains(key: A): Boolean
     Is the given key mapped to a value by this map?
override def equals(that: Any): Boolean
     Compares two maps structurally; i.e.
  def exists(p: (A,B) => Boolean): Boolean
     Applies the given predicate to all (key, value) mappings contained in this map and returns true if there is at least one mapping for which this predicate yields true.
  def exists(p: (A) => Boolean): Boolean
     Apply a predicate p to all elements of this iterable object and return true, iff there is at least one element for which p yields true.
  def forall(p: (A,B) => Boolean): Boolean
     Applies the given predicate to all (key, value) mappings contained in this map and returns true if this predicate yields true for all mappings.
  def forall(p: (A) => Boolean): Boolean
     Apply a predicate p to all elements of this iterable object and return true, iff the predicate yields true for all elements.
  def foreach(f: (A,B) => Unit): Unit
     Executes the given function for all (key, value) pairs contained in this map.
  def foreach(f: (A) => Unit): Unit
     Apply a function f to all elements of this iterable object.
abstract def get(key: A): Option[B]
     Check if this map maps key to a value and return the value if it exists.
  def isDefinedAt(key: A): Boolean
     Does this map contain a mapping from the given key to a value?
  def isEmpty: Boolean
     Is this an empty map?
  def keys: Iterator[A]
     Creates an iterator for all keys.
abstract def size: Int
     Compute the number of key-to-value mappings.
  def toList: List[Tuple2[A,B]]
     Returns the mappings of this map as a list.
override def toString(): String
     Creates a string representation for this map.
  def values: Iterator[B]
     Creates an iterator for a contained values.

Methods inherited from java/lang/Object-class
clone, eq, finalize, getClass, hashCode, ne, notify, notifyAll, synchronized, wait, wait, wait

Methods inherited from scala/Any-class
!=, ==, asInstanceOf, isInstanceOf, match

Methods inherited from scala/Iterable-class
/:, :\, concat, elements, exists, find, foldLeft, foldRight, forall, foreach, sameElements

Methods inherited from scala/ScalaObject-class
getScalaType

Method Detail

size

  abstract def size: Int
Compute the number of key-to-value mappings.
Returns:
the number of mappings

get

  abstract def get(key: A): Option[B]
Check if this map maps key to a value and return the value if it exists.
Parameters:
key - the key of the mapping of interest
Returns:
the value of the mapping, if it exists

isEmpty

  def isEmpty: Boolean
Is this an empty map?
Returns:
true, iff the map is empty.

apply

  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.

contains

  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

isDefinedAt

  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

keys

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

values

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

foreach

  def foreach(f: (A,B) => Unit): Unit
Executes the given function for all (key, value) pairs contained in this map.
Parameters:
f - the function to execute.

foreach

  def foreach(f: (A) => Unit): Unit
Apply a function f to all elements of this iterable object.
Parameters:
f - a function that is applied to every element.

forall

  def forall(p: (A,B) => Boolean): Boolean
Applies the given predicate to all (key, value) mappings contained in this map and returns true if this predicate yields true for all mappings.
Parameters:
p - the predicate
Returns:
true, iff p yields true for all mappings.

forall

  def forall(p: (A) => Boolean): Boolean
Apply a predicate p to all elements of this iterable object and return true, iff the predicate yields true for all elements.
Parameters:
p - the predicate
Returns:
true, iff the predicate yields true for all elements.

exists

  def exists(p: (A,B) => Boolean): Boolean
Applies the given predicate to all (key, value) mappings contained in this map and returns true if there is at least one mapping for which this predicate yields true.
Parameters:
p - the predicate
Returns:
true, iff there is at least one mapping for which p yields true.

exists

  def exists(p: (A) => Boolean): Boolean
Apply a predicate p to all elements of this iterable object and return true, iff there is at least one element for which p yields true.
Parameters:
p - the predicate
Returns:
true, iff the predicate yields true for at least one element.

equals

  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.
Returns:
true, iff both maps contain exactly the same mappings.

toList

  def toList: List[Tuple2[A,B]]
Returns the mappings of this map as a list.
Returns:
a list containing all mappings

toString

  override def toString(): String
Creates a string representation for this map.
Returns:
a string showing all mappings