/** * Parses the given string using the type class provided and returns an * instance. * * Default time zone is used (UTC) for dynamic types (timestamps/intervals). * * @param str string to parse * @param typeClass class of the desired type * @return an instance of the type class, or null if <em>str</em> is null or * empty */ public static Object parse(String str, Class typeClass) { return parse(str, typeClass, null); }
/** * Parses the given string using the type class provided and returns an * instance. * * Default time zone is used (UTC) for dynamic types (timestamps/intervals). * * @param str string to parse * @param typeClass class of the desired type * @return an instance of the type class, or null if <em>str</em> is null or * empty */ public static Object parse(String str, Class typeClass) { return parse(str, typeClass, null); }
private static <T extends Number> T parseNumberWithDecimals(Class<T> typeClass, String valString) { valString = infinityIgnoreCase(valString); return (T) AttributeUtils.parse(valString, typeClass); }
private static <T extends Number> T parseNumberWithoutDecimals(Class<T> typeClass, String valString) { valString = removeDecimalDigitsFromString(valString); return (T) AttributeUtils.parse(valString, typeClass); }
private static <T extends Number> T parseNumberWithDecimals(Class<T> typeClass, String valString) { valString = infinityIgnoreCase(valString); return (T) AttributeUtils.parse(valString, typeClass); }
private static <T extends Number> T parseNumberWithoutDecimals(Class<T> typeClass, String valString) { valString = removeDecimalDigitsFromString(valString); return (T) AttributeUtils.parse(valString, typeClass); }
protected Object parseValue(String value, Class type, String column) { try { return AttributeUtils.parse(value, type); } catch (Exception e) { logError(getMessage("AbstractImportProcess.error.parseError", value, type.getSimpleName(), column)); return null; } }
@Override public boolean stopCellEditing() { String value = getCellEditorValue().toString(); if (!value.trim().isEmpty()) { try { AttributeUtils.parse(value, typeClass); } catch (Exception e) { textField.setBorder(RED_BORDER); return false;//Invalid value for type } } return super.stopCellEditing(); }
/** * Converts a string parsed with {@link #parseValue(java.io.StringReader)} * to the target type, taking into account dynamic parsing quirks such as * numbers with/without decimals and infinity values. * * @param <T> Target type * @param typeClass Target type class * @param valString String to parse * @return Converted value */ protected static <T> T convertValue(Class<T> typeClass, String valString) { Object value; if (typeClass.equals(Byte.class) || typeClass.equals(byte.class) || typeClass.equals(Short.class) || typeClass .equals(short.class) || typeClass.equals(Integer.class) || typeClass.equals(int.class) || typeClass .equals(Long.class) || typeClass.equals(long.class) || typeClass.equals(BigInteger.class)) { value = parseNumberWithoutDecimals((Class<? extends Number>) typeClass, valString); } else if (typeClass.equals(Float.class) || typeClass.equals(float.class) || typeClass.equals(Double.class) || typeClass .equals(double.class) || typeClass.equals(BigDecimal.class)) { value = parseNumberWithDecimals((Class<? extends Number>) typeClass, valString); } else { value = AttributeUtils.parse(valString, typeClass); } if (value == null) { throw new IllegalArgumentException("Invalid value for type: " + valString); } return (T) value; }
@Override public void setValueAsString(String value) { row.setAttribute(column, AttributeUtils.parse(value, column.getTypeClass())); } }
/** * Converts a string parsed with {@link #parseValue(java.io.StringReader)} * to the target type, taking into account dynamic parsing quirks such as * numbers with/without decimals and infinity values. * * @param <T> Target type * @param typeClass Target type class * @param valString String to parse * @return Converted value */ protected static <T> T convertValue(Class<T> typeClass, String valString) { Object value; if (typeClass.equals(Byte.class) || typeClass.equals(byte.class) || typeClass.equals(Short.class) || typeClass .equals(short.class) || typeClass.equals(Integer.class) || typeClass.equals(int.class) || typeClass .equals(Long.class) || typeClass.equals(long.class) || typeClass.equals(BigInteger.class)) { value = parseNumberWithoutDecimals((Class<? extends Number>) typeClass, valString); } else if (typeClass.equals(Float.class) || typeClass.equals(float.class) || typeClass.equals(Double.class) || typeClass .equals(double.class) || typeClass.equals(BigDecimal.class)) { value = parseNumberWithDecimals((Class<? extends Number>) typeClass, valString); } else { value = AttributeUtils.parse(valString, typeClass); } if (value == null) { throw new IllegalArgumentException("Invalid value for type: " + valString); } return (T) value; }
@Override public void setValueAsString(String value) { setValueToAllElements(AttributeUtils.parse(value, column.getTypeClass())); } }
Object val = AttributeUtils.parse(value, col.getTypeClass()); element.setAttribute(col, val); } catch (Exception e) {
Object defaultVal = null; try { defaultVal = !defaultValue.isEmpty() ? AttributeUtils.parse(defaultValue, type) : null; } catch (Exception e) {
parsed = new BigDecimal(value); } else { parsed = AttributeUtils.parse(value, clazz);
Object valueObj = null; try { valueObj = AttributeUtils.parse(value, column.getTypeClass()); element.setValue(column.getId(), valueObj); } catch (Exception e) {
value = AttributeUtils.parse(stringValue, targetType);//Try to convert to target type from string representation } catch (Exception ex) { return false;//Could not parse