Skip to content

Commit

Permalink
Proposed changes to finish cleaning these types
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Jul 16, 2024
1 parent 74de5c4 commit a8c9352
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 68 deletions.
40 changes: 20 additions & 20 deletions Plot/src/main/java/io/deephaven/plot/util/ArgumentValidations.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
43 changes: 43 additions & 0 deletions Util/src/main/java/io/deephaven/util/type/NumericTypeUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
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);
}
}
44 changes: 7 additions & 37 deletions Util/src/main/java/io/deephaven/util/type/TypeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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;
}

/**
Expand All @@ -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).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,7 +81,7 @@ public Table create(ColumnStatisticsRequest request, List<SessionState.ExportObj
throw Exceptions.statusRuntimeException(Code.INVALID_ARGUMENT,
"DateTime columns must be Instant or ZonedDateTime");
}
} else if (TypeUtils.isNumeric(type)) {
} else if (NumericTypeUtils.isNumeric(type)) {
// Numeric types have a variety of statistics recorded
statsFunc = ChunkedNumericalStatsKernel.makeChunkedNumericalStats(type);
columnSource = table.getColumnSource(columnName);
Expand Down

0 comments on commit a8c9352

Please sign in to comment.