Skip to content

Commit ed0d56f

Browse files
authored
Merge pull request #54 from sjrd/upgrades
Upgrades.
2 parents cf1623a + 41df62f commit ed0d56f

File tree

10 files changed

+58
-44
lines changed

10 files changed

+58
-44
lines changed

.travis.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@ script:
99
scala:
1010
- 2.10.7
1111
- 2.11.12
12-
- 2.12.6
13-
- 2.13.0-M3
14-
- 2.13.0-M4
12+
- 2.12.10
13+
- 2.13.1
1514
jdk:
16-
- oraclejdk8
15+
- openjdk8
1716
env:
18-
- SCALAJS_VERSION=0.6.24
19-
- SCALAJS_VERSION=1.0.0-M3
20-
- SCALAJS_VERSION=1.0.0-M5
17+
- SCALAJS_VERSION=0.6.31
18+
- SCALAJS_VERSION=1.0.0-M8
19+
- SCALAJS_VERSION=1.0.0-RC1
2120
matrix:
2221
exclude:
2322
- scala: 2.10.7
24-
env: SCALAJS_VERSION=1.0.0-M3
25-
- scala: 2.13.0-M4
26-
env: SCALAJS_VERSION=1.0.0-M3
23+
env: SCALAJS_VERSION=1.0.0-M8
2724
- scala: 2.10.7
28-
env: SCALAJS_VERSION=1.0.0-M5
25+
env: SCALAJS_VERSION=1.0.0-RC1
2926

3027
cache:
3128
directories:

build.sbt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import sbtcrossproject.crossProject
22

33
crossScalaVersions in ThisBuild := {
4-
val allVersions = Seq("2.12.6", "2.11.12", "2.10.7", "2.13.0-M3", "2.13.0-M4")
4+
val allVersions = Seq("2.12.10", "2.11.12", "2.10.7", "2.13.1")
55
if (scalaJSVersion.startsWith("0.6."))
66
allVersions
7-
else if (scalaJSVersion == "1.0.0-M3")
8-
allVersions.filter(v => !v.startsWith("2.10.") && v != "2.13.0-M4")
97
else
108
allVersions.filter(!_.startsWith("2.10."))
119
}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.17
1+
sbt.version=1.3.3

project/build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
val scalaJSVersion =
2-
Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.24")
2+
Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.31")
33

44
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
5-
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.5.0")
5+
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
66

7-
addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "0.8.0")
7+
addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "1.0.0")

src/main/scala/java/time/Duration.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package java.time
22

3-
import scala.collection.JavaConverters._
4-
53
import java.time.temporal._
64

5+
import java.{util => ju}
6+
77
final class Duration private (seconds: Long, nanos: Int)
88
extends TemporalAmount with Comparable[Duration]
99
with java.io.Serializable {
@@ -29,7 +29,7 @@ final class Duration private (seconds: Long, nanos: Int)
2929
}
3030

3131
def getUnits(): java.util.List[TemporalUnit] =
32-
Seq[TemporalUnit](SECONDS, NANOS).asJava
32+
ju.Collections.unmodifiableList(ju.Arrays.asList(SECONDS, NANOS))
3333

3434
def isZero(): Boolean = seconds == 0 && nanos == 0
3535

@@ -274,9 +274,13 @@ object Duration {
274274
}
275275

276276
def from(amount: TemporalAmount): Duration = {
277-
amount.getUnits.asScala.foldLeft(ZERO) { (d, u) =>
278-
d.plus(amount.get(u), u)
277+
var result = ZERO
278+
val iter = amount.getUnits().iterator()
279+
while (iter.hasNext()) {
280+
val unit = iter.next()
281+
result = result.plus(amount.get(unit), unit)
279282
}
283+
result
280284
}
281285

282286
// Not implemented

src/main/scala/java/time/Period.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package java.time
22

3-
import scala.collection.JavaConverters._
4-
53
import java.time.chrono.{IsoChronology, ChronoPeriod}
64
import java.time.temporal._
5+
76
import java.{util => ju}
87

98
final class Period private (years: Int, months: Int, days: Int)
@@ -20,7 +19,7 @@ final class Period private (years: Int, months: Int, days: Int)
2019
}
2120

2221
def getUnits(): ju.List[TemporalUnit] =
23-
Seq[TemporalUnit](YEARS, MONTHS, DAYS).asJava
22+
ju.Collections.unmodifiableList(ju.Arrays.asList(YEARS, MONTHS, DAYS))
2423

2524
def getChronology(): IsoChronology = IsoChronology.INSTANCE
2625

