Skip to content

Commit efde7b9

Browse files
committed
Merge pull request scala#40 from gkossakowski/cleanups
Cleanups
2 parents 9c9e961 + dba8935 commit efde7b9

File tree

4 files changed

+75
-41
lines changed

4 files changed

+75
-41
lines changed

src/library/scala/collection/GenMapLike.scala

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,78 @@ trait GenMapLike[A, +B, +Repr] extends GenIterableLike[(A, B), Repr] with Equals
2929
def +[B1 >: B](kv: (A, B1)): GenMap[A, B1]
3030
def - (key: A): Repr
3131

32+
3233
// This hash code must be symmetric in the contents but ought not
3334
// collide trivially.
3435
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
3554

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+
36104
/** Compares two maps structurally; i.e. checks if all mappings
37105
* contained in this map are also contained in the other map,
38106
* and vice versa.
@@ -42,21 +110,21 @@ trait GenMapLike[A, +B, +Repr] extends GenIterableLike[(A, B), Repr] with Equals
42110
* same mappings, `false` otherwise.
43111
*/
44112
override def equals(that: Any): Boolean = that match {
45-
case that: GenMap[b, _] =>
113+
case that: GenMap[b, _] =>
46114
(this eq that) ||
47115
(that canEqual this) &&
48116
(this.size == that.size) && {
49117
try {
50-
this forall {
118+
this forall {
51119
case (k, v) => that.get(k.asInstanceOf[b]) match {
52120
case Some(`v`) =>
53121
true
54122
case _ => false
55123
}
56124
}
57-
} catch {
58-
case ex: ClassCastException =>
59-
false
125+
} catch {
126+
case ex: ClassCastException =>
127+
println("class cast "); false
60128
}}
61129
case _ =>
62130
false

src/library/scala/collection/immutable/RedBlack.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ abstract class RedBlack[A] extends Serializable {
257257
def last = if (right.isEmpty) key else right.last
258258
def count = 1 + left.count + right.count
259259
}
260-
class Empty extends Tree[Nothing] {
260+
case object Empty extends Tree[Nothing] {
261261
def isEmpty = true
262262
def isBlack = true
263263
def lookup(k: A): Tree[Nothing] = this
@@ -274,7 +274,6 @@ abstract class RedBlack[A] extends Serializable {
274274
def last = throw new NoSuchElementException("empty map")
275275
def count = 0
276276
}
277-
lazy val Empty = new Empty
278277
case class RedTree[+B](override val key: A,
279278
override val value: B,
280279
override val left: Tree[B],

src/library/scala/collection/immutable/Vector.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ private[immutable] trait VectorPointer[T] {
933933

934934
private[immutable] final def copyOf(a: Array[AnyRef]) = {
935935
//println("copy")
936-
// if (a eq null) println ("NULL")
936+
if (a eq null) println ("NULL")
937937
val b = new Array[AnyRef](a.length)
938938
Platform.arraycopy(a, 0, b, 0, a.length)
939939
b

src/library/scala/runtime/JavaSourceMisc.scala

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)