|
1 | 1 | //
|
2 | 2 | // Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
|
3 | 3 | //
|
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 | + |
16 | 6 | import io.deephaven.qst.type.ArrayType;
|
17 | 7 | import io.deephaven.qst.type.BoxedBooleanType;
|
18 | 8 | import io.deephaven.qst.type.BoxedByteType;
|
|
27 | 17 | import io.deephaven.qst.type.GenericType;
|
28 | 18 | import io.deephaven.qst.type.InstantType;
|
29 | 19 | import io.deephaven.qst.type.StringType;
|
30 |
| -import io.deephaven.util.type.TypeUtils; |
31 | 20 |
|
32 | 21 | import java.util.Objects;
|
33 | 22 | import java.util.Optional;
|
34 | 23 |
|
35 |
| -class UnboxTransform { |
| 24 | +import static io.deephaven.util.QueryConstants.*; |
| 25 | + |
| 26 | +public class UnboxTransform { |
36 | 27 |
|
37 | 28 | private static final ToByteFunction<Byte> UNBOX_BYTE = TypeUtils::unbox;
|
38 | 29 | private static final ToCharFunction<Character> UNBOX_CHAR = TypeUtils::unbox;
|
39 | 30 | private static final ToShortFunction<Short> UNBOX_SHORT = TypeUtils::unbox;
|
40 | 31 | private static final ToIntFunction<Integer> UNBOX_INT = TypeUtils::unbox;
|
41 | 32 | private static final ToLongFunction<Long> UNBOX_LONG = TypeUtils::unbox;
|
42 | 33 | 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; |
44 | 35 |
|
45 | 36 | /**
|
46 | 37 | * 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) {
|
161 | 152 | * @see TypeUtils#unbox(Double)
|
162 | 153 | */
|
163 | 154 | public static <T> ToDoubleFunction<T> unboxDouble(ToObjectFunction<T, Double> f) {
|
164 |
| - return f.mapToDouble(UNBOX_DOULE); |
| 155 | + return f.mapToDouble(UNBOX_DOUBLE); |
165 | 156 | }
|
166 | 157 |
|
167 | 158 | private enum UnboxFunctionVisitor implements TypedFunction.Visitor<Object, ToPrimitiveFunction<Object>> {
|
@@ -264,4 +255,36 @@ public ToPrimitiveFunction<T> visit(BoxedDoubleType doubleType) {
|
264 | 255 | return unboxDouble(f.cast(doubleType));
|
265 | 256 | }
|
266 | 257 | }
|
| 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 | + } |
267 | 290 | }
|
0 commit comments