@@ -170,21 +169,25 @@ object Period {
170169
case amount: Period => amount
171170

172171
case _ =>
173-
amount.getUnits().asScala.foldLeft(ZERO) { (p, unit) =>
172+
var result = ZERO
173+
val iter = amount.getUnits().iterator()
174+
while (iter.hasNext()) {
175+
val unit = iter.next()
174176
unit match {
175177
case ChronoUnit.YEARS =>
176-
p.withYears(Math.toIntExact(amount.get(unit)))
178+
result = result.withYears(Math.toIntExact(amount.get(unit)))
177179

178180
case ChronoUnit.MONTHS =>
179-
p.withMonths(Math.toIntExact(amount.get(unit)))
181+
result = result.withMonths(Math.toIntExact(amount.get(unit)))
180182

181183
case ChronoUnit.DAYS =>
182-
p.withDays(Math.toIntExact(amount.get(unit)))
184+
result = result.withDays(Math.toIntExact(amount.get(unit)))
183185

184186
case _ =>
185187
throw new DateTimeException(s"Unit not allowed: $unit")
186188
}
187189
}
190+
result
188191
}
189192

190193
def between(start: LocalDate, end: LocalDate): Period = start.until(end)

src/main/scala/java/time/chrono/ChronoPeriod.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package java.time.chrono
22

3-
import scala.collection.JavaConverters._
4-
53
import java.time.temporal.{Temporal, TemporalAmount}
4+
import java.time.temporal.TemporalUnit
65

76
trait ChronoPeriod extends TemporalAmount {
87
def getChronology(): Chronology
98

10-
def isZero(): Boolean = getUnits.asScala.forall(get(_) == 0)
9+
def isZero(): Boolean = forallUnits(get(_) == 0)
1110

12-
def isNegative(): Boolean = getUnits.asScala.exists(get(_) < 0)
11+
def isNegative(): Boolean = !forallUnits(get(_) >= 0)
1312

1413
def plus(amount: TemporalAmount): ChronoPeriod
1514

@@ -24,6 +23,17 @@ trait ChronoPeriod extends TemporalAmount {
2423
def addTo(temporal: Temporal): Temporal
2524

2625
def subtractFrom(temporal: Temporal): Temporal
26+
27+
private def forallUnits(f: TemporalUnit => Boolean): Boolean = {
28+
// scalastyle:off return
29+
val iter = getUnits().iterator()
30+
while (iter.hasNext()) {
31+
if (!f(iter.next()))
32+
return false
33+
}
34+
true
35+
// scalastyle:on return
36+
}
2737
}
2838

2939
object ChronoPeriod {

src/main/scala/java/time/chrono/Chronology.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package java.time.chrono
22

3-
import scala.collection.JavaConverters._
43
import scala.scalajs.js
54

65
import java.time.{Period, DateTimeException}
@@ -70,11 +69,17 @@ object Chronology {
7069
// def ofLocale(locale: ju.Locale): Chronology
7170

7271
def of(id: String): Chronology = {
73-
getAvailableChronologies().asScala.find(_.getId == id).getOrElse {
74-
throw new DateTimeException(s"Unknown chronology: $id")
72+
// scalastyle:off return
73+
val iter = getAvailableChronologies().iterator()
74+
while (iter.hasNext()) {
75+
val chronology = iter.next()
76+
if (chronology.getId() == id)
77+
return chronology
7578
}
79+
throw new DateTimeException(s"Unknown chronology: $id")
80+
// scalastyle:on return
7681
}
7782

7883
def getAvailableChronologies(): ju.Set[Chronology] =
79-
Set[Chronology](IsoChronology.INSTANCE).asJava
84+
ju.Collections.singleton(IsoChronology.INSTANCE)
8085
}

src/main/scala/java/time/chrono/IsoChronology.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package java.time.chrono
22

3-
import scala.collection.JavaConverters._
4-
53
import java.time.{Period, LocalDate}
64
import java.time.temporal.{ValueRange, ChronoField, TemporalAccessor}
75
import java.{util => ju}
@@ -53,7 +51,8 @@ final class IsoChronology private () extends AbstractChronology with Serializabl
5351

5452
def eraOf(eraValue: Int): IsoEra = IsoEra.of(eraValue)
5553

56-
def eras(): ju.List[Era] = Seq[Era](IsoEra.BCE, IsoEra.CE).asJava
54+
def eras(): ju.List[Era] =
55+
ju.Collections.unmodifiableList(ju.Arrays.asList(IsoEra.BCE, IsoEra.CE))
5756

5857
// Not implemented
5958
// def resolveDate(fieldValues: ju.Map[TemporalField, Long],

testSuite/shared/src/test/scala/org/scalajs/testsuite/javalib/time/TemporalAmountTest.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package org.scalajs.testsuite.javalib.time
22

33
import java.time.temporal.{UnsupportedTemporalTypeException, ChronoUnit, TemporalAmount}
44

5-
import scala.collection.JavaConverters._
6-
75
import org.junit.Test
86
import org.junit.Assert._
97
import org.scalajs.testsuite.utils.AssertThrows._
@@ -25,6 +23,6 @@ abstract class TemporalAmountTest {
2523

2624
@Test def test_getUnits(): Unit = {
2725
for (amount <- samples)
28-
assertEquals(units.toIterable, amount.getUnits.asScala)
26+
assertArrayEquals(units.toArray[AnyRef], amount.getUnits.toArray())
2927
}
3028
}

0 commit comments

Comments
 (0)