-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2c9e69
commit e0bb89b
Showing
29 changed files
with
901 additions
and
636 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ plugins { | |
} | ||
|
||
group = "xyz.lbres" | ||
version = "1.3.4" | ||
version = "1.4.4" | ||
|
||
repositories { | ||
mavenCentral() | ||
|
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
61 changes: 0 additions & 61 deletions
61
kotlin-utils/src/main/kotlin/xyz/lbres/kotlinutils/set/multiset/MultiSetGenerics.kt
This file was deleted.
Oops, something went wrong.
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
44 changes: 0 additions & 44 deletions
44
...ils/src/main/kotlin/xyz/lbres/kotlinutils/set/multiset/const/AbstractConstMultiSetImpl.kt
This file was deleted.
Oops, something went wrong.
69 changes: 68 additions & 1 deletion
69
kotlin-utils/src/main/kotlin/xyz/lbres/kotlinutils/set/multiset/const/ConstMultiSet.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,9 +1,76 @@ | ||
package xyz.lbres.kotlinutils.set.multiset.const | ||
|
||
import xyz.lbres.kotlinutils.general.tryOrDefault | ||
import xyz.lbres.kotlinutils.internal.constants.Suppressions | ||
import xyz.lbres.kotlinutils.set.multiset.MultiSet | ||
import xyz.lbres.kotlinutils.set.multiset.utils.CountsMap | ||
import xyz.lbres.kotlinutils.set.multiset.utils.performIntersect | ||
import xyz.lbres.kotlinutils.set.multiset.utils.performMinus | ||
import xyz.lbres.kotlinutils.set.multiset.utils.performPlus | ||
|
||
/** | ||
* [MultiSet] implementation where values of elements are assumed to be constant. | ||
* Behavior is not defined if values of elements are changed (i.e. elements are added to a mutable list). | ||
*/ | ||
sealed class ConstMultiSet<E> : MultiSet<E> | ||
sealed class ConstMultiSet<E> : MultiSet<E> { | ||
// required because ConstMultiSet is a public class. Must be CountsMap<E> | ||
protected abstract val counts: Any | ||
private val _counts: CountsMap<E> | ||
@Suppress(Suppressions.UNCHECKED_CAST) | ||
get() = counts as CountsMap<E> | ||
|
||
override fun plus(other: MultiSet<E>): MultiSet<E> = performPlus(_counts, other) | ||
override fun minus(other: MultiSet<E>): MultiSet<E> = performMinus(_counts, other) | ||
override fun intersect(other: MultiSet<E>): MultiSet<E> = performIntersect(_counts, other) | ||
|
||
@Suppress(Suppressions.FUNCTION_NAME) | ||
infix fun `+c`(other: ConstMultiSet<E>): ConstMultiSet<E> = plusC(other) | ||
@Suppress(Suppressions.FUNCTION_NAME) | ||
infix fun `-c`(other: ConstMultiSet<E>): ConstMultiSet<E> = minusC(other) | ||
|
||
/** | ||
* Alternate version of [plus], which returns a ConstMultiSet | ||
* | ||
* @param other [ConstMultiSet]<E>: values to add to this MultiSet | ||
* @return [ConstMultiSet]<E>: ConstMultiSet containing all values from both MultiSets | ||
*/ | ||
fun plusC(other: ConstMultiSet<E>): ConstMultiSet<E> = performPlus(_counts, other, true) as ConstMultiSet<E> | ||
|
||
/** | ||
* Alternate version of [minus], which returns a ConstMultiSet | ||
* | ||
* @param other [ConstMultiSet]<E>: values to subtract from this MultiSet | ||
* @return [ConstMultiSet]<E>: ConstMultiSet containing the items in this MultiSet but not the other | ||
*/ | ||
fun minusC(other: ConstMultiSet<E>): ConstMultiSet<E> = performMinus(_counts, other, true) as ConstMultiSet<E> | ||
|
||
/** | ||
* Alternate version of [intersect], which returns a ConstMultiSet | ||
* | ||
* @param other [ConstMultiSet]<E>: values to intersect with this MultiSet | ||
* @return [ConstMultiSet]<E>: ConstMultiSet containing only values that are in both MultiSets | ||
*/ | ||
infix fun intersectC(other: ConstMultiSet<E>): ConstMultiSet<E> = performIntersect(_counts, other, true) as ConstMultiSet<E> | ||
|
||
override fun getCountOf(element: E): Int = _counts.getCountOf(element) | ||
override fun contains(element: E): Boolean = _counts.contains(element) | ||
override fun containsAll(elements: Collection<E>): Boolean = _counts.containsAll(elements) | ||
override fun isEmpty(): Boolean = _counts.isEmpty() | ||
|
||
override fun hashCode(): Int { | ||
val hashCode = _counts.hashCode() | ||
return 31 * hashCode + MultiSet::class.java.name.hashCode() | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
return if (other is ConstMultiSet<*>) { | ||
_counts == other._counts | ||
} else { | ||
tryOrDefault(false, listOf(ClassCastException::class)) { | ||
@Suppress(Suppressions.UNCHECKED_CAST) | ||
other as MultiSet<E> | ||
_counts == CountsMap.from(other) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.