Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(#12): move updating's operations from NotEmptyMutableCollect…
…ion to NotEmptyMutableList
- Loading branch information
Showing
4 changed files
with
272 additions
and
319 deletions.
There are no files selected for viewing
57 changes: 2 additions & 55 deletions
57
src/main/kotlin/kotools/types/collections/NotEmptyMutableCollection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,13 @@ | ||
package kotools.types.collections | ||
|
||
import kotools.types.annotations.SinceKotoolsTypes | ||
import kotools.types.number.PositiveInt | ||
import kotools.types.number.StrictlyPositiveInt | ||
|
||
// TODO: 26/07/2022 Remove this type | ||
/** | ||
* Represents mutable collections containing at least one element. | ||
* | ||
* @param E The type of elements contained in this collection. | ||
*/ | ||
@SinceKotoolsTypes("1.3") | ||
public sealed interface NotEmptyMutableCollection<E> : MutableCollection<E>, | ||
NotEmptyCollection<E> { | ||
// ---------- Positional Access Operations ---------- | ||
|
||
/** | ||
* Replaces the element at the specified [index] in this list with the | ||
* specified [element], or throws an [IndexOutOfBoundsException] if the | ||
* [index] is out of bounds. | ||
*/ | ||
@Throws(IndexOutOfBoundsException::class) | ||
public operator fun set(index: Int, element: E): E | ||
|
||
/** | ||
* Replaces the element at the specified [index] in this list with the | ||
* specified [element], or throws an [IndexOutOfBoundsException] if the | ||
* [index] is out of bounds. | ||
*/ | ||
@Throws(IndexOutOfBoundsException::class) | ||
public operator fun set(index: PositiveInt, element: E): E = | ||
set(index.value, element) | ||
|
||
/** | ||
* Replaces the element at the specified [index] in this list with the | ||
* specified [element], or throws an [IndexOutOfBoundsException] if the | ||
* [index] is out of bounds. | ||
*/ | ||
@Throws(IndexOutOfBoundsException::class) | ||
public operator fun set(index: StrictlyPositiveInt, element: E): E = | ||
set(index.value, element) | ||
|
||
/** | ||
* Replaces the element at the specified [index] in this list with the | ||
* specified [element], or returns `null` if the [index] is out of bounds. | ||
*/ | ||
public fun setOrNull(index: Int, element: E): E? = try { | ||
set(index, element) | ||
} catch (_: IndexOutOfBoundsException) { | ||
null | ||
} | ||
|
||
/** | ||
* Replaces the element at the specified [index] in this list with the | ||
* specified [element], or returns `null` if the [index] is out of bounds. | ||
*/ | ||
public fun setOrNull(index: PositiveInt, element: E): E? = | ||
setOrNull(index.value, element) | ||
|
||
/** | ||
* Replaces the element at the specified [index] in this list with the | ||
* specified [element], or returns `null` if the [index] is out of bounds. | ||
*/ | ||
public fun setOrNull(index: StrictlyPositiveInt, element: E): E? = | ||
setOrNull(index.value, element) | ||
} | ||
NotEmptyCollection<E> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 0 additions & 217 deletions
217
src/test/kotlin/kotools/types/collections/NotEmptyMutableCollectionTest.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.