Skip to content

Commit 8832682

Browse files
authored
refactor: make utility classes UnboxTransform and ToChunkTypeTransform public (deephaven#6338)
1 parent 7657ff5 commit 8832682

File tree

5 files changed

+52
-33
lines changed

5 files changed

+52
-33
lines changed

Util/function/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55

66
dependencies {
77
api project(':qst-type')
8+
implementation project(':engine-query-constants')
89

910
compileOnly libs.jetbrains.annotations
1011

extensions/kafka/src/main/java/io/deephaven/kafka/UnboxTransform.java Util/function/src/main/java/io/deephaven/function/UnboxTransform.java

+39-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
//
22
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
33
//
4-
package io.deephaven.kafka;
5-
6-
import io.deephaven.function.ToByteFunction;
7-
import io.deephaven.function.ToCharFunction;
8-
import io.deephaven.function.ToDoubleFunction;
9-
import io.deephaven.function.ToFloatFunction;
10-
import io.deephaven.function.ToIntFunction;
11-
import io.deephaven.function.ToLongFunction;
12-
import io.deephaven.function.ToObjectFunction;
13-
import io.deephaven.function.ToPrimitiveFunction;
14-
import io.deephaven.function.ToShortFunction;
15-
import io.deephaven.function.TypedFunction;
4+
package io.deephaven.function;
5+
166
import io.deephaven.qst.type.ArrayType;
177
import io.deephaven.qst.type.BoxedBooleanType;
188
import io.deephaven.qst.type.BoxedByteType;
@@ -27,20 +17,21 @@
2717
import io.deephaven.qst.type.GenericType;
2818
import io.deephaven.qst.type.InstantType;
2919
import io.deephaven.qst.type.StringType;
30-
import io.deephaven.util.type.TypeUtils;
3120

3221
import java.util.Objects;
3322
import java.util.Optional;
3423

35-
class UnboxTransform {
24+
import static io.deephaven.util.QueryConstants.*;
25+
26+
public class UnboxTransform {
3627

3728
private static final ToByteFunction<Byte> UNBOX_BYTE = TypeUtils::unbox;
3829
private static final ToCharFunction<Character> UNBOX_CHAR = TypeUtils::unbox;
3930
private static final ToShortFunction<Short> UNBOX_SHORT = TypeUtils::unbox;
4031
private static final ToIntFunction<Integer> UNBOX_INT = TypeUtils::unbox;
4132
private static final ToLongFunction<Long> UNBOX_LONG = TypeUtils::unbox;
4233
private static final ToFloatFunction<Float> UNBOX_FLOAT = TypeUtils::unbox;
43-
private static final ToDoubleFunction<Double> UNBOX_DOULE = TypeUtils::unbox;
34+
private static final ToDoubleFunction<Double> UNBOX_DOUBLE = TypeUtils::unbox;
4435

4536
/**
4637
* Returns the Deephaven unboxed equivalent of {@code f}. Relevant for all {@link BoxedType boxed types} except the
@@ -161,7 +152,7 @@ public static <T> ToFloatFunction<T> unboxFloat(ToObjectFunction<T, Float> f) {
161152
* @see TypeUtils#unbox(Double)
162153
*/
163154
public static <T> ToDoubleFunction<T> unboxDouble(ToObjectFunction<T, Double> f) {
164-
return f.mapToDouble(UNBOX_DOULE);
155+
return f.mapToDouble(UNBOX_DOUBLE);
165156
}
166157

167158
private enum UnboxFunctionVisitor implements TypedFunction.Visitor<Object, ToPrimitiveFunction<Object>> {
@@ -264,4 +255,36 @@ public ToPrimitiveFunction<T> visit(BoxedDoubleType doubleType) {
264255
return unboxDouble(f.cast(doubleType));
265256
}
266257
}
258+
259+
// TODO: Clean up dependencies to be able to use io.deephaven.util.type.TypeUtils.
260+
private static class TypeUtils {
261+
public static byte unbox(Byte value) {
262+
return (value == null ? NULL_BYTE : value);
263+
}
264+
265+
public static char unbox(Character value) {
266+
return (value == null ? NULL_CHAR : value);
267+
}
268+
269+
public static double unbox(Double value) {
270+
return (value == null ? NULL_DOUBLE : value);
271+
}
272+
273+
public static float unbox(Float value) {
274+
return (value == null ? NULL_FLOAT : value);
275+
}
276+
277+
public static int unbox(Integer value) {
278+
return (value == null ? NULL_INT : value);
279+
}
280+
281+
public static long unbox(Long value) {
282+
return (value == null ? NULL_LONG : value);
283+
}
284+
285+
public static short unbox(Short value) {
286+
return (value == null ? NULL_SHORT : value);
287+
}
288+
289+
}
267290
}

extensions/kafka/src/main/java/io/deephaven/kafka/ProtobufImpl.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
import io.deephaven.api.ColumnName;
1818
import io.deephaven.engine.table.ColumnDefinition;
1919
import io.deephaven.engine.table.TableDefinition;
20-
import io.deephaven.function.ToObjectFunction;
21-
import io.deephaven.function.ToPrimitiveFunction;
22-
import io.deephaven.function.TypedFunction;
20+
import io.deephaven.function.*;
2321
import io.deephaven.kafka.KafkaTools.Consume;
2422
import io.deephaven.kafka.KafkaTools.KeyOrValue;
2523
import io.deephaven.kafka.KafkaTools.KeyOrValueIngestData;
@@ -38,6 +36,7 @@
3836
import io.deephaven.protobuf.ProtobufFunction;
3937
import io.deephaven.protobuf.ProtobufFunctions;
4038
import io.deephaven.protobuf.ProtobufFunctions.Builder;
39+
import io.deephaven.function.ToChunkTypeTransform;
4140
import io.deephaven.qst.type.Type;
4241
import io.deephaven.util.annotations.VisibleForTesting;
4342
import io.deephaven.util.mutable.MutableInt;

extensions/protobuf/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies {
99
api project(':util-function')
1010
api libs.protobuf.java
1111
implementation project(':engine-query-constants')
12+
implementation project(':engine-time')
1213

1314
compileOnly project(':util-immutables')
1415
annotationProcessor libs.immutables.value

extensions/kafka/src/main/java/io/deephaven/kafka/ToChunkTypeTransform.java extensions/protobuf/src/main/java/io/deephaven/function/ToChunkTypeTransform.java

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
//
22
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
33
//
4-
package io.deephaven.kafka;
4+
package io.deephaven.function;
55

6-
import io.deephaven.function.ToByteFunction;
7-
import io.deephaven.function.ToLongFunction;
8-
import io.deephaven.function.ToObjectFunction;
9-
import io.deephaven.function.ToPrimitiveFunction;
10-
import io.deephaven.function.TypedFunction;
116
import io.deephaven.qst.type.ArrayType;
127
import io.deephaven.qst.type.BoxedBooleanType;
138
import io.deephaven.qst.type.BoxedByteType;
@@ -28,15 +23,15 @@
2823
import java.time.Instant;
2924
import java.util.Objects;
3025

31-
import static io.deephaven.kafka.UnboxTransform.unboxByte;
32-
import static io.deephaven.kafka.UnboxTransform.unboxChar;
33-
import static io.deephaven.kafka.UnboxTransform.unboxDouble;
34-
import static io.deephaven.kafka.UnboxTransform.unboxFloat;
35-
import static io.deephaven.kafka.UnboxTransform.unboxInt;
36-
import static io.deephaven.kafka.UnboxTransform.unboxLong;
37-
import static io.deephaven.kafka.UnboxTransform.unboxShort;
26+
import static io.deephaven.function.UnboxTransform.unboxByte;
27+
import static io.deephaven.function.UnboxTransform.unboxChar;
28+
import static io.deephaven.function.UnboxTransform.unboxDouble;
29+
import static io.deephaven.function.UnboxTransform.unboxFloat;
30+
import static io.deephaven.function.UnboxTransform.unboxInt;
31+
import static io.deephaven.function.UnboxTransform.unboxLong;
32+
import static io.deephaven.function.UnboxTransform.unboxShort;
3833

39-
class ToChunkTypeTransform {
34+
public class ToChunkTypeTransform {
4035

4136
private static final ToByteFunction<Boolean> BOOLEAN_AS_BYTE = BooleanUtils::booleanAsByte;
4237
private static final ToLongFunction<Instant> EPOCH_NANOS = DateTimeUtils::epochNanos;

0 commit comments

Comments
 (0)