All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.io.nacular.doodle.utils.TreeSet.kt Maven / Gradle / Ivy

package io.nacular.doodle.utils

/**
 * Created by Nicholas Eddy on 4/11/18.
 */

public actual open class TreeSet actual constructor(comparator: Comparator, elements: Collection): Set {
    public actual constructor(comparator: Comparator): this(comparator, emptyList())

    protected val treeSet: java.util.TreeSet = java.util.TreeSet(comparator).also { it.addAll(elements) }

    actual override val size: Int get(                       ) = treeSet.size
    actual override fun isEmpty      (                       ): Boolean = treeSet.isEmpty    (        )
    actual override fun contains     (element: E             ): Boolean = treeSet.contains   (element )
    actual override fun containsAll  (elements: Collection): Boolean = treeSet.containsAll(elements)

    actual override fun iterator(): Iterator = treeSet.iterator()

    public actual companion object {
        public actual operator fun > invoke(): TreeSet = TreeSet(Comparator { a, b -> a.compareTo(b) })

        public actual operator fun > invoke(elements: Collection): TreeSet = TreeSet(Comparator { a, b -> a.compareTo(b) }, elements)
    }
}

public actual class MutableTreeSet actual constructor(comparator: Comparator, elements: Collection): io.nacular.doodle.utils.TreeSet(comparator, elements), MutableSet {
    public actual constructor(comparator: Comparator): this(comparator, emptyList())

    actual override fun iterator(): MutableIterator = treeSet.iterator()

    actual override fun add      (element:  E            ): Boolean = treeSet.add      (element )
    actual override fun remove   (element:  E            ): Boolean = treeSet.remove   (element )
    actual override fun addAll   (elements: Collection): Boolean = treeSet.addAll   (elements)
    actual override fun removeAll(elements: Collection): Boolean = treeSet.removeAll(elements)
    actual override fun retainAll(elements: Collection): Boolean = treeSet.retainAll(elements)

    actual override fun clear(): Unit = treeSet.clear()

    public actual companion object {
        public actual operator fun > invoke(): MutableTreeSet = MutableTreeSet(Comparator { a, b -> a.compareTo(b) })

        public actual operator fun > invoke(elements: Collection): MutableTreeSet = MutableTreeSet(Comparator { a, b -> a.compareTo(b) }, elements)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy