API description correction

This commit is contained in:
DBotThePony 2022-05-10 17:10:40 +07:00
parent 6819866c48
commit 01e3b2fb38
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -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 : IStorageStack> T.key(): T {
return copy().also { it.count = ImpreciseFraction.ONE } as T
}