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

macosX64Main.common.workarounds.SortedSet.objc.kt Maven / Gradle / Ivy

package io.fluidsonic.stdlib


// TODO remove
internal actual class _SortedSet private constructor(
	private val container: MutableList
) : MutableSet {

	constructor(vararg elements: E) : this(container = elements.toMutableList()) {
		sort()
	}


	override fun add(element: E): Boolean {
		if (container.contains(element)) return false
		container.add(element)

		sort()
		return true
	}


	override fun addAll(elements: Collection): Boolean {
		var addedAny = false
		for (element in elements)
			if (add(element))
				addedAny = true

		if (!addedAny) return false

		sort()
		return true
	}


	override fun clear() {
		container.clear()
	}


	override fun contains(element: E) =
		container.contains(element)


	override fun containsAll(elements: Collection) =
		container.containsAll(elements)


	override fun isEmpty() =
		container.isEmpty()


	override fun iterator() =
		container.iterator()


	override fun remove(element: E) =
		container.remove(element)


	override fun removeAll(elements: Collection) =
		container.removeAll(elements)


	override fun retainAll(elements: Collection) =
		container.retainAll(elements)


	override val size
		get() = container.size


	private fun sort() {
		(container as MutableList>).sort()
	}
}


internal actual fun  _sortedSetOf(vararg elements: T) =
	_SortedSet(*elements)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy