Skip to content

Commit 5dc8e67

Browse files
committed
Merge '0.6.x' into 'master'.
2 parents 6d4c849 + a347ca1 commit 5dc8e67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2499
-1308
lines changed

javalanglib/src/main/scala/java/lang/Byte.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ object Byte {
8484
@inline def toString(b: scala.Byte): String =
8585
"" + b
8686

87+
@noinline def decode(nm: String): Byte =
88+
Integer.decodeGeneric(nm, valueOf(_, _))
89+
8790
@inline def compare(x: scala.Byte, y: scala.Byte): scala.Int =
8891
x - y
8992
}

javalanglib/src/main/scala/java/lang/Character.scala

Lines changed: 376 additions & 344 deletions
Large diffs are not rendered by default.

javalanglib/src/main/scala/java/lang/Integer.scala

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,63 @@ object Integer {
119119
@inline def toUnsignedString(i: Int, radix: Int): String =
120120
toStringBase(i, radix)
121121

122+
@noinline def decode(nm: String): Integer =
123+
decodeGeneric(nm, valueOf(_, _))
124+
125+
@inline private[lang] def decodeGeneric[A](nm: String,
126+
parse: js.Function2[String, Int, A]): A = {
127+
128+
val len = nm.length()
129+
var i = 0
130+
131+
val negative = if (i != len) {
132+
nm.charAt(i) match {
133+
case '+' =>
134+
i += 1
135+
false
136+
case '-' =>
137+
i += 1
138+
true
139+
case _ =>
140+
false
141+
}
142+
} else {
143+
false
144+
}
145+
146+
val base = if (i != len) {
147+
nm.charAt(i) match {
148+
case '0' =>
149+
if (i == len - 1) {
150+
10
151+
} else {
152+
i += 1
153+
nm.charAt(i) match {
154+
case 'x' | 'X' =>
155+
i += 1
156+
16
157+
case _ =>
158+
8
159+
}
160+
}
161+
case '#' =>
162+
i += 1
163+
16
164+
case _ =>
165+
10
166+
}
167+
} else {
168+
10
169+
}
170+
171+
val remaining = nm.substring(i)
172+
if (remaining.startsWith("+") || remaining.startsWith("-"))
173+
throw new NumberFormatException("Sign character in wrong position")
174+
175+
val s = if (negative) "-" + remaining else remaining
176+
parse(s, base)
177+
}
178+
122179
@inline def compare(x: scala.Int, y: scala.Int): scala.Int =
123180
if (x == y) 0 else if (x < y) -1 else 1
124181

javalanglib/src/main/scala/java/lang/Long.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ object Long {
324324
@inline def valueOf(s: String, radix: Int): Long =
325325
valueOf(parseLong(s, radix))
326326

327+
@noinline def decode(nm: String): Long =
328+
Integer.decodeGeneric(nm, valueOf(_, _))
329+
327330
@inline def hashCode(value: scala.Long): Int =
328331
value.toInt ^ (value >>> 32).toInt
329332

javalanglib/src/main/scala/java/lang/Short.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ object Short {
8383
@inline def toString(s: scala.Short): String =
8484
"" + s
8585

86+
@noinline def decode(nm: String): Short =
87+
Integer.decodeGeneric(nm, valueOf(_, _))
88+
8689
@inline def compare(x: scala.Short, y: scala.Short): scala.Int =
8790
x - y
8891

javalib/src/main/scala/java/util/AbstractCollection.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class AbstractCollection[E] protected () extends Collection[E] {
2525
def isEmpty(): Boolean = size == 0
2626

2727
def contains(o: Any): Boolean =
28-
this.scalaOps.exists(o === _)
28+
this.scalaOps.exists(Objects.equals(o, _))
2929

3030
def toArray(): Array[AnyRef] =
3131
toArray(new Array[AnyRef](size))
@@ -50,7 +50,7 @@ abstract class AbstractCollection[E] protected () extends Collection[E] {
5050
@tailrec
5151
def findAndRemove(iter: Iterator[E]): Boolean = {
5252
if (iter.hasNext) {
53-
if (iter.next() === o) {
53+
if (Objects.equals(iter.next(), o)) {
5454
iter.remove()
5555
true
5656
} else

javalib/src/main/scala/java/util/AbstractList.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ abstract class AbstractList[E] protected () extends AbstractCollection[E]
3535
throw new UnsupportedOperationException
3636

3737
def indexOf(o: Any): Int =
38-
this.scalaOps.indexWhere(_ === o)
38+
this.scalaOps.indexWhere(Objects.equals(_, o))
3939

4040
def lastIndexOf(o: Any): Int = {
4141
@tailrec
4242
def findIndex(iter: ListIterator[E]): Int = {
4343
if (!iter.hasPrevious) -1
44-
else if (iter.previous() === o) iter.nextIndex
44+
else if (Objects.equals(iter.previous(), o)) iter.nextIndex
4545
else findIndex(iter)
4646
}
4747
findIndex(listIterator(size))
@@ -111,15 +111,15 @@ abstract class AbstractList[E] protected () extends AbstractCollection[E]
111111
o match {
112112
case o: List[_] =>
113113
val oIter = o.listIterator
114-
this.scalaOps.forall(oIter.hasNext && _ === oIter.next()) && !oIter.hasNext
114+
this.scalaOps.forall(oIter.hasNext && Objects.equals(_, oIter.next())) && !oIter.hasNext
115115
case _ => false
116116
}
117117
}
118118
}
119119

120120
override def hashCode(): Int = {
121121
this.scalaOps.foldLeft(1) {
122-
(prev, elem) => 31 * prev + (if (elem == null) 0 else elem.hashCode)
122+
(prev, elem) => 31 * prev + Objects.hashCode(elem)
123123
}
124124
}
125125

javalib/src/main/scala/java/util/AbstractMap.scala

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,14 @@ object AbstractMap {
2121
private def entryEquals[K, V](entry: Map.Entry[K, V], other: Any): Boolean = {
2222
other match {
2323
case other: Map.Entry[_, _] =>
24-
entry.getKey === other.getKey && entry.getValue === other.getValue
24+
Objects.equals(entry.getKey, other.getKey) &&
25+
Objects.equals(entry.getValue, other.getValue)
2526
case _ => false
2627
}
2728
}
2829

29-
private def entryHashCode[K, V](entry: Map.Entry[K, V]): Int = {
30-
val keyHash =
31-
if (entry.getKey == null) 0
32-
else entry.getKey.hashCode
33-
val valueHash =
34-
if (entry.getValue == null) 0
35-
else entry.getValue.hashCode
36-
37-
keyHash ^ valueHash
38-
}
30+
private def entryHashCode[K, V](entry: Map.Entry[K, V]): Int =
31+
Objects.hashCode(entry.getKey) ^ Objects.hashCode(entry.getValue)
3932

4033
class SimpleEntry[K, V](private var key: K, private var value: V)
4134
extends Map.Entry[K, V] with Serializable {
@@ -95,13 +88,13 @@ abstract class AbstractMap[K, V] protected () extends java.util.Map[K, V] {
9588
def isEmpty(): Boolean = size == 0
9689

9790
def containsValue(value: Any): Boolean =
98-
entrySet.scalaOps.exists(value === _.getValue)
91+
entrySet.scalaOps.exists(entry => Objects.equals(value, entry.getValue))
9992

10093
def containsKey(key: Any): Boolean =
101-
entrySet.scalaOps.exists(entry => entry === key)
94+
entrySet.scalaOps.exists(entry => Objects.equals(key, entry.getKey))
10295

10396
def get(key: Any): V = {
104-
entrySet.scalaOps.find(_.getKey === key).fold[V] {
97+
entrySet.scalaOps.find(entry => Objects.equals(key, entry.getKey)).fold[V] {
10598
null.asInstanceOf[V]
10699
} { entry =>
107100
entry.getValue
@@ -116,7 +109,7 @@ abstract class AbstractMap[K, V] protected () extends java.util.Map[K, V] {
116109
def findAndRemove(iter: Iterator[Map.Entry[K, V]]): V = {
117110
if (iter.hasNext) {
118111
val item = iter.next()
119-
if (key === item.getKey) {
112+
if (Objects.equals(key, item.getKey)) {
120113
iter.remove()
121114
item.getValue
122115
} else
@@ -177,7 +170,7 @@ abstract class AbstractMap[K, V] protected () extends java.util.Map[K, V] {
177170
o match {
178171
case m: Map[_, _] =>
179172
self.size == m.size &&
180-
entrySet.scalaOps.forall(item => m.get(item.getKey) === item.getValue)
173+
entrySet.scalaOps.forall(item => Objects.equals(m.get(item.getKey), item.getValue))
181174
case _ => false
182175
}
183176
}

javalib/src/main/scala/java/util/ArrayDeque.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ArrayDeque[E] private (private var inner: js.Array[E])
114114
}
115115

116116
def removeFirstOccurrence(o: Any): Boolean = {
117-
val index = inner.indexWhere(_ === o)
117+
val index = inner.indexWhere(Objects.equals(_, o))
118118
if (index >= 0) {
119119
inner.remove(index)
120120
status += 1
@@ -124,7 +124,7 @@ class ArrayDeque[E] private (private var inner: js.Array[E])
124124
}
125125

126126
def removeLastOccurrence(o: Any): Boolean = {
127-
val index = inner.lastIndexWhere(_ === o)
127+
val index = inner.lastIndexWhere(Objects.equals(_, o))
128128
if (index >= 0) {
129129
inner.remove(index)
130130
status += 1
@@ -193,7 +193,7 @@ class ArrayDeque[E] private (private var inner: js.Array[E])
193193
def descendingIterator(): Iterator[E] =
194194
failFastIterator(inner.size, x => (x - 1))
195195

196-
override def contains(o: Any): Boolean = inner.exists(_ === o)
196+
override def contains(o: Any): Boolean = inner.exists(Objects.equals(_, o))
197197

198198
override def remove(o: Any): Boolean = removeFirstOccurrence(o)
199199

javalib/src/main/scala/java/util/Arrays.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,13 +651,13 @@ object Arrays {
651651
hashCodeImpl[Double](a)
652652

653653
@noinline def hashCode(a: Array[AnyRef]): Int =
654-
hashCodeImpl[AnyRef](a)
654+
hashCodeImpl[AnyRef](a, Objects.hashCode(_))
655655

656656
@inline
657657
private def hashCodeImpl[T](a: Array[T],
658-
elementHashCode: T => Int = (x: T) => x.asInstanceOf[AnyRef].hashCode): Int = {
658+
elementHashCode: T => Int = (x: T) => x.hashCode): Int = {
659659
if (a == null) 0
660-
else a.foldLeft(1)((acc, x) => 31*acc + (if (x == null) 0 else elementHashCode(x)))
660+
else a.foldLeft(1)((acc, x) => 31*acc + elementHashCode(x))
661661
}
662662

663663
@noinline def deepHashCode(a: Array[AnyRef]): Int = {
@@ -673,7 +673,7 @@ object Arrays {
673673
case elem: Array[Boolean] => hashCode(elem)
674674
case elem: Array[Float] => hashCode(elem)
675675
case elem: Array[Double] => hashCode(elem)
676-
case _ => elem.hashCode
676+
case _ => Objects.hashCode(elem)
677677
}
678678
}
679679
hashCodeImpl(a, getHash)

javalib/src/main/scala/java/util/Collections.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ object Collections {
305305
case _: RandomAccess =>
306306
var modified = false
307307
for (i <- 0 until list.size) {
308-
if (list.get(i) === oldVal) {
308+
if (Objects.equals(list.get(i), oldVal)) {
309309
list.set(i, newVal)
310310
modified = true
311311
}
@@ -316,7 +316,7 @@ object Collections {
316316
@tailrec
317317
def replaceAll(iter: ListIterator[T], mod: Boolean): Boolean = {
318318
if (iter.hasNext) {
319-
val isEqual = iter.next() === oldVal
319+
val isEqual = Objects.equals(iter.next(), oldVal)
320320
if (isEqual)
321321
iter.set(newVal)
322322
replaceAll(iter, mod || isEqual)
@@ -541,7 +541,7 @@ object Collections {
541541
}
542542

543543
def frequency(c: Collection[_], o: AnyRef): Int =
544-
c.scalaOps.count(_ === o)
544+
c.scalaOps.count(Objects.equals(_, o))
545545

546546
def disjoint(c1: Collection[_], c2: Collection[_]): Boolean = {
547547
if (c1.size < c2.size)

0 commit comments

Comments
 (0)