org.pkl.thirdparty.kotlin.collections.CollectionsJVM.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.
*/
@file:org.pkl.thirdparty.kotlin.jvm.JvmMultifileClass
@file:org.pkl.thirdparty.kotlin.jvm.JvmName("CollectionsKt")
package org.pkl.thirdparty.kotlin.collections
import org.pkl.thirdparty.kotlin.collections.builders.ListBuilder
import org.pkl.thirdparty.kotlin.internal.InlineOnly
import org.pkl.thirdparty.kotlin.internal.apiVersionIsAtLeast
/**
* Returns an immutable list containing only the specified object [element].
* The returned list is serializable.
* @sample samples.collections.Collections.Lists.singletonReadOnlyList
*/
public fun listOf(element: T): List = java.util.Collections.singletonList(element)
@PublishedApi
@SinceKotlin("1.3")
@org.pkl.thirdparty.kotlin.internal.InlineOnly
internal actual inline fun buildListInternal(builderAction: MutableList.() -> Unit): List {
return build(createListBuilder().apply(builderAction))
}
@PublishedApi
@SinceKotlin("1.3")
@org.pkl.thirdparty.kotlin.internal.InlineOnly
internal actual inline fun buildListInternal(capacity: Int, builderAction: MutableList.() -> Unit): List {
return build(createListBuilder(capacity).apply(builderAction))
}
@PublishedApi
@SinceKotlin("1.3")
internal fun createListBuilder(): MutableList {
return ListBuilder()
}
@PublishedApi
@SinceKotlin("1.3")
internal fun createListBuilder(capacity: Int): MutableList {
return ListBuilder(capacity)
}
@PublishedApi
@SinceKotlin("1.3")
internal fun build(builder: MutableList): List {
return (builder as ListBuilder).build()
}
/**
* Returns a list containing the elements returned by this enumeration
* in the order they are returned by the enumeration.
* @sample samples.collections.Collections.Lists.listFromEnumeration
*/
@org.pkl.thirdparty.kotlin.internal.InlineOnly
public inline fun java.util.Enumeration.toList(): List = java.util.Collections.list(this)
/**
* Returns a new list with the elements of this list randomly shuffled.
*/
@SinceKotlin("1.2")
public actual fun Iterable.shuffled(): List = toMutableList().apply { shuffle() }
/**
* Returns a new list with the elements of this list randomly shuffled
* using the specified [random] instance as the source of randomness.
*/
@SinceKotlin("1.2")
public fun Iterable.shuffled(random: java.util.Random): List = toMutableList().apply { shuffle(random) }
@org.pkl.thirdparty.kotlin.internal.InlineOnly
internal actual inline fun copyToArrayImpl(collection: Collection<*>): Array =
org.pkl.thirdparty.kotlin.jvm.internal.collectionToArray(collection)
@org.pkl.thirdparty.kotlin.internal.InlineOnly
@Suppress("UNCHECKED_CAST")
internal actual inline fun copyToArrayImpl(collection: Collection<*>, array: Array): Array =
org.pkl.thirdparty.kotlin.jvm.internal.collectionToArray(collection, array as Array) as Array
// copies typed varargs array to array of objects
internal actual fun Array.copyToArrayOfAny(isVarargs: Boolean): Array =
if (isVarargs && this.javaClass == Array::class.java)
// if the array came from varargs and already is array of Any, copying isn't required
@Suppress("UNCHECKED_CAST") (this as Array)
else
java.util.Arrays.copyOf(this, this.size, Array::class.java)
@PublishedApi
@SinceKotlin("1.3")
@InlineOnly
internal actual inline fun checkIndexOverflow(index: Int): Int {
if (index < 0) {
if (apiVersionIsAtLeast(1, 3, 0))
throwIndexOverflow()
else
throw ArithmeticException("Index overflow has happened.")
}
return index
}
@PublishedApi
@SinceKotlin("1.3")
@InlineOnly
internal actual inline fun checkCountOverflow(count: Int): Int {
if (count < 0) {
if (apiVersionIsAtLeast(1, 3, 0))
throwCountOverflow()
else
throw ArithmeticException("Count overflow has happened.")
}
return count
}
@Suppress("NOTHING_TO_INLINE")
internal actual inline fun brittleContainsOptimizationEnabled(): Boolean = CollectionSystemProperties.brittleContainsOptimizationEnabled
internal object CollectionSystemProperties {
@JvmField
internal val brittleContainsOptimizationEnabled: Boolean =
System.getProperty("org.pkl.thirdparty.kotlin.collections.convert_arg_to_set_in_removeAll")?.toBoolean() ?: false
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy