Skip to content

Commit

Permalink
Ryan's Impl of SimpleTypeMap
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Aug 14, 2024
1 parent 893d644 commit 900d34a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
43 changes: 41 additions & 2 deletions Util/src/main/java/io/deephaven/util/SimpleTypeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,56 @@

public final class SimpleTypeMap<V> {

public static <V> SimpleTypeMap<V> create(V forBoolean, V forChar, V forByte, V forShort, V forInt, V forLong,
V forFloat, V forDouble, V forObject) {
/**
* Create a mapping from type {@link Class classes} to a value.
*
* @param forBoolean The mapping for {@code boolean} types (<em>note</em> {@link Boolean} maps to {@code forObject})
* @param forChar The mapping for {@code char} and {@link Character} types
* @param forByte The mapping for {@code byte} and {@link Byte} types
* @param forShort The mapping for {@code short} and {@link Short} types
* @param forInt The mapping for {@code int} and {@link Integer} types
* @param forLong The mapping for {@code long} and {@link Long} types
* @param forFloat The mapping for {@code float} and {@link Float} types
* @param forDouble The mapping for {@code double} and {@link Double} types
* @param forObject The mapping for all other types
* @return A SimpleTypeMap to the provided values
*/
public static <V> SimpleTypeMap<V> create(
V forBoolean,
V forChar,
V forByte,
V forShort,
V forInt,
V forLong,
V forFloat,
V forDouble,
V forObject) {
final HashMap<Class<?>, V> map = new HashMap<>();

map.put(boolean.class, forBoolean);
// Note: Booleans are treated as Objects, unlike other boxed primitives

map.put(char.class, forChar);
map.put(Character.class, forChar);

map.put(byte.class, forByte);
map.put(Byte.class, forByte);

map.put(short.class, forShort);
map.put(Short.class, forShort);

map.put(int.class, forInt);
map.put(Integer.class, forInt);

map.put(long.class, forLong);
map.put(Long.class, forLong);

map.put(float.class, forFloat);
map.put(Float.class, forFloat);

map.put(double.class, forDouble);
map.put(Double.class, forDouble);

return new SimpleTypeMap<>(map, forObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ private static Map<String, Class<?>> makeNameToTypeDict(final String[] names,
}

public static Class<?> getVectorType(Class<?> declaredType) {
if (declaredType == boolean.class || declaredType == Boolean.class) {
return ObjectVector.class;
}
return VectorFactory.forElementType(TypeUtils.getUnboxedType(declaredType)).vectorType();
return VectorFactory.forElementType(declaredType).vectorType();
}

@Override
Expand Down

0 comments on commit 900d34a

Please sign in to comment.