Package org.partiql.lang.util

Types

Link copied to clipboard
abstract class BindingHelper

Containing static methods intended to be invoked by Java clients, this class provides a standard way to compare identifiers and includes some helper methods for looking up values from IonStruct and Map instances according to the specified BindingCase.

Link copied to clipboard
interface ExprValueFormatter
Link copied to clipboard
class IonWriterContext(writer: IonWriter)

A simple wrapper for writing Ion from Kotlin. This is not implemented as a set of extension methods because our coding standards disallow non-private extension methods.

Link copied to clipboard
class WhenAsExpressionHelper

See case for a description of how to use this[]

Functions

Link copied to clipboard
fun IonValue.asIonInt(): IonInt
Link copied to clipboard
fun IonValue.asIonSexp(): IonSexp
Link copied to clipboard
fun IonValue.asIonStruct(): IonStruct
Link copied to clipboard
fun IonValue.asIonSymbol(): IonSymbol
Link copied to clipboard
fun IonValue.asSequence(): Sequence<IonValue>
Link copied to clipboard
fun IonValue.bigDecimalValue(): BigDecimal
Link copied to clipboard
fun IonValue.bigDecimalValueOrNull(): BigDecimal?
Link copied to clipboard
fun IonValue.booleanValue(): Boolean
Link copied to clipboard
fun IonValue.booleanValueOrNull(): Boolean?
Link copied to clipboard
fun IonValue.bytesValue(): ByteArray
Link copied to clipboard
fun IonValue.bytesValueOrNull(): ByteArray?
Link copied to clipboard
fun <T> List<List<T>>.cartesianProduct(): List<List<T>>

Returns the cartesian product between each list in this (i.e. every possible list formed by choosing an element from each of the sublists where order matters). Elements in each sub-list must have homogeneous elements.

Link copied to clipboard
inline fun case(block: () -> Unit): WhenAsExpressionHelper

In Kotlin, the cases of a when <is <type>>... must be exhaustive only when when is used as an expression. Wrapping each of the cases in this is an attempt to allow when to be easily used as an expression even when an expression isn't actually needed. Example:

Link copied to clipboard
fun String.caseInsensitiveEquivalent(name: String): Boolean

One case insensitive equality check to rule them all.

Link copied to clipboard
fun String.codePointSequence(): Sequence<Int>

Provides a lazy sequence over the code points in the given string.

Link copied to clipboard
fun <T : Number> Number.coerce(type: Class<T>): T

Provides a narrowing or widening operator on supported numbers.

Link copied to clipboard
fun coerceNumbers(first: Number, second: Number): Pair<Number, Number>

Implements a very simple number tower to convert two numbers to their arithmetic compatible type.

Link copied to clipboard
operator fun Number.compareTo(other: Number): Int
Link copied to clipboard
operator fun Number.div(other: Number): Number
Link copied to clipboard
fun IonValue.doubleValue(): Double
Link copied to clipboard
fun IonValue.doubleValueOrNull(): Double?
Link copied to clipboard
fun <T> Any.downcast(type: Class<T>?): T?

Simple dynamic downcast for a type.

Link copied to clipboard
fun BigDecimal.exp(mathContext: MathContext = MATH_CONTEXT): BigDecimal

Computes e^x of a given BigDecimal x.

Link copied to clipboard
fun IonStruct.field(nameOfField: String): IonValue
Link copied to clipboard
fun IonSexp.filterMetaNodes(): IonValue

Creates a new IonSexp from a legacy AST IonSexp that strips out meta nodes.

Link copied to clipboard
inline fun <T, S, C> List<S>.foldLeftProduct(initialContext: C, crossinline map: (C, S) -> Iterator<Pair<C, T>>): Iterable<List<T>>

Constructs a cartesian product of the given ordered list of source elements, by computing the Iterable via a mapping function with a context. The mapping function constructs an Iterator of Pair instances of C and S that are used to derive subsequent iterators.

Link copied to clipboard
inline fun <T> List<T>.forAll(predicate: (T) -> Boolean): Boolean

Given a predicate function, return true if all members of the list satisfy the predicate, return false otherwise. In the case that an empty list is given, the result is true.

Link copied to clipboard
operator fun IonValue.get(index: Int): IonValue
operator fun IonValue.get(name: String): IonValue?
Link copied to clipboard
fun Number.ionValue(ion: IonSystem): IonValue
Link copied to clipboard
fun Iterable<ExprValue>.isAnyMissing(): Boolean

Returns true if any ExprValue in the Iterable is missing.

Link copied to clipboard
fun Iterable<ExprValue>.isAnyNull(): Boolean

Returns true if any ExprValue in the Iterable is null.

Link copied to clipboard
fun Iterable<ExprValue>.isAnyUnknown(): Boolean

