Skip to content

Commit

Permalink
Added static factors methods for use in Java.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppanopticon committed Jan 17, 2024
1 parent 066e678 commit b9420bc
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.vitrivr.cottontail.grpc.CottontailGrpc
* This is an abstraction over a [Boolean].
*
* @author Ralph Gasser
* @version 2.0.0
* @version 2.1.0
*/
@Serializable
@SerialName("Boolean")
Expand All @@ -24,7 +24,16 @@ value class BooleanValue(override val value: Boolean): ScalarValue<Boolean>, Pub

/** The false [BooleanValue]. */
val FALSE = BooleanValue(false)

/**
* A static helper class to use this [BooleanValue] in plain Java.
*
* @param value [Boolean] to create [BooleanValue] from
*/
@JvmStatic
fun of(value: Boolean) = BooleanValue(value)
}

/** The logical size of this [BooleanValue]. */
override val logicalSize: Int
get() = 1
Expand All @@ -35,7 +44,7 @@ value class BooleanValue(override val value: Boolean): ScalarValue<Boolean>, Pub

/**
* Compares this [BooleanValue] to another [Value]. Returns -1, 0 or 1 of other value is smaller,
* equal or greater than this value. [BooleanValue] can only be compared to other [NumericValue]s.
* equal or greater than this value. [BooleanValue] can only be compared to other [BooleanValue]s.
*
* @param other Value to compare to.
* @return -1, 0 or 1 of other value is smaller, equal or greater than this value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@ import kotlin.math.pow
* This is an abstraction over a [BooleanArray] and it represents a vector of [Boolean]s.
*
* @author Ralph Gasser
* @version 2.0.0
* @version 2.1.0
*/
@Serializable
@SerialName("BooleanVector")
@JvmInline
value class BooleanVectorValue(val data: BooleanArray) : RealVectorValue<Int>, PublicValue {

companion object {
/**
* A static helper class to use this [BooleanVectorValue] in plain Java.
*
* @param array [BooleanArray] to create [BooleanVectorValue] from
*/
@JvmStatic
fun of(array: BooleanArray) = BooleanVectorValue(array)
}

constructor(input: List<Number>) : this(BooleanArray(input.size) { input[it].toInt() == 1 })
constructor(input: Array<Number>) : this(BooleanArray(input.size) { input[it].toInt() == 1 })
constructor(input: Array<Boolean>) : this(BooleanArray(input.size) { input[it] })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.vitrivr.cottontail.grpc.CottontailGrpc
* This is an abstraction over a [Byte].
*
* @author Ralph Gasser
* @version 2.0.0
* @version 2.1.0
*/
@Serializable
@SerialName("Byte")
Expand All @@ -35,6 +35,14 @@ value class ByteValue(override val value: Byte): RealValue<Byte>, PublicValue {

/** The one [ByteValue]. */
val ONE = ByteValue(1.toByte())

/**
* A static helper class to use this [ByteValue] in plain Java.
*
* @param value [Byte] to create [ByteValue] from
*/
@JvmStatic
fun of(value: Byte) = ByteValue(value)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ import java.util.*
* This is an abstraction over a [Date].
*
* @author Ralph Gasser
* @version 2.0.0
* @version 2.1.0
*/
@Serializable
@SerialName("Date")
@JvmInline
value class DateValue(override val value: Long) : ScalarValue<Long>, PublicValue {

companion object {
/**
* A static helper class to use this [DateValue] in plain Java.
*
* @param array [Date] to create [DateValue] from
*/
@JvmStatic
fun of(array: Date) = DateValue(array)
}

/**
* Converts a [Date] to a [DateValue].
*
Expand All @@ -37,7 +47,7 @@ value class DateValue(override val value: Long) : ScalarValue<Long>, PublicValue

/**
* Compares this [LongValue] to another [Value]. Returns -1, 0 or 1 of other value is smaller,
* equal or greater than this value. [LongValue] can only be compared to other [NumericValue]s.
* equal or greater than this value. [LongValue] can only be compared to other [ScalarValue]s.
*
* @param other Value to compare to.
* @return -1, 0 or 1 of other value is smaller, equal or greater than this value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import kotlin.math.pow
* This is an abstraction over a [Double].
*
* @author Ralph Gasser
* @version 2.0.0
* @version 2.1.0
*/
@Serializable
@SerialName("Double")
@JvmInline
value class DoubleValue(override val value: Double): RealValue<Double>, PublicValue{

companion object {
/**
* The minimum value that can be held by a [DoubleValue].
Expand All @@ -42,6 +41,14 @@ value class DoubleValue(override val value: Double): RealValue<Double>, PublicVa

/** The infinity [DoubleValue]. */
val INF = DoubleValue(Double.POSITIVE_INFINITY)

/**
* A static helper class to use this [DoubleValue] in plain Java.
*
* @param array [Double] to create [DoubleValue] from
*/
@JvmStatic
fun of(array: Double) = DoubleValue(array)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ import kotlin.math.pow
@SerialName("DoubleVector")
@JvmInline
value class DoubleVectorValue(val data: DoubleArray) : RealVectorValue<Double>, PublicValue {
companion object {
/**
* A static helper class to use this [DoubleVectorValue] in plain Java.
*
* @param array [DoubleArray] to create [DoubleVectorValue] from
*/
@JvmStatic
fun of(array: DoubleArray) = DoubleVectorValue(array)
}

constructor(input: List<Number>) : this(DoubleArray(input.size) { input[it].toDouble() })
constructor(input: Array<Number>) : this(DoubleArray(input.size) { input[it].toDouble() })
constructor(input: FloatArray) : this(DoubleArray(input.size) { input[it].toDouble() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ value class FloatValue(override val value: Float): RealValue<Float>, PublicValue

/** The INF [FloatValue]. */
val INF = FloatValue(Float.POSITIVE_INFINITY)

/**
* A static helper class to use this [FloatValue] in plain Java.
*
* @param value [Float] to create [FloatValue] from
*/
@JvmStatic
fun of(value: Float) = FloatValue(value)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ import kotlin.math.pow
* This is an abstraction over a [FloatArray] and it represents a vector of [Float]s.
*
* @author Ralph Gasser
* @version 2.1.0
* @version 2.2.0
*/
@Serializable
@SerialName("FloatVector")
@JvmInline
value class FloatVectorValue(val data: FloatArray) : RealVectorValue<Float>, PublicValue {
companion object {
/**
* A static helper class to use this [FloatVectorValue] in plain Java.
*
* @param array [FloatArray] to create [FloatVectorValue] from
*/
@JvmStatic
fun of(array: FloatArray) = FloatVectorValue(array)
}

constructor(input: List<Number>) : this(FloatArray(input.size) { input[it].toFloat() })
constructor(input: Array<Number>) : this(FloatArray(input.size) { input[it].toFloat() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ import kotlin.math.absoluteValue
import kotlin.math.pow

/**
* This is an abstraction over a [FloatArray] and it represents a vector of [Float]s, which are stored using half-precision
*
* @author Ralph Gasser
* @version 1.0
* @author Luca Rossetto
* @version 1.1.0
*/
@Serializable
@SerialName("HalfVector")
@JvmInline
value class HalfVectorValue(val data: FloatArray) : RealVectorValue<Float>, PublicValue {
companion object {
/**
* A static helper class to use this [HalfVectorValue] in plain Java.
*
* @param array [FloatArray] to create [HalfVectorValue] from
*/
@JvmStatic
fun of(array: FloatArray) = HalfVectorValue(array)
}

constructor(input: List<Number>) : this(FloatArray(input.size) { input[it].toFloat() })
constructor(input: Array<Number>) : this(FloatArray(input.size) { input[it].toFloat() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.vitrivr.cottontail.grpc.CottontailGrpc
* This is an abstraction over an [Int].
*
* @author Ralph Gasser
* @version 2.0.0
* @version 2.1.0
*/
@Serializable
@SerialName("Integer")
Expand All @@ -35,6 +35,14 @@ value class IntValue(override val value: Int): RealValue<Int>, PublicValue {

/** The zero [IntValue]. */
val ONE = IntValue(1)

/**
* A static helper class to use this [IntValue] in plain Java.
*
* @param value [Int] to create [IntValue] from
*/
@JvmStatic
fun of(value: Int) = IntValue(value)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ import kotlin.math.pow
* This is an abstraction over an [IntArray] and it represents a vector of [Int]s.
*
* @author Ralph Gasser
* @version 2.1.0
* @version 2.20
*/
@Serializable
@SerialName("IntegerVector")
@JvmInline
value class IntVectorValue(val data: IntArray) : RealVectorValue<Int>, PublicValue {
companion object {
/**
* A static helper class to use this [IntVectorValue] in plain Java.
*
* @param array [IntArray] to create [IntVectorValue] from
*/
@JvmStatic
fun of(array: IntArray) = IntVectorValue(array)
}

constructor(input: List<Number>) : this(IntArray(input.size) { input[it].toInt() })
constructor(input: Array<Number>) : this(IntArray(input.size) { input[it].toInt() })
constructor(input: DoubleArray) : this(IntArray(input.size) { input[it].toInt() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.vitrivr.cottontail.grpc.CottontailGrpc
* This is an abstraction over a [Long].
*
* @author Ralph Gasser
* @version 2.0.0
* @version 2.1.0
*/
@Serializable
@SerialName("Long")
Expand All @@ -35,6 +35,14 @@ value class LongValue(override val value: Long): RealValue<Long>, PublicValue {

/** The one [LongValue]. */
val ONE = LongValue(1L)

/**
* A static helper class to use this [LongValue] in plain Java.
*
* @param value [Long] to create [LongValue] from
*/
@JvmStatic
fun of(value: Long) = LongValue(value)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ import kotlin.math.pow
* This is an abstraction over a [LongArray] and it represents a vector of [Long]s.
*
* @author Ralph Gasser
* @version 2.1.0
* @version 2.2.0
*/
@Serializable
@SerialName("LongVector")
@JvmInline
value class LongVectorValue(val data: LongArray) : RealVectorValue<Long>, PublicValue {
companion object {
/**
* A static helper class to use this [LongVectorValue] in plain Java.
*
* @param array [LongArray] to create [LongVectorValue] from
*/
@JvmStatic
fun of(array: LongArray) = LongVectorValue(array)
}

constructor(input: List<Number>) : this(LongArray(input.size) { input[it].toLong() })
constructor(input: Array<Number>) : this(LongArray(input.size) { input[it].toLong() })
constructor(input: DoubleArray) : this(LongArray(input.size) { input[it].toLong() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.vitrivr.cottontail.grpc.CottontailGrpc
* This is an abstraction over a [Short].
*
* @author Ralph Gasser
* @version 2.0.0
* @version 2.1.0
*/
@Serializable
@SerialName("Short")
Expand All @@ -34,6 +34,14 @@ value class ShortValue(override val value: Short): RealValue<Short>, PublicValue

/** The one [ShortValue]. */
val ONE = ShortValue(1.toShort())

/**
* A static helper class to use this [ShortValue] in plain Java.
*
* @param value [Short] to create [ShortValue] from
*/
@JvmStatic
fun of(value: Short) = ShortValue(value)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import kotlin.math.pow
@SerialName("ShortVector")
@JvmInline
value class ShortVectorValue(val data: ShortArray) : RealVectorValue<Short>, PublicValue {


constructor(input: List<Number>) : this(ShortArray(input.size) { input[it].toShort() })
constructor(input: Array<Number>) : this(ShortArray(input.size) { input[it].toShort() })
constructor(input: DoubleArray) : this(ShortArray(input.size) { input[it].toInt().toShort() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.vitrivr.cottontail.grpc.CottontailGrpc
* This is a [Value] abstraction over a [String].
*
* @author Ralph Gasser
* @version 2.0.0
* @version 2.1.0
*/
@Serializable
@SerialName("String")
Expand All @@ -21,6 +21,14 @@ value class StringValue(override val value: String) : ScalarValue<String>, Publi
companion object {
/** The empty [StringValue]. */
val EMPTY = StringValue("")

/**
* A static helper class to use this [StringValue] in plain Java.
*
* @param value [String] to create [StringValue] from
*/
@JvmStatic
fun of(value: String) = StringValue(value)
}

/** The logical size of this [StringValue]. */
Expand Down
Loading

0 comments on commit b9420bc

Please sign in to comment.