summaryrefslogtreecommitdiff
path: root/src/dotnet-library/scala/collection/immutable/Map4.scala
blob: 35960081090c6d29b76832086890418bb1234503 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2007, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id: ListMap.scala 9554 2007-01-04 16:30:16 +0000 (Thu, 04 Jan 2007) odersky $

package scala.collection.immutable

import Predef._

/** This class implements empty immutable maps
 *  @author  Martin Oderskty
 *  @version 1.0, 019/01/2007
 */
[serializable]
class Map4[A, +B](key1: A, value1: B, key2: A, value2: B, key3: A, value3: B, key4: A, value4: B) extends Map[A, B] {

  def size = 4

  def get(key: A): Option[B] =
    if      (key == key1) Some(value1)
    else if (key == key2) Some(value2)
    else if (key == key3) Some(value3)
    else if (key == key4) Some(value4)
    else None

  def elements = Iterator.fromValues(
    {key1, value1}, {key2, value2}, {key3, value3}, {key4, value4})

  def empty[C]: Map[A, C] = new EmptyMap[A, C]

  def update [B1 >: B](key: A, value: B1): Map[A, B1] =
    if      (key == key1) new Map4(key1, value, key2, value2, key3, value3, key4, value4)
    else if (key == key2) new Map4(key1, value1, key2, value, key3, value3, key4, value4)
    else if (key == key3) new Map4(key1, value1, key2, value2, key3, value, key4, value4)
    else if (key == key4) new Map4(key1, value1, key2, value2, key3, value3, key4, value)
    else HashMap(key1 -> value1, key2 -> value2, key3 -> value3, key4 -> value4, key -> value)

  def - (key: A): Map[A, B] =
    if      (key == key1) new Map3(key2, value2, key3, value3, key4, value4)
    else if (key == key2) new Map3(key1, value1, key3, value3, key4, value4)
    else if (key == key3) new Map3(key1, value1, key2, value2, key4, value4)
    else if (key == key4) new Map3(key1, value1, key2, value2, key3, value3)
    else this
}