diff --git a/.courseignore b/.courseignore index 1b44ac6..301e1ed 100644 --- a/.courseignore +++ b/.courseignore @@ -1,3 +1,4 @@ backToTheFutureFrontend duckShopFrontend -oldSchoolFrontend \ No newline at end of file +oldSchoolFrontend +kotlin-js-store \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index cd09b65..92ffaba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ fun properties(key: String) = project.findProperty(key).toString() @Suppress("DSL_SCOPE_VIOLATION") // "libs" produces a false-positive warning, see https://youtrack.jetbrains.com/issue/KTIJ-19369 plugins { java - val kotlinVersion = "1.7.10" + val kotlinVersion = "1.9.0" id("org.jetbrains.kotlin.jvm") version kotlinVersion apply false id("org.jetbrains.kotlin.multiplatform") version kotlinVersion apply false id("org.springframework.boot") version "2.7.3" apply false diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 126c08f..04838fb 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - val kotlinVersion = "1.7.10" + val kotlinVersion = "1.9.0" kotlin("multiplatform") version kotlinVersion } diff --git a/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt b/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt index 5ebe45c..4673196 100644 --- a/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt +++ b/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt @@ -15,7 +15,7 @@ class GameModeService { fun generateSetOfDucks() = getRandomDucks().toSet() // It is better to move common code into a separated function - private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS) + private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS) fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() } } diff --git a/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/DuckShopServerDuckMapInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/DuckShopServerDuckMapInitialization/test/Tests.kt b/duckShopServer/DuckShopServerDuckMapInitialization/test/Tests.kt index 64571be..0fc1596 100644 --- a/duckShopServer/DuckShopServerDuckMapInitialization/test/Tests.kt +++ b/duckShopServer/DuckShopServerDuckMapInitialization/test/Tests.kt @@ -10,7 +10,7 @@ class Test { @Test fun generateMapOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateMapOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -34,7 +34,7 @@ class Test { @Test fun generateSetOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateSetOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -73,7 +73,7 @@ class Test { @Test fun generateListOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { diff --git a/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt b/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt index 53ab3ec..a0df56f 100644 --- a/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt +++ b/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt @@ -11,7 +11,7 @@ class GameModeService { // but this way demonstrates different approaches to work with collections fun generateListOfDucks() = List(MAX_NUMBER_OF_DUCKS) { generateRandomDuck() } - fun generateSetOfDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS).toSet() + fun generateSetOfDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS).toSet() fun generateMapOfDucks(): Map = TODO("Not implemented yet") } diff --git a/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/DuckShopServerDuckSetInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/DuckShopServerDuckSetInitialization/task.md b/duckShopServer/DuckShopServerDuckSetInitialization/task.md index 4ab0d1b..b42d67e 100644 --- a/duckShopServer/DuckShopServerDuckSetInitialization/task.md +++ b/duckShopServer/DuckShopServerDuckSetInitialization/task.md @@ -24,11 +24,11 @@ If you have any difficulties, **hints will help you solve this task**. If you need to shuffle a list of elements, you can use the built-in function [`shuffled`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/shuffled.html). -Since `Duck.values()` returns [`kotlin.Array`](https://kotlinlang.org/docs/arrays.html), by default you cannot invoke the `shuffled` function, you need to convert the result into a list: +Since `Duck.entries()` returns [`kotlin.Array`](https://kotlinlang.org/docs/arrays.html), by default you cannot invoke the `shuffled` function, you need to convert the result into a list: ```kotlin -Duck.values().shuffled() // ERROR +Duck.entries().shuffled() // ERROR -Duck.values().toList().shuffled() // OK +Duck.entries().toList().shuffled() // OK ``` We will not consider the detailed difference between lists and arrays in this project, you can follow to the documentation to get more details. diff --git a/duckShopServer/DuckShopServerDuckSetInitialization/test/Tests.kt b/duckShopServer/DuckShopServerDuckSetInitialization/test/Tests.kt index d179092..ca056eb 100644 --- a/duckShopServer/DuckShopServerDuckSetInitialization/test/Tests.kt +++ b/duckShopServer/DuckShopServerDuckSetInitialization/test/Tests.kt @@ -2,7 +2,6 @@ import org.jetbrains.academy.test.system.core.findMethod import org.jetbrains.academy.test.system.core.models.method.TestMethodInvokeData import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.utils.MAX_NUMBER_OF_DUCKS -import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import java.lang.reflect.InvocationTargetException @@ -10,7 +9,7 @@ class Test { @Test fun generateSetOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateSetOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -49,7 +48,7 @@ class Test { @Test fun generateListOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { diff --git a/duckShopServer/DuckShopServerDucksListInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/DuckShopServerDucksListInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/DuckShopServerDucksListInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/DuckShopServerDucksListInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/DuckShopServerDucksListInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/DuckShopServerDucksListInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/DuckShopServerDucksListInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/DuckShopServerDucksListInitialization/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/DuckShopServerDucksListInitialization/test/Tests.kt b/duckShopServer/DuckShopServerDucksListInitialization/test/Tests.kt index dfb377f..b4c8768 100644 --- a/duckShopServer/DuckShopServerDucksListInitialization/test/Tests.kt +++ b/duckShopServer/DuckShopServerDucksListInitialization/test/Tests.kt @@ -2,7 +2,6 @@ import org.jetbrains.academy.test.system.core.findMethod import org.jetbrains.academy.test.system.core.models.method.TestMethodInvokeData import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.utils.MAX_NUMBER_OF_DUCKS -import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import java.lang.reflect.InvocationTargetException @@ -27,7 +26,7 @@ class Test { @Test fun generateListOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { diff --git a/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt b/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt index ae9268b..362316d 100644 --- a/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt +++ b/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt @@ -13,7 +13,7 @@ class GameModeService { fun generateSetOfDucks() = getRandomDucks().toSet() - private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS) + private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS) fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() } } diff --git a/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/DuckShopServerFinishApp/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/DuckShopServerFinishApp/task-info.yaml b/duckShopServer/DuckShopServerFinishApp/task-info.yaml index a5e4d58..247eff9 100644 --- a/duckShopServer/DuckShopServerFinishApp/task-info.yaml +++ b/duckShopServer/DuckShopServerFinishApp/task-info.yaml @@ -28,8 +28,6 @@ files: visible: false - name: src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/DuckShopApplication.kt visible: true - - name: src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/tmp.kt - visible: true - name: src/main/resources/static/precache-manifest.70fad1423aecd2cc1dc8df1c8a51ab6a.js visible: true - name: src/main/resources/static/precache-manifest.79d5bbf541fc215a96f9bc662f0e090b.js diff --git a/duckShopServer/DuckShopServerFinishApp/test/Tests.kt b/duckShopServer/DuckShopServerFinishApp/test/Tests.kt index 8ef4aa3..e69de29 100644 --- a/duckShopServer/DuckShopServerFinishApp/test/Tests.kt +++ b/duckShopServer/DuckShopServerFinishApp/test/Tests.kt @@ -1,9 +0,0 @@ -import org.junit.Assert -import org.junit.Test - -class Test { - @Test fun testSolution() { - //TODO: implement your test here - Assert.assertTrue("Tests not implemented for the task", false) - } -} \ No newline at end of file diff --git a/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt b/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt index 53ab3ec..a0df56f 100644 --- a/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt +++ b/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt @@ -11,7 +11,7 @@ class GameModeService { // but this way demonstrates different approaches to work with collections fun generateListOfDucks() = List(MAX_NUMBER_OF_DUCKS) { generateRandomDuck() } - fun generateSetOfDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS).toSet() + fun generateSetOfDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS).toSet() fun generateMapOfDucks(): Map = TODO("Not implemented yet") } diff --git a/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/DuckShopServerMapDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/DuckShopServerSetDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/DuckShopServerSetDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/DuckShopServerSetDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/DuckShopServerSetDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/DuckShopServerSetDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/DuckShopServerSetDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/DuckShopServerSetDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/DuckShopServerSetDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt b/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt index 7062bc8..88d7c61 100644 --- a/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt +++ b/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service class GameChangeFunctionsService { fun List.addRandomDuck() = generateRandomDuck().also { toMutableList().add(it) } - fun Collection.getNewRandomDuck() = Duck.values().toList().minus(toSet()).shuffled().random() + fun Collection.getNewRandomDuck() = Duck.entries.toList().minus(toSet()).shuffled().random() fun Set.addRandomDuck() = getNewRandomDuck().also { toMutableSet().add(it) diff --git a/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt b/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt index 5ebe45c..4673196 100644 --- a/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt +++ b/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt @@ -15,7 +15,7 @@ class GameModeService { fun generateSetOfDucks() = getRandomDucks().toSet() // It is better to move common code into a separated function - private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS) + private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS) fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() } } diff --git a/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/duckShopServerAddElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/duckShopServerAddElements/test/Tests.kt b/duckShopServer/duckShopServerAddElements/test/Tests.kt index 1ed310b..60904c6 100644 --- a/duckShopServer/duckShopServerAddElements/test/Tests.kt +++ b/duckShopServer/duckShopServerAddElements/test/Tests.kt @@ -17,7 +17,7 @@ class Test { val invokeData = TestMethodInvokeData(gameChangeFunctionsServiceTestClass, testMethod) val errorPrefix = "The method ${testMethod.name} should add a random duck to a $collectionName of ducks, but " val addedDucks = mutableListOf() - val possibleDucks = Duck.values().toList() + val possibleDucks = Duck.entries.toList() repeat(100) { val currentDucks = toCollection(possibleDucks) try { @@ -57,7 +57,7 @@ class Test { val invokeData = TestMethodInvokeData(gameChangeFunctionsServiceTestClass, addRandomDuckMapMethod) val errorPrefix = "The method ${addRandomDuckMapMethod.name} should add a random duck to a map of ducks, but " val addedDucks = mutableListOf>() - val possibleDucks = Duck.values().toList() + val possibleDucks = Duck.entries.toList() repeat(100) { val currentDucks = possibleDucks.shuffled().take(MAX_NUMBER_OF_DUCKS).associateWith { it.getDescription() } try { @@ -116,7 +116,7 @@ class Test { @Test fun removeRandomDuckFromListMethodTest() { testRemoveDuckFromCollection( - gameChangeFunctionsServiceTestClass, removeRandomDuckListMethod, "list", Duck.values().toList().shuffled() + gameChangeFunctionsServiceTestClass, removeRandomDuckListMethod, "list", Duck.entries.toList().shuffled() ) { output, errorPrefix, currentDucks -> (output as? List) ?: run { assert(false) { "$errorPrefix for the list $currentDucks it returns $output" } @@ -131,7 +131,7 @@ class Test { gameChangeFunctionsServiceTestClass, removeRandomDuckSetMethod, "set", - Duck.values().toList().shuffled().toSet() + Duck.entries.toList().shuffled().toSet() ) { output, errorPrefix, currentDucks -> (output as? Set) ?: run { assert(false) { "$errorPrefix for the set $currentDucks it returns $output" } @@ -146,7 +146,7 @@ class Test { val errorPrefix = "The method ${removeRandomDuckMapMethod.name} should remove a random duck from a map of ducks, but " val removedDucks = mutableListOf>() - val possibleDucks = Duck.values().toList() + val possibleDucks = Duck.entries.toList() repeat(100) { val currentDucks = possibleDucks.shuffled().associateWith { it.getDescription() } try { @@ -174,7 +174,7 @@ class Test { @Test fun generateMapOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateMapOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -198,7 +198,7 @@ class Test { @Test fun generateSetOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateSetOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -237,7 +237,7 @@ class Test { @Test fun generateListOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { diff --git a/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt b/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt index 7062bc8..88d7c61 100644 --- a/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt +++ b/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service class GameChangeFunctionsService { fun List.addRandomDuck() = generateRandomDuck().also { toMutableList().add(it) } - fun Collection.getNewRandomDuck() = Duck.values().toList().minus(toSet()).shuffled().random() + fun Collection.getNewRandomDuck() = Duck.entries.toList().minus(toSet()).shuffled().random() fun Set.addRandomDuck() = getNewRandomDuck().also { toMutableSet().add(it) diff --git a/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt b/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt index 5ebe45c..4673196 100644 --- a/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt +++ b/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt @@ -15,7 +15,7 @@ class GameModeService { fun generateSetOfDucks() = getRandomDucks().toSet() // It is better to move common code into a separated function - private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS) + private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS) fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() } } diff --git a/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/duckShopServerBuiltInFunctions/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt b/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt index 7062bc8..88d7c61 100644 --- a/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt +++ b/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service class GameChangeFunctionsService { fun List.addRandomDuck() = generateRandomDuck().also { toMutableList().add(it) } - fun Collection.getNewRandomDuck() = Duck.values().toList().minus(toSet()).shuffled().random() + fun Collection.getNewRandomDuck() = Duck.entries.toList().minus(toSet()).shuffled().random() fun Set.addRandomDuck() = getNewRandomDuck().also { toMutableSet().add(it) diff --git a/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt b/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt index 5ebe45c..4673196 100644 --- a/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt +++ b/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt @@ -15,7 +15,7 @@ class GameModeService { fun generateSetOfDucks() = getRandomDucks().toSet() // It is better to move common code into a separated function - private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS) + private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS) fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() } } diff --git a/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/duckShopServerFilter/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/duckShopServerFilter/test/Tests.kt b/duckShopServer/duckShopServerFilter/test/Tests.kt index afd85d1..5d1e338 100644 --- a/duckShopServer/duckShopServerFilter/test/Tests.kt +++ b/duckShopServer/duckShopServerFilter/test/Tests.kt @@ -15,7 +15,7 @@ class Test { fun deleteDucksWithoutKotlinStuffCollectionMethodTest() { val invokeData = TestMethodInvokeData(gameActionFunctionsServiceTestClass, deleteDucksWithoutKotlinStuffCollectionMethod) val collectionOfDucks: MutableCollection = mutableListOf() - val ducks = Duck.values() + val ducks = Duck.entries.toTypedArray() ducks.toCollection(collectionOfDucks) val errorPrefix = "The method ${deleteDucksWithoutKotlinStuffCollectionMethod.name} should remove all ducks without Kotlin stuff, but " try { @@ -33,7 +33,7 @@ class Test { @Test fun deleteDucksWithoutKotlinStuffMapMethodTest() { val invokeData = TestMethodInvokeData(gameActionFunctionsServiceTestClass, deleteDucksWithoutKotlinStuffMapMethod) - val ducks = Duck.values().associateWith { it.getDescription() } + val ducks = Duck.entries.associateWith { it.getDescription() } val errorPrefix = "The method ${deleteDucksWithoutKotlinStuffMapMethod.name} should remove all ducks without Kotlin stuff, but " try { val output = gameActionFunctionsServiceTestClass.invokeMethodWithArgs(ducks, invokeData = invokeData) @@ -55,7 +55,7 @@ class Test { val invokeData = TestMethodInvokeData(gameChangeFunctionsServiceTestClass, testMethod) val errorPrefix = "The method ${testMethod.name} should add a random duck to a $collectionName of ducks, but " val addedDucks = mutableListOf() - val possibleDucks = Duck.values().toList() + val possibleDucks = Duck.entries repeat(100) { val currentDucks = toCollection(possibleDucks) try { @@ -95,7 +95,7 @@ class Test { val invokeData = TestMethodInvokeData(gameChangeFunctionsServiceTestClass, addRandomDuckMapMethod) val errorPrefix = "The method ${addRandomDuckMapMethod.name} should add a random duck to a map of ducks, but " val addedDucks = mutableListOf>() - val possibleDucks = Duck.values().toList() + val possibleDucks = Duck.entries repeat(100) { val currentDucks = possibleDucks.shuffled().take(MAX_NUMBER_OF_DUCKS).associateWith { it.getDescription() } try { @@ -154,7 +154,7 @@ class Test { @Test fun removeRandomDuckFromListMethodTest() { testRemoveDuckFromCollection( - gameChangeFunctionsServiceTestClass, removeRandomDuckListMethod, "list", Duck.values().toList().shuffled() + gameChangeFunctionsServiceTestClass, removeRandomDuckListMethod, "list", Duck.entries.toList().shuffled() ) { output, errorPrefix, currentDucks -> (output as? List) ?: run { assert(false) { "$errorPrefix for the list $currentDucks it returns $output" } @@ -169,7 +169,7 @@ class Test { gameChangeFunctionsServiceTestClass, removeRandomDuckSetMethod, "set", - Duck.values().toList().shuffled().toSet() + Duck.entries.shuffled().toSet() ) { output, errorPrefix, currentDucks -> (output as? Set) ?: run { assert(false) { "$errorPrefix for the set $currentDucks it returns $output" } @@ -184,7 +184,7 @@ class Test { val errorPrefix = "The method ${removeRandomDuckMapMethod.name} should remove a random duck from a map of ducks, but " val removedDucks = mutableListOf>() - val possibleDucks = Duck.values().toList() + val possibleDucks = Duck.entries repeat(100) { val currentDucks = possibleDucks.shuffled().associateWith { it.getDescription() } try { @@ -212,7 +212,7 @@ class Test { @Test fun generateMapOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateMapOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries.toTypedArray() val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -236,7 +236,7 @@ class Test { @Test fun generateSetOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateSetOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries.toTypedArray() val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -275,7 +275,7 @@ class Test { @Test fun generateListOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { diff --git a/duckShopServer/duckShopServerHowToRun/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/duckShopServerHowToRun/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/duckShopServerHowToRun/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/duckShopServerHowToRun/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/duckShopServerIntroduction/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/duckShopServerIntroduction/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/duckShopServerIntroduction/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/duckShopServerIntroduction/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/duckShopServerListDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/duckShopServerListDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/duckShopServerListDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/duckShopServerListDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt b/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt index 5ebe45c..4673196 100644 --- a/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt +++ b/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt @@ -15,7 +15,7 @@ class GameModeService { fun generateSetOfDucks() = getRandomDucks().toSet() // It is better to move common code into a separated function - private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS) + private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS) fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() } } diff --git a/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/duckShopServerMutableCollectionDefinition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt b/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt index 7062bc8..88d7c61 100644 --- a/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt +++ b/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/functions/change/GameChangeFunctionsService.kt @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service class GameChangeFunctionsService { fun List.addRandomDuck() = generateRandomDuck().also { toMutableList().add(it) } - fun Collection.getNewRandomDuck() = Duck.values().toList().minus(toSet()).shuffled().random() + fun Collection.getNewRandomDuck() = Duck.entries.toList().minus(toSet()).shuffled().random() fun Set.addRandomDuck() = getNewRandomDuck().also { toMutableSet().add(it) diff --git a/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt b/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt index 5ebe45c..4673196 100644 --- a/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt +++ b/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt @@ -15,7 +15,7 @@ class GameModeService { fun generateSetOfDucks() = getRandomDucks().toSet() // It is better to move common code into a separated function - private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS) + private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS) fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() } } diff --git a/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/duckShopServerPartition/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/duckShopServerPartition/test/Tests.kt b/duckShopServer/duckShopServerPartition/test/Tests.kt index 1c43bac..e39bdd2 100644 --- a/duckShopServer/duckShopServerPartition/test/Tests.kt +++ b/duckShopServer/duckShopServerPartition/test/Tests.kt @@ -15,7 +15,7 @@ class Test { fun divideDucksIntoKotlinAndNonKotlinMethodTest() { val invokeData = TestMethodInvokeData(gameActionFunctionsServiceTestClass, divideDucksIntoKotlinAndNonKotlinMethod) val collectionOfDucks: MutableCollection = mutableListOf() - val ducks = Duck.values() + val ducks = Duck.entries ducks.toCollection(collectionOfDucks) val errorPrefix = "The method ${divideDucksIntoKotlinAndNonKotlinMethod.name} should divide ducks into two collections, but " try { @@ -34,7 +34,7 @@ class Test { fun deleteDucksWithoutKotlinStuffCollectionMethodTest() { val invokeData = TestMethodInvokeData(gameActionFunctionsServiceTestClass, deleteDucksWithoutKotlinStuffCollectionMethod) val collectionOfDucks: MutableCollection = mutableListOf() - val ducks = Duck.values() + val ducks = Duck.entries ducks.toCollection(collectionOfDucks) val errorPrefix = "The method ${deleteDucksWithoutKotlinStuffCollectionMethod.name} should remove all ducks without Kotlin stuff, but " try { @@ -52,7 +52,7 @@ class Test { @Test fun deleteDucksWithoutKotlinStuffMapMethodTest() { val invokeData = TestMethodInvokeData(gameActionFunctionsServiceTestClass, deleteDucksWithoutKotlinStuffMapMethod) - val ducks = Duck.values().associateWith { it.getDescription() } + val ducks = Duck.entries.associateWith { it.getDescription() } val errorPrefix = "The method ${deleteDucksWithoutKotlinStuffMapMethod.name} should remove all ducks without Kotlin stuff, but " try { val output = gameActionFunctionsServiceTestClass.invokeMethodWithArgs(ducks, invokeData = invokeData) @@ -74,7 +74,7 @@ class Test { val invokeData = TestMethodInvokeData(gameChangeFunctionsServiceTestClass, testMethod) val errorPrefix = "The method ${testMethod.name} should add a random duck to a $collectionName of ducks, but " val addedDucks = mutableListOf() - val possibleDucks = Duck.values().toList() + val possibleDucks = Duck.entries.toList() repeat(100) { val currentDucks = toCollection(possibleDucks) try { @@ -114,7 +114,7 @@ class Test { val invokeData = TestMethodInvokeData(gameChangeFunctionsServiceTestClass, addRandomDuckMapMethod) val errorPrefix = "The method ${addRandomDuckMapMethod.name} should add a random duck to a map of ducks, but " val addedDucks = mutableListOf>() - val possibleDucks = Duck.values().toList() + val possibleDucks = Duck.entries.toList() repeat(100) { val currentDucks = possibleDucks.shuffled().take(MAX_NUMBER_OF_DUCKS).associateWith { it.getDescription() } try { @@ -173,7 +173,7 @@ class Test { @Test fun removeRandomDuckFromListMethodTest() { testRemoveDuckFromCollection( - gameChangeFunctionsServiceTestClass, removeRandomDuckListMethod, "list", Duck.values().toList().shuffled() + gameChangeFunctionsServiceTestClass, removeRandomDuckListMethod, "list", Duck.entries.toList().shuffled() ) { output, errorPrefix, currentDucks -> (output as? List) ?: run { assert(false) { "$errorPrefix for the list $currentDucks it returns $output" } @@ -188,7 +188,7 @@ class Test { gameChangeFunctionsServiceTestClass, removeRandomDuckSetMethod, "set", - Duck.values().toList().shuffled().toSet() + Duck.entries.toList().shuffled().toSet() ) { output, errorPrefix, currentDucks -> (output as? Set) ?: run { assert(false) { "$errorPrefix for the set $currentDucks it returns $output" } @@ -203,7 +203,7 @@ class Test { val errorPrefix = "The method ${removeRandomDuckMapMethod.name} should remove a random duck from a map of ducks, but " val removedDucks = mutableListOf>() - val possibleDucks = Duck.values().toList() + val possibleDucks = Duck.entries.toList() repeat(100) { val currentDucks = possibleDucks.shuffled().associateWith { it.getDescription() } try { @@ -231,7 +231,7 @@ class Test { @Test fun generateMapOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateMapOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -255,7 +255,7 @@ class Test { @Test fun generateSetOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateSetOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -294,7 +294,7 @@ class Test { @Test fun generateListOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { diff --git a/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt b/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt index c33cf83..5e17575 100644 --- a/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt +++ b/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/duck/Duck.kt @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) { ; } -fun generateRandomDuck() = Duck.values().random() +fun generateRandomDuck() = Duck.entries.random() fun Duck.getDescription() = this.customName ?: this.name diff --git a/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt b/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt index 5ebe45c..4673196 100644 --- a/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt +++ b/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/mode/GameModeService.kt @@ -15,7 +15,7 @@ class GameModeService { fun generateSetOfDucks() = getRandomDucks().toSet() // It is better to move common code into a separated function - private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS) + private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS) fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() } } diff --git a/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt b/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt index 8de5bfe..fe6a130 100644 --- a/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt +++ b/duckShopServer/duckShopServerRemoveElements/src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/utils/Converters.kt @@ -4,7 +4,7 @@ import duck.shop.JsDuck import org.jetbrains.kotlin.course.duck.shop.duck.Duck import org.jetbrains.kotlin.course.duck.shop.functions.common.Body -fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") +fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this") fun String.toGameMode() = GameMode.valueOf(this) diff --git a/duckShopServer/duckShopServerRemoveElements/test/Tests.kt b/duckShopServer/duckShopServerRemoveElements/test/Tests.kt index c8bcef2..4efb3d1 100644 --- a/duckShopServer/duckShopServerRemoveElements/test/Tests.kt +++ b/duckShopServer/duckShopServerRemoveElements/test/Tests.kt @@ -45,7 +45,7 @@ class Test { gameChangeFunctionsServiceTestClass, removeRandomDuckListMethod, "list", - Duck.values().toList().shuffled() + Duck.entries.toList().shuffled() ) { output, errorPrefix, currentDucks -> (output as? List) ?: run { assert(false) { "$errorPrefix for the list $currentDucks it returns $output" } @@ -60,7 +60,7 @@ class Test { gameChangeFunctionsServiceTestClass, removeRandomDuckSetMethod, "set", - Duck.values().toList().shuffled().toSet() + Duck.entries.toList().shuffled().toSet() ) { output, errorPrefix, currentDucks -> (output as? Set) ?: run { assert(false) { "$errorPrefix for the set $currentDucks it returns $output" } @@ -74,7 +74,7 @@ class Test { val invokeData = TestMethodInvokeData(gameChangeFunctionsServiceTestClass, removeRandomDuckMapMethod) val errorPrefix = "The method ${removeRandomDuckMapMethod.name} should remove a random duck from a map of ducks, but " val removedDucks = mutableListOf>() - val possibleDucks = Duck.values().toList() + val possibleDucks = Duck.entries.toList() repeat(100) { val currentDucks = possibleDucks.shuffled().associateWith { it.getDescription() } try { @@ -101,7 +101,7 @@ class Test { @Test fun generateMapOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateMapOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -125,7 +125,7 @@ class Test { @Test fun generateSetOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateSetOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try { @@ -164,7 +164,7 @@ class Test { @Test fun generateListOfDucksMethodTest() { val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod) - val possibleDucks = Duck.values() + val possibleDucks = Duck.entries val generatedDucks = mutableSetOf>() repeat(100) { try {