MCPcopy Create free account
hub / github.com/badvision/jace / deserializeString

Method deserializeString

src/main/java/jace/core/Utility.java:327–371  ·  view source on GitHub ↗
(String value, Class type, boolean hex)

Source from the content-addressed store, hash-verified

325 }
326
327 @SuppressWarnings("all")
328 public static Object deserializeString(String value, Class type, boolean hex) {
329 int radix = hex ? 16 : 10;
330 if (type.equals(Integer.TYPE) || type == Integer.class) {
331 value = value.replaceAll(hex ? "[^0-9\\-A-Fa-f]" : "[^0-9\\-]", "");
332 try {
333 return Integer.valueOf(value, radix);
334 } catch (NumberFormatException ex) {
335 return null;
336 }
337 } else if (type.equals(Short.TYPE) || type == Short.class) {
338 value = value.replaceAll(hex ? "[^0-9\\-\\.A-Fa-f]" : "[^0-9\\-\\.]", "");
339 try {
340 return Short.valueOf(value, radix);
341 } catch (NumberFormatException ex) {
342 return null;
343 }
344 } else if (type.equals(Long.TYPE) || type == Long.class) {
345 value = value.replaceAll(hex ? "[^0-9\\-\\.A-Fa-f]" : "[^0-9\\-\\.]", "");
346 try {
347 return Long.valueOf(value, radix);
348 } catch (NumberFormatException ex) {
349 return null;
350 }
351 } else if (type.equals(Byte.TYPE) || type == Byte.class) {
352 try {
353 value = value.replaceAll(hex ? "[^0-9\\-A-Fa-f]" : "[^0-9\\-]", "");
354 return Byte.valueOf(value, radix);
355 } catch (NumberFormatException ex) {
356 return null;
357 }
358 } else if (type.equals(Boolean.TYPE) || type == Boolean.class) {
359 return Boolean.valueOf(value);
360 } else if (type.equals(Float.TYPE) || type == Float.class) {
361 return Float.parseFloat(value);
362 } else if (type.equals(Double.TYPE) || type == Double.class) {
363 return Double.parseDouble(value);
364 } else if (type == File.class) {
365 return new File(String.valueOf(value));
366 } else if (type.isEnum()) {
367 value = value.replaceAll("[\\.\\s\\-]", "");
368 return findClosestEnumConstant(value, type);
369 }
370 return null;
371 }
372
373 public static Function<Boolean, Boolean> getNamedInvokableAction(String action) {
374 InvokableActionRegistry registry = InvokableActionRegistry.getInstance();

Callers 1

doApplyMethod · 0.95

Calls 2

equalsMethod · 0.45

Tested by

no test coverage detected