kotlin.UShortArray.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-stdlib-common Show documentation
Show all versions of kotlin-stdlib-common Show documentation
Kotlin Common Standard Library (legacy, use kotlin-stdlib instead)
/*
* Copyright 2010-2023 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.
*/
// Auto-generated file. DO NOT EDIT!
package kotlin
import kotlin.jvm.*
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@JvmInline
public value class UShortArray
@PublishedApi
internal constructor(@PublishedApi internal val storage: ShortArray) : Collection {
/** Creates a new array of the specified [size], with all elements initialized to zero. */
public constructor(size: Int) : this(ShortArray(size))
/**
* Returns the array element at the given [index]. This method can be called using the index operator.
*
* If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
public operator fun get(index: Int): UShort = storage[index].toUShort()
/**
* Sets the element at the given [index] to the given [value]. This method can be called using the index operator.
*
* If the [index] is out of bounds of this array, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
public operator fun set(index: Int, value: UShort) {
storage[index] = value.toShort()
}
/** Returns the number of elements in the array. */
public override val size: Int get() = storage.size
/** Creates an iterator over the elements of the array. */
public override operator fun iterator(): kotlin.collections.Iterator = Iterator(storage)
private class Iterator(private val array: ShortArray) : kotlin.collections.Iterator {
private var index = 0
override fun hasNext() = index < array.size
override fun next() = if (index < array.size) array[index++].toUShort() else throw NoSuchElementException(index.toString())
}
override fun contains(element: UShort): Boolean {
// TODO: Eliminate this check after KT-30016 gets fixed.
// Currently JS BE does not generate special bridge method for this method.
@Suppress("USELESS_CAST")
if ((element as Any?) !is UShort) return false
return storage.contains(element.toShort())
}
override fun containsAll(elements: Collection): Boolean {
return (elements as Collection<*>).all { it is UShort && storage.contains(it.toShort()) }
}
override fun isEmpty(): Boolean = this.storage.size == 0
}
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function.
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray(size: Int, init: (Int) -> UShort): UShortArray {
return UShortArray(ShortArray(size) { index -> init(index).toShort() })
}
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ushortArrayOf(vararg elements: UShort): UShortArray = elements