@@ -29,10 +29,78 @@ trait GenMapLike[A, +B, +Repr] extends GenIterableLike[(A, B), Repr] with Equals
29
29
def + [B1 >: B ](kv : (A , B1 )): GenMap [A , B1 ]
30
30
def - (key : A ): Repr
31
31
32
+
32
33
// This hash code must be symmetric in the contents but ought not
33
34
// collide trivially.
34
35
override def hashCode () = util.MurmurHash3 .symmetricHash(seq, Map .hashSeed)
36
+
37
+ /** Returns the value associated with a key, or a default value if the key is not contained in the map.
38
+ * @param key the key.
39
+ * @param default a computation that yields a default value in case no binding for `key` is
40
+ * found in the map.
41
+ * @tparam B1 the result type of the default computation.
42
+ * @return the value associated with `key` if it exists,
43
+ * otherwise the result of the `default` computation.
44
+ * @usecase def getOrElse(key: A, default: => B): B
45
+ */
46
+ def getOrElse [B1 >: B ](key : A , default : => B1 ): B1
47
+
48
+ /** Tests whether this map contains a binding for a key.
49
+ *
50
+ * @param key the key
51
+ * @return `true` if there is a binding for `key` in this map, `false` otherwise.
52
+ */
53
+ def contains (key : A ): Boolean
35
54
55
+ /** Tests whether this map contains a binding for a key. This method,
56
+ * which implements an abstract method of trait `PartialFunction`,
57
+ * is equivalent to `contains`.
58
+ *
59
+ * @param key the key
60
+ * @return `true` if there is a binding for `key` in this map, `false` otherwise.
61
+ */
62
+ def isDefinedAt (key : A ): Boolean
63
+
64
+ def keySet : GenSet [A ]
65
+
66
+ /** Collects all keys of this map in an iterable collection.
67
+ *
68
+ * @return the keys of this map as an iterable.
69
+ */
70
+ def keys : GenIterable [A ]
71
+
72
+ /** Collects all values of this map in an iterable collection.
73
+ *
74
+ * @return the values of this map as an iterable.
75
+ */
76
+ def values : GenIterable [B ]
77
+
78
+ /** Creates an iterator for all keys.
79
+ *
80
+ * @return an iterator over all keys.
81
+ */
82
+ def keysIterator : Iterator [A ]
83
+
84
+ /** Creates an iterator for all values in this map.
85
+ *
86
+ * @return an iterator over all values that are associated with some key in this map.
87
+ */
88
+ def valuesIterator : Iterator [B ]
89
+
90
+ /** Filters this map by retaining only keys satisfying a predicate.
91
+ * @param p the predicate used to test keys
92
+ * @return an immutable map consisting only of those key value pairs of this map where the key satisfies
93
+ * the predicate `p`. The resulting map wraps the original map without copying any elements.
94
+ */
95
+ def filterKeys (p : A => Boolean ): GenMap [A , B ]
96
+
97
+ /** Transforms this map by applying a function to every retrieved value.
98
+ * @param f the function used to transform values of this map.
99
+ * @return a map view which maps every key of this map
100
+ * to `f(this(key))`. The resulting map wraps the original map without copying any elements.
101
+ */
102
+ def mapValues [C ](f : B => C ): GenMap [A , C ]
103
+
36
104
/** Compares two maps structurally; i.e. checks if all mappings
37
105
* contained in this map are also contained in the other map,
38
106
* and vice versa.
@@ -42,21 +110,21 @@ trait GenMapLike[A, +B, +Repr] extends GenIterableLike[(A, B), Repr] with Equals
42
110
* same mappings, `false` otherwise.
43
111
*/
44
112
override def equals (that : Any ): Boolean = that match {
45
- case that : GenMap [b, _] =>
113
+ case that : GenMap [b, _] =>
46
114
(this eq that) ||
47
115
(that canEqual this ) &&
48
116
(this .size == that.size) && {
49
117
try {
50
- this forall {
118
+ this forall {
51
119
case (k, v) => that.get(k.asInstanceOf [b]) match {
52
120
case Some (`v`) =>
53
121
true
54
122
case _ => false
55
123
}
56
124
}
57
- } catch {
58
- case ex : ClassCastException =>
59
- false
125
+ } catch {
126
+ case ex : ClassCastException =>
127
+ println( " class cast " ); false
60
128
}}
61
129
case _ =>
62
130
false
0 commit comments