@Override public Config configVal(final String path) throws InvalidValuePathException, InvalidValueTypeException { return (Config) val(path); }
@Override public String stringVal(final String path) throws InvalidValuePathException, NoSuchElementException { return (String) val(path); }
@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 void val(final String path, final Object val) throws InvalidValuePathException, InvalidValueTypeException { final int sepPos = path.indexOf(pathSep); if(sepPos == 0 || sepPos == path.length() - 1) { throw new InvalidValuePathException(path); } if(sepPos > 0) { final String key = path.substring(0, sepPos); final String childPath = path.substring(sepPos + 1); val(key, childPath, val); } else { leafVal(path, val); } }
@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 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 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 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 @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()); } } }
@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()); } } }