From 7e612ba9afe730e3423f86dc3d698538c4083e79 Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Tue, 16 Jul 2024 16:55:58 -0500 Subject: [PATCH] Proposed changes to finish cleaning these types --- .../plot/util/ArgumentValidations.java | 40 ++++++++--------- .../deephaven/util/type/NumericTypeUtils.java | 41 +++++++++++++++++ .../io/deephaven/util/type/TypeUtils.java | 44 +++---------------- .../table/impl/by/AggregationProcessor.java | 2 +- .../impl/preview/ColumnPreviewManager.java | 3 +- .../deephaven/engine/util/TestTypeUtils.java | 17 +++---- .../table/ops/ColumnStatisticsGrpcImpl.java | 3 +- 7 files changed, 82 insertions(+), 68 deletions(-) create mode 100644 Util/src/main/java/io/deephaven/util/type/NumericTypeUtils.java diff --git a/Plot/src/main/java/io/deephaven/plot/util/ArgumentValidations.java b/Plot/src/main/java/io/deephaven/plot/util/ArgumentValidations.java index f23c4c28920..91616c5dbf2 100644 --- a/Plot/src/main/java/io/deephaven/plot/util/ArgumentValidations.java +++ b/Plot/src/main/java/io/deephaven/plot/util/ArgumentValidations.java @@ -4,7 +4,6 @@ package io.deephaven.plot.util; import io.deephaven.base.verify.Require; -import io.deephaven.base.verify.RequirementFailure; import io.deephaven.configuration.Configuration; import io.deephaven.engine.table.ColumnDefinition; import io.deephaven.plot.datasets.data.IndexableNumericData; @@ -13,6 +12,7 @@ import io.deephaven.plot.util.tables.TableHandle; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.TableDefinition; +import io.deephaven.util.type.NumericTypeUtils; import io.deephaven.util.type.TypeUtils; import org.apache.commons.lang3.ClassUtils; @@ -362,24 +362,24 @@ public static boolean isTime(final Class c, final PlotInfo plotInfo) { } /** - * Whether the class is {@link TypeUtils#isNumeric(Class)} or {@link #isTime(Class, PlotInfo)} + * Whether the class is {@link NumericTypeUtils#isNumeric(Class)} or {@link #isTime(Class, PlotInfo)} * * @param c class * @return true if {@code c} is a numeric or time class, false otherwise */ public static boolean isNumericOrTime(final Class c) { - return TypeUtils.isNumeric(c) || isTime(c, null); + return NumericTypeUtils.isNumeric(c) || isTime(c, null); } /** - * Whether the class is {@link TypeUtils#isNumeric(Class)} or {@link #isTime(Class, PlotInfo)} + * Whether the class is {@link NumericTypeUtils#isNumeric(Class)} or {@link #isTime(Class, PlotInfo)} * * @param c class * @param plotInfo source of the exception * @return true if {@code c} is a numeric or time class, false otherwise */ public static boolean isNumericOrTime(final Class c, final PlotInfo plotInfo) { - return TypeUtils.isNumeric(c) || isTime(c, plotInfo); + return NumericTypeUtils.isNumeric(c) || isTime(c, plotInfo); } /** @@ -432,7 +432,7 @@ public static boolean isPrimitiveNumeric(final Table t, final String column, fin } /** - * Whether the column's data type {@link TypeUtils#isBoxedNumeric(Class)}. + * Whether the column's data type {@link NumericTypeUtils#isBoxedNumeric(Class)}. * * @param t table * @param column column @@ -441,11 +441,11 @@ public static boolean isPrimitiveNumeric(final Table t, final String column, fin */ public static boolean isBoxedNumeric(final Table t, final String column, final PlotInfo plotInfo) { assertNotNull(t, "t", plotInfo); - return TypeUtils.isBoxedNumeric(getColumnType(t, column, plotInfo)); + return NumericTypeUtils.isBoxedNumeric(getColumnType(t, column, plotInfo)); } /** - * Whether the column's data type {@link TypeUtils#isNumeric(Class)}. + * Whether the column's data type {@link NumericTypeUtils#isNumeric(Class)}. * * @param t table * @param column column @@ -454,11 +454,11 @@ public static boolean isBoxedNumeric(final Table t, final String column, final P */ public static boolean isNumeric(final Table t, final String column, final PlotInfo plotInfo) { assertNotNull(t, "t", plotInfo); - return TypeUtils.isNumeric(getColumnType(t, column, plotInfo)); + return NumericTypeUtils.isNumeric(getColumnType(t, column, plotInfo)); } /** - * Whether the column's data type {@link TypeUtils#isNumeric(Class)}. + * Whether the column's data type {@link NumericTypeUtils#isNumeric(Class)}. * * @param t table * @param column column @@ -467,11 +467,11 @@ public static boolean isNumeric(final Table t, final String column, final PlotIn */ public static boolean isNumeric(final TableDefinition t, final String column, final PlotInfo plotInfo) { assertNotNull(t, "t", plotInfo); - return TypeUtils.isNumeric(getColumnType(t, column, plotInfo)); + return NumericTypeUtils.isNumeric(getColumnType(t, column, plotInfo)); } /** - * Whether the column's data type {@link TypeUtils#isNumeric(Class)}. + * Whether the column's data type {@link NumericTypeUtils#isNumeric(Class)}. * * @param sds selectable dataset * @param column column @@ -480,7 +480,7 @@ public static boolean isNumeric(final TableDefinition t, final String column, fi */ public static boolean isNumeric(final SelectableDataSet sds, final String column, final PlotInfo plotInfo) { assertNotNull(sds, "t", plotInfo); - return TypeUtils.isNumeric(getColumnType(sds, column, plotInfo)); + return NumericTypeUtils.isNumeric(getColumnType(sds, column, plotInfo)); } /** @@ -616,7 +616,7 @@ public static void assertIsPrimitiveNumeric(final Table t, final String column, /** * Requires the column's data type to be an instance of {@link Number} as defined in - * {@link TypeUtils#isBoxedNumeric(Class)} + * {@link NumericTypeUtils#isBoxedNumeric(Class)} * * @throws RuntimeException if the column's data type isn't an instance of {@link Number} * @param t table @@ -631,7 +631,7 @@ public static void assertIsBoxedNumeric(final Table t, final String column, fina /** * Requires the column's data type to be an instance of {@link Number} as defined in - * {@link TypeUtils#isBoxedNumeric(Class)} + * {@link NumericTypeUtils#isBoxedNumeric(Class)} * * @throws RuntimeException if the column's data type isn't an instance of {@link Number} * @param t table @@ -649,7 +649,7 @@ public static void assertIsBoxedNumeric(final Table t, final String column, fina /** - * Requires the column's data type to be a numeric instance as defined in {@link TypeUtils#isNumeric(Class)} + * Requires the column's data type to be a numeric instance as defined in {@link NumericTypeUtils#isNumeric(Class)} * * @throws PlotRuntimeException if the column's data type isn't a numeric instance * @param t table @@ -663,7 +663,7 @@ public static void assertIsNumeric(final Table t, final String column, final Plo /** - * Requires the column's data type to be a numeric instance as defined in {@link TypeUtils#isNumeric(Class)} + * Requires the column's data type to be a numeric instance as defined in {@link NumericTypeUtils#isNumeric(Class)} * * @throws PlotRuntimeException if the column's data type isn't a numeric instance * @param t table @@ -677,7 +677,7 @@ public static void assertIsNumeric(final TableDefinition t, final String column, /** - * Requires the column's data type to be a numeric instance as defined in {@link TypeUtils#isNumeric(Class)} + * Requires the column's data type to be a numeric instance as defined in {@link NumericTypeUtils#isNumeric(Class)} * * @throws PlotRuntimeException if the column's data type isn't a numeric instance * @param t table @@ -695,7 +695,7 @@ public static void assertIsNumeric(final Table t, final String column, final Str /** - * Requires the column's data type to be a numeric instance as defined in {@link TypeUtils#isNumeric(Class)} + * Requires the column's data type to be a numeric instance as defined in {@link NumericTypeUtils#isNumeric(Class)} * * @throws PlotRuntimeException if the column's data type isn't a numeric instance * @param t table @@ -713,7 +713,7 @@ public static void assertIsNumeric(final TableDefinition t, final String column, /** - * Requires the column's data type to be a numeric instance as defined in {@link TypeUtils#isNumeric(Class)} + * Requires the column's data type to be a numeric instance as defined in {@link NumericTypeUtils#isNumeric(Class)} * * @throws PlotRuntimeException if the column's data type isn't a numeric instance * @param sds selectable dataset diff --git a/Util/src/main/java/io/deephaven/util/type/NumericTypeUtils.java b/Util/src/main/java/io/deephaven/util/type/NumericTypeUtils.java new file mode 100644 index 00000000000..eecd35acaaf --- /dev/null +++ b/Util/src/main/java/io/deephaven/util/type/NumericTypeUtils.java @@ -0,0 +1,41 @@ +package io.deephaven.util.type; + +import org.jetbrains.annotations.NotNull; + +import java.math.BigDecimal; +import java.math.BigInteger; + +public class NumericTypeUtils { + private NumericTypeUtils() {} + + + /** + * Whether the class is an instance of {@link Number}. + * + * @param c class + * @return true if Number.class is assignable from {@code c}, false otherwise + */ + public static boolean isBoxedNumeric(@NotNull final Class c) { + return Number.class.isAssignableFrom(c); + } + + /** + * Whether the class is {@link TypeUtils#isPrimitiveNumeric(Class)} or {@link #isBoxedNumeric(Class)} + * + * @param c class + * @return true if {@code c} is numeric, false otherwise + */ + public static boolean isNumeric(@NotNull final Class c) { + return TypeUtils.isPrimitiveNumeric(c) || isBoxedNumeric(c); + } + + /** + * Whether the class is a {@link BigInteger} or {@link BigDecimal} + * + * @param type the class + * @return true if the type is BigInteger or BigDecimal, false otherwise + */ + public static boolean isBigNumeric(Class type) { + return BigInteger.class.isAssignableFrom(type) || BigDecimal.class.isAssignableFrom(type); + } +} diff --git a/Util/src/main/java/io/deephaven/util/type/TypeUtils.java b/Util/src/main/java/io/deephaven/util/type/TypeUtils.java index faab3d554bb..ad69ffc6fb5 100644 --- a/Util/src/main/java/io/deephaven/util/type/TypeUtils.java +++ b/Util/src/main/java/io/deephaven/util/type/TypeUtils.java @@ -7,8 +7,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import java.math.BigDecimal; -import java.math.BigInteger; import java.time.Instant; import java.time.ZonedDateTime; import java.util.*; @@ -55,6 +53,10 @@ public class TypeUtils { .unmodifiableMap(PRIMITIVE_TYPES.stream().collect(Collectors.toMap(Class::getName, type -> type))); } + /** + * Deprecated with no replacement. + */ + @Deprecated @Retention(RetentionPolicy.RUNTIME) public @interface IsDateTime { boolean value() default true; @@ -380,16 +382,6 @@ public static boolean isPrimitiveNumeric(@NotNull final Class c) { || c == int.class || c == long.class || c == short.class || c == byte.class; } - /** - * Whether the class is an instance of {@link Number}. - * - * @param c class - * @return true if Number.class is assignable from {@code c}, false otherwise - */ - public static boolean isBoxedNumeric(@NotNull final Class c) { - return Number.class.isAssignableFrom(c); - } - /** * Whether the class is equal to char.class. * @@ -490,16 +482,6 @@ public static boolean isBoxedBoolean(@NotNull final Class c) { return Boolean.class == c; } - /** - * Whether the class is {@link #isPrimitiveNumeric(Class)} or {@link #isBoxedNumeric(Class)} - * - * @param c class - * @return true if {@code c} is numeric, false otherwise - */ - public static boolean isNumeric(@NotNull final Class c) { - return isPrimitiveNumeric(c) || isBoxedNumeric(c); - } - /** * Whether the class equals char.class or Character.class is assignable from it. * @@ -511,15 +493,13 @@ public static boolean isCharacter(@NotNull final Class c) { } /** - * Whether the class is an {@link Instant}, a {@link ZonedDateTime}, or annotated as {@link IsDateTime}. + * Whether the class is an {@link Instant} or a {@link ZonedDateTime}. * * @param type The class. - * @return true if the type is a DateTime, {@link java.time.ZonedDateTime} or {@link Instant}. + * @return true if the type is a DateTime: {@link java.time.ZonedDateTime} or {@link Instant}. */ public static boolean isDateTime(Class type) { - return Instant.class.isAssignableFrom(type) - || ZonedDateTime.class.isAssignableFrom(type) - || (type.getAnnotation(IsDateTime.class) != null && type.getAnnotation(IsDateTime.class).value()); + return Instant.class == type || ZonedDateTime.class == type; } /** @@ -532,16 +512,6 @@ public static boolean isString(Class type) { return String.class == type; } - /** - * Whether the class is a {@link BigInteger} or {@link BigDecimal} - * - * @param type the class - * @return true if the type is BigInteger or BigDecimal, false otherwise - */ - public static boolean isBigNumeric(Class type) { - return BigInteger.class.isAssignableFrom(type) || BigDecimal.class.isAssignableFrom(type); - } - /** * Checks if the type is a primitive or Boxed floate type (double or float). * diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/by/AggregationProcessor.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/by/AggregationProcessor.java index f57ac5dae87..ab1d7e83929 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/by/AggregationProcessor.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/by/AggregationProcessor.java @@ -125,7 +125,7 @@ import static io.deephaven.engine.table.impl.by.RollupConstants.*; import static io.deephaven.util.QueryConstants.*; import static io.deephaven.util.type.TypeUtils.getBoxedType; -import static io.deephaven.util.type.TypeUtils.isNumeric; +import static io.deephaven.util.type.NumericTypeUtils.isNumeric; /** * Conversion tool to generate an {@link AggregationContextFactory} for a collection of {@link Aggregation diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/preview/ColumnPreviewManager.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/preview/ColumnPreviewManager.java index 3a12528b431..2e04cd0d712 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/preview/ColumnPreviewManager.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/preview/ColumnPreviewManager.java @@ -6,6 +6,7 @@ import io.deephaven.configuration.Configuration; import io.deephaven.engine.table.ColumnDefinition; import io.deephaven.engine.table.Table; +import io.deephaven.util.type.NumericTypeUtils; import io.deephaven.vector.Vector; import io.deephaven.engine.table.impl.BaseTable; import io.deephaven.engine.table.impl.select.FunctionalColumn; @@ -155,7 +156,7 @@ public static boolean isColumnTypeDisplayable(Class type) { return type.isPrimitive() || io.deephaven.util.type.TypeUtils.isBoxedType(type) || io.deephaven.util.type.TypeUtils.isString(type) - || io.deephaven.util.type.TypeUtils.isBigNumeric(type) + || NumericTypeUtils.isBigNumeric(type) || TypeUtils.isDateTime(type) || isOnWhiteList(type); } diff --git a/engine/table/src/test/java/io/deephaven/engine/util/TestTypeUtils.java b/engine/table/src/test/java/io/deephaven/engine/util/TestTypeUtils.java index 627f8bbd529..5e607356581 100644 --- a/engine/table/src/test/java/io/deephaven/engine/util/TestTypeUtils.java +++ b/engine/table/src/test/java/io/deephaven/engine/util/TestTypeUtils.java @@ -4,6 +4,7 @@ package io.deephaven.engine.util; import io.deephaven.base.verify.Require; +import io.deephaven.util.type.NumericTypeUtils; import junit.framework.TestCase; import org.apache.commons.lang3.ArrayUtils; @@ -133,15 +134,15 @@ public void testIsType() { assertTrue(io.deephaven.util.type.TypeUtils.isPrimitiveNumeric(int.class)); assertFalse(io.deephaven.util.type.TypeUtils.isPrimitiveNumeric(Double.class)); - assertFalse(io.deephaven.util.type.TypeUtils.isBoxedNumeric(Instant.class)); - assertFalse(io.deephaven.util.type.TypeUtils.isBoxedNumeric(Date.class)); - assertFalse(io.deephaven.util.type.TypeUtils.isBoxedNumeric(int.class)); - assertTrue(io.deephaven.util.type.TypeUtils.isBoxedNumeric(Double.class)); + assertFalse(NumericTypeUtils.isBoxedNumeric(Instant.class)); + assertFalse(NumericTypeUtils.isBoxedNumeric(Date.class)); + assertFalse(NumericTypeUtils.isBoxedNumeric(int.class)); + assertTrue(NumericTypeUtils.isBoxedNumeric(Double.class)); - assertFalse(io.deephaven.util.type.TypeUtils.isNumeric(Instant.class)); - assertFalse(io.deephaven.util.type.TypeUtils.isNumeric(Date.class)); - assertTrue(io.deephaven.util.type.TypeUtils.isNumeric(int.class)); - assertTrue(io.deephaven.util.type.TypeUtils.isNumeric(Double.class)); + assertFalse(NumericTypeUtils.isNumeric(Instant.class)); + assertFalse(NumericTypeUtils.isNumeric(Date.class)); + assertTrue(NumericTypeUtils.isNumeric(int.class)); + assertTrue(NumericTypeUtils.isNumeric(Double.class)); assertFalse(io.deephaven.util.type.TypeUtils.isCharacter(Instant.class)); assertFalse(io.deephaven.util.type.TypeUtils.isCharacter(Date.class)); diff --git a/server/src/main/java/io/deephaven/server/table/ops/ColumnStatisticsGrpcImpl.java b/server/src/main/java/io/deephaven/server/table/ops/ColumnStatisticsGrpcImpl.java index 6418219308f..e99f3062edb 100644 --- a/server/src/main/java/io/deephaven/server/table/ops/ColumnStatisticsGrpcImpl.java +++ b/server/src/main/java/io/deephaven/server/table/ops/ColumnStatisticsGrpcImpl.java @@ -22,6 +22,7 @@ import io.deephaven.server.table.stats.ChunkedStatsKernel; import io.deephaven.server.table.stats.DateTimeChunkedStats; import io.deephaven.server.table.stats.ObjectChunkedStats; +import io.deephaven.util.type.NumericTypeUtils; import io.deephaven.util.type.TypeUtils; import org.apache.commons.lang3.mutable.Mutable; import org.apache.commons.lang3.mutable.MutableObject; @@ -80,7 +81,7 @@ public Table create(ColumnStatisticsRequest request, List