io.deephaven.kafka.UnboxTransform Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-extensions-kafka Show documentation
Show all versions of deephaven-extensions-kafka Show documentation
Kafka: Integrating Engine tables with Kafka
/**
* Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.kafka;
import io.deephaven.function.ToByteFunction;
import io.deephaven.function.ToCharFunction;
import io.deephaven.function.ToDoubleFunction;
import io.deephaven.function.ToFloatFunction;
import io.deephaven.function.ToIntFunction;
import io.deephaven.function.ToLongFunction;
import io.deephaven.function.ToObjectFunction;
import io.deephaven.function.ToPrimitiveFunction;
import io.deephaven.function.ToShortFunction;
import io.deephaven.function.TypedFunction;
import io.deephaven.qst.type.ArrayType;
import io.deephaven.qst.type.BoxedBooleanType;
import io.deephaven.qst.type.BoxedByteType;
import io.deephaven.qst.type.BoxedCharType;
import io.deephaven.qst.type.BoxedDoubleType;
import io.deephaven.qst.type.BoxedFloatType;
import io.deephaven.qst.type.BoxedIntType;
import io.deephaven.qst.type.BoxedLongType;
import io.deephaven.qst.type.BoxedShortType;
import io.deephaven.qst.type.BoxedType;
import io.deephaven.qst.type.CustomType;
import io.deephaven.qst.type.GenericType;
import io.deephaven.qst.type.InstantType;
import io.deephaven.qst.type.StringType;
import io.deephaven.util.type.TypeUtils;
import java.util.Objects;
import java.util.Optional;
class UnboxTransform {
private static final ToByteFunction UNBOX_BYTE = TypeUtils::unbox;
private static final ToCharFunction UNBOX_CHAR = TypeUtils::unbox;
private static final ToShortFunction UNBOX_SHORT = TypeUtils::unbox;
private static final ToIntFunction UNBOX_INT = TypeUtils::unbox;
private static final ToLongFunction UNBOX_LONG = TypeUtils::unbox;
private static final ToFloatFunction UNBOX_FLOAT = TypeUtils::unbox;
private static final ToDoubleFunction UNBOX_DOULE = TypeUtils::unbox;
/**
* Returns the Deephaven unboxed equivalent of {@code f}. Relevant for all {@link BoxedType boxed types} except the
* {@link BoxedBooleanType boxed Boolean type}. All other functions will be return unchanged.
*
* @param f the function
* @return the unboxed equivalent
* @param the input type
* @see #unboxByte(ToObjectFunction)
* @see #unboxChar(ToObjectFunction)
* @see #unboxDouble(ToObjectFunction)
* @see #unboxFloat(ToObjectFunction)
* @see #unboxInt(ToObjectFunction)
* @see #unboxLong(ToObjectFunction)
* @see #unboxShort(ToObjectFunction)
*/
public static Optional> of(TypedFunction f) {
return UnboxFunctionVisitor.of(f);
}
/**
* Returns the Deephaven unboxed equivalent of {@code f}. Relevant for all {@link BoxedType boxed types} except the
* {@link BoxedBooleanType boxed Boolean type}. All other functions will be return unchanged.
*
* @param f the object function
* @return the unboxed equivalent
* @param the input type
* @see #unboxByte(ToObjectFunction)
* @see #unboxChar(ToObjectFunction)
* @see #unboxDouble(ToObjectFunction)
* @see #unboxFloat(ToObjectFunction)
* @see #unboxInt(ToObjectFunction)
* @see #unboxLong(ToObjectFunction)
* @see #unboxShort(ToObjectFunction)
*/
public static Optional> of(ToObjectFunction f) {
return UnboxObjectFunctionVisitor.of(f);
}
/**
* Equivalent to {@code f.mapByte(TypeUtils::unbox)}.
*
* @param f the Byte function
* @return the byte function
* @param the input type
* @see TypeUtils#unbox(Byte)
*/
public static ToByteFunction unboxByte(ToObjectFunction f) {
return f.mapToByte(UNBOX_BYTE);
}
/**
* Equivalent to {@code f.mapChar(TypeUtils::unbox)}.
*
* @param f the Character function
* @return the char function
* @param the input type
* @see TypeUtils#unbox(Character)
*/
public static ToCharFunction unboxChar(ToObjectFunction f) {
return f.mapToChar(UNBOX_CHAR);
}
/**
* Equivalent to {@code f.mapShort(TypeUtils::unbox)}.
*
* @param f the Short function
* @return the short function
* @param the input type
* @see TypeUtils#unbox(Short)
*/
public static ToShortFunction unboxShort(ToObjectFunction f) {
return f.mapToShort(UNBOX_SHORT);
}
/**
* Equivalent to {@code f.mapInt(TypeUtils::unbox)}.
*
* @param f the Integer function
* @return the int function
* @param the input type
* @see TypeUtils#unbox(Integer)
*/
public static ToIntFunction unboxInt(ToObjectFunction f) {
return f.mapToInt(UNBOX_INT);
}
/**
* Equivalent to {@code f.mapLong(TypeUtils::unbox)}.
*
* @param f the Long function
* @return the long function
* @param the input type
* @see TypeUtils#unbox(Long)
*/
public static ToLongFunction unboxLong(ToObjectFunction f) {
return f.mapToLong(UNBOX_LONG);
}
/**
* Equivalent to {@code f.mapFloat(TypeUtils::unbox)}.
*
* @param f the Float function
* @return the float function
* @param the input type
* @see TypeUtils#unbox(Float)
*/
public static ToFloatFunction unboxFloat(ToObjectFunction f) {
return f.mapToFloat(UNBOX_FLOAT);
}
/**
* Equivalent to {@code f.mapDouble(TypeUtils::unbox)}.
*
* @param f the Double function
* @return the double function
* @param the input type
* @see TypeUtils#unbox(Double)
*/
public static ToDoubleFunction unboxDouble(ToObjectFunction f) {
return f.mapToDouble(UNBOX_DOULE);
}
private enum UnboxFunctionVisitor implements TypedFunction.Visitor
© 2015 - 2024 Weber Informatics LLC | Privacy Policy