@Override public char charVal(final String path) throws InvalidValueTypeException, NoSuchElementException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Character.TYPE, null); } try { return (char) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Character.TYPE, v.getClass()); } }
@Override public float floatVal(final String path) throws InvalidValueTypeException, NoSuchElementException, NumberFormatException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Float.TYPE, null); } else if(v instanceof String) { return Float.parseFloat((String) v); } else { try { return (float) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Float.TYPE, v.getClass()); } } }
@Override public byte byteVal(final String path) throws InvalidValueTypeException, NoSuchElementException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Byte.TYPE, null); } else if(v instanceof String) { return Byte.parseByte((String) v); } else { try { return (byte) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Byte.TYPE, v.getClass()); } } }
@Override public short shortVal(final String path) throws InvalidValueTypeException, NoSuchElementException, NumberFormatException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Short.TYPE, null); } else if(v instanceof String) { return Short.parseShort((String) v); } else { try { return (short) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Short.TYPE, v.getClass()); } } }
@Override public boolean boolVal(final String path) throws InvalidValuePathException, InvalidValueTypeException, NoSuchElementException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Boolean.TYPE, null); } else if(v instanceof String) { return Boolean.parseBoolean((String) v); } else { try { return (boolean) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Boolean.TYPE, v.getClass()); } } }
@Override public int intVal(final String path) throws InvalidValuePathException, NoSuchElementException, NumberFormatException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Integer.TYPE, null); } else if(v instanceof String) { return Integer.parseInt((String) v); } else if(v instanceof Short) { return (short) v; } else { try { return (int) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Integer.TYPE, v.getClass()); } } }
@Override @SuppressWarnings("unchecked") public <E> List<E> listVal(final String path) throws InvalidValuePathException, NoSuchElementException { final Object v = val(path); try { return (List<E>) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, List.class, v.getClass()); } }
@Override public double doubleVal(final String path) throws InvalidValuePathException, NoSuchElementException, NumberFormatException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Double.TYPE, null); } else if(v instanceof String) { return Double.parseDouble((String) v); } else if(v instanceof Float) { return (float) v; } else { try { return (double) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Double.TYPE, v.getClass()); } } }
@Override public long longVal(final String path) throws InvalidValuePathException, NoSuchElementException, NumberFormatException { final Object v = val(path); if(v == null) { throw new InvalidValueTypeException(path, Long.TYPE, null); } else if(v instanceof String) { return Long.parseLong((String) v); } else if(v instanceof Short) { return (short) v; } else if(v instanceof Integer) { return (int) v; } else { try { return (long) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Long.TYPE, v.getClass()); } } }
protected void putLeaf(final String key, final Class<?> expectedValType, final Object val) throws InvalidValuePathException, InvalidValueTypeException { if(val == null) { if(expectedValType.isPrimitive()) { throw new InvalidValueTypeException(key, expectedValType, null); } else { node.put(key, null); } } else { final Class<?> actualValType = val.getClass(); if(typeEquals(expectedValType, actualValType)) { node.put(key, val); } else { try { node.put(key, typeConvert(val, expectedValType)); } catch(final ClassCastException e) { throw new InvalidValueTypeException(key, expectedValType, actualValType); } } } }
@Override @SuppressWarnings("unchecked") public <V> Map<String, V> mapVal(final String path) throws InvalidValuePathException, NoSuchElementException { final Object v = val(path); if(v instanceof Config) { return ((Config) v).mapVal(ROOT_PATH); } else { try { return (Map<String, V>) v; } catch(final ClassCastException e) { throw new InvalidValueTypeException(path, Map.class, v.getClass()); } } }
throw new InvalidValuePathException(key + pathSep + e.path()); } catch(final InvalidValueTypeException e) { throw new InvalidValueTypeException( key + pathSep + e.path(), e.expectedType(), e.actualType() ); mapVal = (Map<String, Object>) prevNodeVal; } else { throw new InvalidValueTypeException(key, Map.class, prevNodeVal.getClass());
throw new InvalidValuePathException(key + pathSep + e.path()); } catch(final InvalidValueTypeException e) { throw new InvalidValueTypeException( key + pathSep + e.path(), e.expectedType(), e.actualType() ); throw new InvalidValuePathException(key + pathSep + e.path()); } catch(final InvalidValueTypeException e) { throw new InvalidValueTypeException( key + pathSep + e.path(), e.expectedType(), e.actualType() ); throw new InvalidValuePathException(key); } else { throw new InvalidValueTypeException( key, schemaVal.getClass(), val == null ? null : val.getClass() );