Added support for all primitive types. No arrays yet. That seems more complicated

This commit is contained in:
Sander Hautvast 2020-11-10 21:17:58 +01:00
parent 10ffe459e0
commit d926ed2adc

View file

@ -8,12 +8,19 @@ public class TypeMapper {
private static final Map<Class<?>, String> MAP = new ConcurrentHashMap<>();
static {
MAP.put(byte.class, "B");
MAP.put(char.class, "C");
MAP.put(double.class, "D");
MAP.put(float.class, "F");
MAP.put(int.class, "I");
MAP.put(long.class, "J");
MAP.put(short.class, "S");
MAP.put(boolean.class, "Z");
}
public static String map(Class<?> type) {
return Optional.ofNullable(MAP.get(type))
.orElseThrow(() -> new RuntimeException("Type " + type.getName() + " not found")); //this MUST not happen -> TODO map all types
.orElseThrow(() -> new RuntimeException("Type " + type.getName() + " not found")); // this MUST not happen -> TODO map all types
}