From 01e3b2fb3886fc541bb1a3a2652c13b366977860 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 10 May 2022 17:10:40 +0700 Subject: [PATCH] API description correction --- src/main/kotlin/ru/dbotthepony/mc/otm/storage/API.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/storage/API.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/storage/API.kt index 691a8524a..f5e677d25 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/storage/API.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/storage/API.kt @@ -12,7 +12,7 @@ import java.util.* * 2. Due to condition above, and due to sublying storage most of time being * mutable, it is expected you do defensive copies. Examples of when you should do * them are described on related interfaces. - * 3. For storing stacks as [Map] keys, a stack with size of 1 is utilized (requiring [equals] and [hashCode] to return meaningful results). + * 3. For storing stacks as [Map] keys, a stack with size of 1 is utilized (requiring [equals] and [hashCode] to return meaningful results, see [IStorageStack.key]). * 4. For equality (INCLUDING count), regular [equals] is utilized. */ interface IStorageStack { @@ -54,6 +54,14 @@ interface IStorageStack { } } +/** + * (Supposedly shallow) Copies this object and sets it's count to 1 for use as map key. + * + * Equals to next code: + * ```kotlin + * this.copy().also { it.count = ImpreciseFraction.ONE } + * ``` + */ fun T.key(): T { return copy().also { it.count = ImpreciseFraction.ONE } as T }