use of com.datastax.oss.driver.api.core.type.codec.PrimitiveDoubleCodec in project java-driver by datastax.
the class SettableByIndex method setDouble.
/**
* Sets the {@code i}th value to the provided Java primitive double.
*
* <p>By default, this works with CQL type {@code double}.
*
* <p>To set the value to CQL {@code NULL}, use {@link #setToNull(int)}, or {@code set(i, v,
* Double.class)}.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
@NonNull
@CheckReturnValue
default SelfT setDouble(int i, double v) {
DataType cqlType = getType(i);
TypeCodec<Double> codec = codecRegistry().codecFor(cqlType, Double.class);
return (codec instanceof PrimitiveDoubleCodec) ? setBytesUnsafe(i, ((PrimitiveDoubleCodec) codec).encodePrimitive(v, protocolVersion())) : set(i, v, codec);
}
use of com.datastax.oss.driver.api.core.type.codec.PrimitiveDoubleCodec in project java-driver by datastax.
the class GettableByIndex method getDouble.
/**
* Returns the {@code i}th value as a Java primitive double.
*
* <p>By default, this works with CQL type {@code double}.
*
* <p>Note that, due to its signature, this method cannot return {@code null}. If the CQL value is
* {@code NULL}, it will return {@code 0.0}. If this doesn't work for you, either call {@link
* #isNull(int)} before calling this method, or use {@code get(i, Double.class)} instead.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
default double getDouble(int i) {
DataType cqlType = getType(i);
TypeCodec<Double> codec = codecRegistry().codecFor(cqlType, Double.class);
if (codec instanceof PrimitiveDoubleCodec) {
return ((PrimitiveDoubleCodec) codec).decodePrimitive(getBytesUnsafe(i), protocolVersion());
} else {
Double value = get(i, codec);
return value == null ? 0 : value;
}
}
Aggregations