Skip to content

Commit 8dc7e2e

Browse files
committed
Use Enum entries instead of values
1 parent 2616a9d commit 8dc7e2e

File tree

5 files changed

+5
-15
lines changed

5 files changed

+5
-15
lines changed

core/common/src/DayOfWeek.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package kotlinx.datetime
77

8-
import kotlin.native.concurrent.*
9-
108
/**
119
* The enumeration class representing the days of the week.
1210
*/
@@ -25,13 +23,10 @@ public expect enum class DayOfWeek {
2523
*/
2624
public val DayOfWeek.isoDayNumber: Int get() = ordinal + 1
2725

28-
@SharedImmutable
29-
private val allDaysOfWeek = DayOfWeek.values().asList()
30-
3126
/**
3227
* Returns the [DayOfWeek] instance for the given ISO-8601 week day number. Monday is 1, Sunday is 7.
3328
*/
3429
public fun DayOfWeek(isoDayNumber: Int): DayOfWeek {
3530
require(isoDayNumber in 1..7)
36-
return allDaysOfWeek[isoDayNumber - 1]
31+
return DayOfWeek.entries[isoDayNumber - 1]
3732
}

core/common/src/Month.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package kotlinx.datetime
77

8-
import kotlin.native.concurrent.*
9-
108
/**
119
* The enumeration class representing the 12 months of the year.
1210
*/
@@ -55,15 +53,12 @@ public expect enum class Month {
5553
*/
5654
public val Month.number: Int get() = ordinal + 1
5755

58-
@SharedImmutable
59-
private val allMonths = Month.values().asList()
60-
6156
/**
6257
* Returns the [Month] instance for the given month number. January is 1, December is 12.
6358
*/
6459
public fun Month(number: Int): Month {
6560
require(number in 1..12)
66-
return allMonths[number - 1]
61+
return Month.entries[number - 1]
6762
}
6863

6964

core/jvm/test/ConvertersTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ConvertersTest {
3939

4040
private fun randomDate(): LocalDate {
4141
val year = Random.nextInt(-20000, 20000)
42-
val month = Month.values().random()
42+
val month = Month.entries.random()
4343
val day = (1..java.time.YearMonth.of(year, month).lengthOfMonth()).random()
4444
return LocalDate(year, month.number, day)
4545
}

serialization/common/test/DayOfWeekSerializationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlin.test.*
1313
class DayOfWeekSerializationTest {
1414
@Test
1515
fun testSerialization() {
16-
for (dayOfWeek in DayOfWeek.values()) {
16+
for (dayOfWeek in DayOfWeek.entries) {
1717
val json = "\"${dayOfWeek.name}\""
1818
assertEquals(json, Json.encodeToString(DayOfWeekSerializer, dayOfWeek))
1919
assertEquals(dayOfWeek, Json.decodeFromString(DayOfWeekSerializer, json))

serialization/common/test/MonthSerializationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlin.test.*
1313
class MonthSerializationTest {
1414
@Test
1515
fun testSerialization() {
16-
for (month in Month.values()) {
16+
for (month in Month.entries) {
1717
val json = "\"${month.name}\""
1818
assertEquals(json, Json.encodeToString(MonthSerializer, month))
1919
assertEquals(month, Json.decodeFromString(MonthSerializer, json))

0 commit comments

Comments
 (0)