org.babyfish.jimmer.sql.ast.tuple.Tuple3.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jimmer-sql Show documentation
Show all versions of jimmer-sql Show documentation
A revolutionary ORM framework for both java and kotlin
package org.babyfish.jimmer.sql.ast.tuple
import org.babyfish.jimmer.sql.ast.impl.TupleImplementor
import java.util.function.BiFunction
data class Tuple3(
val _1: T1,
val _2: T2,
val _3: T3
) : TupleImplementor {
override fun size(): Int = 3
override operator fun get(index: Int): Any? =
when (index) {
0 -> _1
1 -> _2
2 -> _3
else -> throw IllegalArgumentException("Index must between 0 and ${size() - 1}")
}
override fun convert(block: BiFunction): TupleImplementor =
Tuple3(
block.apply(_1, 0),
block.apply(_2, 1),
block.apply(_3, 2)
)
companion object {
@JvmStatic
@Suppress("UNCHECKED_CAST")
fun projection1(tuples: Collection>) : Collection =
TupleImplementor.projection(tuples, 0) as Collection
@JvmStatic
@Suppress("UNCHECKED_CAST")
fun projection2(tuples: Collection>) : Collection =
TupleImplementor.projection(tuples, 1) as Collection
@JvmStatic
@Suppress("UNCHECKED_CAST")
fun projection3(tuples: Collection>) : Collection =
TupleImplementor.projection(tuples, 2) as Collection
}
}