2016-12-24 13:47:35 +01:00
|
|
|
package org.mariotaku.ktextension
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mariotaku on 2016/12/24.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fun Collection<*>?.isNotNullOrEmpty(): Boolean {
|
|
|
|
return this != null && this.isNotEmpty()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Collection<*>?.isNullOrEmpty(): Boolean {
|
|
|
|
return this == null || this.isEmpty()
|
|
|
|
}
|
2016-12-30 15:59:23 +01:00
|
|
|
|
2016-12-31 18:13:21 +01:00
|
|
|
fun <T> MutableCollection<T>.addAllEnhanced(collection: Collection<T>, ignoreDuplicates: Boolean): Boolean {
|
|
|
|
if (ignoreDuplicates) {
|
|
|
|
return addAll(collection.filter { it !in this })
|
|
|
|
} else {
|
|
|
|
return addAll(collection)
|
|
|
|
}
|
2017-01-02 09:33:27 +01:00
|
|
|
}
|
|
|
|
|
2017-01-23 07:12:29 +01:00
|
|
|
fun <T> Collection<T>.addAllTo(collection: MutableCollection<T>): Boolean {
|
|
|
|
return collection.addAll(this)
|
|
|
|
}
|
|
|
|
|
2017-01-02 09:33:27 +01:00
|
|
|
fun <E> Collection<E>?.nullableContentEquals(other: Collection<E>?): Boolean {
|
|
|
|
if (this == null) return other.isNullOrEmpty()
|
|
|
|
return contentEquals(other!!)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun <E> Collection<E>.contentEquals(other: Collection<E>): Boolean {
|
|
|
|
if (this === other) return true
|
|
|
|
if (this.size != other.size) return false
|
|
|
|
return this.containsAll(other) && other.containsAll(this)
|
2017-03-07 07:24:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline fun <reified T> List<T>.subArray(range: IntRange): Array<T> {
|
|
|
|
return Array(range.count()) {
|
|
|
|
this[range.start + it]
|
|
|
|
}
|
2017-03-18 07:20:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun <T> T.addTo(collection: MutableCollection<T>): Boolean {
|
|
|
|
return collection.add(this)
|
2016-12-30 15:59:23 +01:00
|
|
|
}
|