From d90566b6710635e1b8d6b5f2987c5c8fa8aee032 Mon Sep 17 00:00:00 2001 From: v_kopychko Date: Thu, 11 Sep 2025 20:01:16 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/homework/processList.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/homework/processList.kt b/src/main/kotlin/ru/otus/homework/homework/processList.kt index 6d8ab43..a3564a0 100644 --- a/src/main/kotlin/ru/otus/homework/homework/processList.kt +++ b/src/main/kotlin/ru/otus/homework/homework/processList.kt @@ -8,7 +8,7 @@ inline fun processList(list: List, action: (Int) -> Unit) { fun skipThreeAndPrint(list: List) { processList(list) { - if (it == 3) return - println("Processing $it") + if (it == 3) return@processList + print("Processing $it\n") } } From fddf8d538623388d3ef9e0947a6df5261d0b293b Mon Sep 17 00:00:00 2001 From: v_kopychko Date: Thu, 11 Sep 2025 20:03:33 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/homework/Coffee.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/homework/Coffee.kt b/src/main/kotlin/ru/otus/homework/homework/Coffee.kt index c73f420..4c88207 100644 --- a/src/main/kotlin/ru/otus/homework/homework/Coffee.kt +++ b/src/main/kotlin/ru/otus/homework/homework/Coffee.kt @@ -22,30 +22,30 @@ class SimpleCoffee : Coffee { class MilkDecorator(private val coffee: Coffee) : Coffee { override fun cost(): Int { - TODO("Not yet implemented") + return coffee.cost() + 50 } override fun description(): String { - TODO("Not yet implemented") + return coffee.description() + ", молоко" } } class SugarDecorator(private val coffee: Coffee) : Coffee { override fun cost(): Int { - TODO("Not yet implemented") + return coffee.cost() + 20 } override fun description(): String { - TODO("Not yet implemented") + return coffee.description() + ", сахар" } } class VanillaDecorator(private val coffee: Coffee) : Coffee { override fun cost(): Int { - TODO("Not yet implemented") + return coffee.cost() + 70 } override fun description(): String { - TODO("Not yet implemented") + return coffee.description() + ", ваниль" } } \ No newline at end of file From 7026abc23ed7a008a63965a0cec3a17b41bdb790 Mon Sep 17 00:00:00 2001 From: v_kopychko Date: Thu, 11 Sep 2025 20:04:28 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=203.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/otus/homework/homework/UserProfile.kt | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/homework/UserProfile.kt b/src/main/kotlin/ru/otus/homework/homework/UserProfile.kt index f0fab82..bc55644 100644 --- a/src/main/kotlin/ru/otus/homework/homework/UserProfile.kt +++ b/src/main/kotlin/ru/otus/homework/homework/UserProfile.kt @@ -2,6 +2,9 @@ package ru.otus.homework.homework +import java.util.LinkedList +import kotlin.properties.Delegates + /** * Профиль пользователя */ @@ -37,7 +40,8 @@ interface UserProfile { * Creates user profile with logging */ fun createWithLogging(fullName: String, email: String): UserProfile.Logging { - TODO("Implement `createWithLogging` function") + return ProfileImplementationWithLogging( + create(fullName, email)) } } } @@ -50,4 +54,31 @@ private val emailRegex = Regex("^[A-Za-z](.*)([@])(.+)(\\.)(.+)") /** * Реализация простого [UserProfile]. */ -private class ProfileImplementation(override var fullName: String, override var email: String): UserProfile \ No newline at end of file +private class ProfileImplementation(fullName: String, email: String): UserProfile{ + override var fullName : String by Delegates.vetoable(fullName) { _, _, newValue -> + newValue.isNotBlank()} + + override var email : String by Delegates.vetoable(email) { _, _, newValue -> + newValue.isNotBlank() && emailRegex.matches(newValue)} +} + +private class ProfileImplementationWithLogging(private val userProfile: UserProfile) : UserProfile.Logging, UserProfile by userProfile { + + private val log = LinkedList() + + override var fullName: String + get() = userProfile.fullName + set(value) { + log.add("Changing `fullName` from '${userProfile.fullName}' to '$value'") + userProfile.fullName = value + } + + override var email: String + get() = userProfile.email + set(value) { + log.add("Changing `email` from '${userProfile.email}' to '$value'") + userProfile.email = value + } + + override fun getLog(): List = log +} \ No newline at end of file From 5224267a680947732f45218336f0be63ef7c42a2 Mon Sep 17 00:00:00 2001 From: v_kopychko Date: Thu, 11 Sep 2025 20:05:06 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=203.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/otus/homework/homework/NonEmptyStringDelegate.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/homework/NonEmptyStringDelegate.kt b/src/main/kotlin/ru/otus/homework/homework/NonEmptyStringDelegate.kt index 568f368..395c1c3 100644 --- a/src/main/kotlin/ru/otus/homework/homework/NonEmptyStringDelegate.kt +++ b/src/main/kotlin/ru/otus/homework/homework/NonEmptyStringDelegate.kt @@ -6,11 +6,16 @@ import kotlin.reflect.KProperty * Delegate that allows to set non-empty string value */ class NonEmptyStringDelegate() { + + private var value: String = "" + operator fun getValue(thisRef: Any?, property: KProperty<*>): String { - TODO("Implement `getValue` function") + return value } operator fun setValue(thisRef: Any?, property: KProperty<*>, newValue: String) { - TODO("Implement `setValue` function") + if (newValue.isNotBlank()) { + this.value = newValue + } } } \ No newline at end of file From 75927d2ae2849c97c3e5059cc4999c000e4ffd03 Mon Sep 17 00:00:00 2001 From: v_kopychko Date: Thu, 11 Sep 2025 20:13:10 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=203.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/homework/UserProfile.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/ru/otus/homework/homework/UserProfile.kt b/src/main/kotlin/ru/otus/homework/homework/UserProfile.kt index bc55644..e80f810 100644 --- a/src/main/kotlin/ru/otus/homework/homework/UserProfile.kt +++ b/src/main/kotlin/ru/otus/homework/homework/UserProfile.kt @@ -63,7 +63,6 @@ private class ProfileImplementation(fullName: String, email: String): UserProfil } private class ProfileImplementationWithLogging(private val userProfile: UserProfile) : UserProfile.Logging, UserProfile by userProfile { - private val log = LinkedList() override var fullName: String