Table

@Serializable(with = Table.RowsSerializer::class)
class Table<T>(source)

Collection where each value has a stable identifier.

Constructors

Link copied to clipboard
constructor()
constructor(initialCapacity: Int)
constructor(table: Table<T>)
constructor(map: Map<TableRowId, T>)
constructor(values: Collection<T>)

Types

Link copied to clipboard
class RowsSerializer<T>(valueSerializer: KSerializer<T>) : KSerializer<Table<T>>

Table serialiser that serialises the table as a map, mapping each row id to its respective value.

Link copied to clipboard
class ValuesSerializer<T>(valueSerializer: KSerializer<T>) : KSerializer<Table<T>>

Table serialiser that serialises the values of the table as a list, ignoring the ids of all table rows.

Properties

Link copied to clipboard

Set of all identifiers of the table.

Link copied to clipboard

Identifier of the next row (when incremented automatically).

Link copied to clipboard

Set of all rows of the table.

Link copied to clipboard
val size: Int

Size of the table.

Link copied to clipboard

Collection of all values of the table.

Functions

Link copied to clipboard
fun add(value: T): TableRowId

Adds a new row with the provided value to the table. Returns the identifier of the newly added row.

Link copied to clipboard

Adds all provided values to the table. Returns a list with the identifiers of all newly added rows.

Link copied to clipboard
fun addAllAt(index: Int, values: Collection<T>): List<TableRowId>

Adds all provided values to the table at the provided index. Returns a list with the identifiers of all newly added rows.

Link copied to clipboard
fun addAt(index: Int, value: T): TableRowId

Adds a new row with the provided value at the provided index. Returns the identifier of the newly added row.

Link copied to clipboard
fun clear()

Clears the table by removing all of its rows.

Link copied to clipboard
inline operator fun contains(value: T): Boolean

Whether the table contains a row with the provided value.

inline operator fun contains(id: TableRowId): Boolean

Whether the table contains a row with the provided id.

Link copied to clipboard

Whether the table contains a row with the provided id.

Link copied to clipboard
fun containsValue(value: T): Boolean

Whether the table contains a row with the provided value.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
operator fun get(id: TableRowId): T?

Returns the value of the row with the provided id.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun idAt(index: Int): TableRowId

Returns the identifier of the row at the provided index.

Link copied to clipboard

Returns the index of the row with the provided id or -1 when no such row exists.

Link copied to clipboard
fun indexOfValue(value: T): Int

Returns the index of the row with the provided value or -1 when no such row exists.

Link copied to clipboard

Whether the table is empty.

Link copied to clipboard
fun lastIndexOfValue(value: T): Int

Returns the last index of the row with the provided value or -1 when no such row exists.

Link copied to clipboard
inline operator fun minusAssign(id: TableRowId)

Removes the row with the provided id. This simply calls remove while ignoring the returned element. If you require knowing which element was removed, use remove instead.

Link copied to clipboard
inline operator fun plusAssign(value: T)

Adds a new row with the provided value to the table. This simply calls add while ignoring the returned identifier. If you require knowing the identifier of the newly added row, use add instead.

Link copied to clipboard
fun remove(id: TableRowId): T?

Removes the row with the provided id. Returns the element of the removed row or null if no such row exists.

Link copied to clipboard
fun removeAt(index: Int): TableRow<T>

Removes the row at the provided index. Returns the removed row.

Link copied to clipboard
fun rowAt(index: Int): TableRow<T>

Returns the row at the provided index.

Link copied to clipboard
operator fun set(id: TableRowId, value: T): T?

Sets the value of a row with the provided id. If no such row exists, then it will be created. Returns the value previously at said row or null if no such row existed.

Link copied to clipboard
fun setAt(index: Int, value: T): T?

Sets the value of the row at the provided index. If index == size, a new row is added. Returns the value previously at said row or null if no such row existed.

Link copied to clipboard
fun subList(fromIndex: Int, toIndex: Int): List<TableRow<T>>

Returns a sub-list representation of the table from index fromIndex (inclusive) to index toIndex (exclusive).

Link copied to clipboard

Creates a new Map from a table.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun <T> Table<T>.toTable(): Table<T>

Creates a copy of the provided table.

Link copied to clipboard
fun valueAt(index: Int): T

Returns the value of the row at the provided index.