Returns true if any ExprValue in the Iterable is an unknown value, i.e. either MISSING or NULL.

Link copied to clipboard
fun IonValue.isAstLiteral(): Boolean
Link copied to clipboard
fun String.isBindingNameEquivalent(other: String, case: BindingCase): Boolean

Compares this string to other using the rules specified by case.

Link copied to clipboard
operator fun IonValue.iterator(): Iterator<IonValue>
Link copied to clipboard
fun IonInt.javaValue(): Number
Link copied to clipboard
fun BigDecimal.ln(mathContext: MathContext = MATH_CONTEXT): BigDecimal

Compute the natural logarithm of a big decimal.

Link copied to clipboard
fun IonValue.longValue(): Long
Link copied to clipboard
fun IonValue.longValueOrNull(): Long?
Link copied to clipboard
operator fun Number.minus(other: Number): Number
Link copied to clipboard
fun IonValue.numberValue(): Number
Link copied to clipboard
fun IonValue.numberValueOrNull(): Number?
Link copied to clipboard
operator fun Number.plus(other: Number): Number
Link copied to clipboard
fun BigDecimal.power(power: BigDecimal, mathContext: MathContext = MATH_CONTEXT): BigDecimal

Calculate the given big decimal raised to the pth power, where p is another big decimal.

Link copied to clipboard
fun <T> List<Iterable<T>>.product(): Iterable<List<T>>

Calculates the cartesian product of the given ordered lists of collections of homogeneous values.

Link copied to clipboard
fun propertyValueMapOf(vararg properties: Pair<Property, Any>): PropertyValueMap
fun propertyValueMapOf(line: Int, column: Int, vararg otherProperties: Pair<Property, Any>): PropertyValueMap

Helper function to reduce the syntactical overhead of creating a PropertyValueMap.

Link copied to clipboard
operator fun Number.rem(other: Number): Number
Link copied to clipboard
fun IonValue.seal(): IonValue
Link copied to clipboard
fun IonSexp.singleArgWithTag(tagName: String): IonValue
Link copied to clipboard
fun IonSexp.singleArgWithTagOrNull(tagName: String): IonValue?
Link copied to clipboard
fun BigDecimal.squareRoot(mathContext: MathContext = MATH_CONTEXT): BigDecimal

Computes the square root of a given BigDecimal. See https://dl.acm.org/doi/pdf/10.1145/214408.214413

Link copied to clipboard
fun IonValue.stringValue(): String?
Link copied to clipboard
fun IonValue.stringValueOrNull(): String?
Link copied to clipboard
operator fun Number.times(other: Number): Number
Link copied to clipboard
fun IonValue.timestampValue(): Timestamp
Link copied to clipboard
fun IonValue.timestampValueOrNull(): Timestamp?
Link copied to clipboard
infix fun Property.to(that: Any): Pair<Property, Any>

Simple overloaded infix operator which accepts a Propery and value as arguments and returns a Pair. Intended to be used in conjunction with propertyValueMapOf.

Link copied to clipboard
fun Long.toIntExact(): Int

Converts this to a Int, throwing an exception in case the value is outside the range of an Int.

Link copied to clipboard
fun Iterable<IonValue>.toListOfIonSexp(): List<IonSexp>
Link copied to clipboard
operator fun Decimal.unaryMinus(): Decimal
operator fun Number.unaryMinus(): Number

Properties

Link copied to clipboard
val IonSexp.args: List<IonValue>
Link copied to clipboard
val IonSexp.arity: Int
Link copied to clipboard
val <T> List<T>.head: T?

Returns the first element of the list or null if it doesn't exist.

Link copied to clipboard
val IonValue.isBag: Boolean
Link copied to clipboard
val IonValue.isDate: Boolean
Link copied to clipboard
val IonValue.isMissing: Boolean
Link copied to clipboard
val Number.isNaN: Boolean
Link copied to clipboard
val Number.isNegInf: Boolean
Link copied to clipboard
val IonValue.isNonNullText: Boolean
Link copied to clipboard
val IonValue.isNumeric: Boolean
Link copied to clipboard
val Number.isPosInf: Boolean
Link copied to clipboard
val IonValue.isText: Boolean
Link copied to clipboard
val IonValue.isTime: Boolean
Link copied to clipboard
val IonValue.isUnsignedInteger: Boolean
Link copied to clipboard
val IonValue.lastIndex: Int
Link copied to clipboard
val IonValue.ordinal: Int
Link copied to clipboard
val IonValue.size: Int
Link copied to clipboard
val IonSexp.tagText: String
Link copied to clipboard
val <T> List<T>.tail: List<T>

Returns the sublist not including the first element which may be the empty list.