org.pkl.thirdparty.kotlin.collections.builders.SetBuilder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pkl-tools Show documentation
Show all versions of pkl-tools Show documentation
Fat Jar containing pkl-cli, pkl-codegen-java, pkl-codegen-kotlin, pkl-config-java, pkl-core, pkl-doc, and their shaded third-party dependencies.
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.pkl.thirdparty.kotlin.collections.builders
import java.io.NotSerializableException
internal class SetBuilder internal constructor(
private val backing: MapBuilder
) : MutableSet, AbstractMutableSet(), Serializable {
constructor() : this(MapBuilder())
constructor(initialCapacity: Int) : this(MapBuilder(initialCapacity))
fun build(): Set {
backing.build()
return this
}
private fun writeReplace(): Any =
if (backing.isReadOnly)
SerializedCollection(this, SerializedCollection.tagSet)
else
throw NotSerializableException("The set cannot be serialized while it is being built.")
override val size: Int get() = backing.size
override fun isEmpty(): Boolean = backing.isEmpty()
override fun contains(element: E): Boolean = backing.containsKey(element)
override fun clear() = backing.clear()
override fun add(element: E): Boolean = backing.addKey(element) >= 0
override fun remove(element: E): Boolean = backing.removeKey(element) >= 0
override fun iterator(): MutableIterator = backing.keysIterator()
override fun addAll(elements: Collection): Boolean {
backing.checkIsMutable()
return super.addAll(elements)
}
override fun removeAll(elements: Collection): Boolean {
backing.checkIsMutable()
return super.removeAll(elements)
}
override fun retainAll(elements: Collection): Boolean {
backing.checkIsMutable()
return super.retainAll(elements)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy