public Object getVal(String key) { return getMapVal(key); }
public String getStr(String key, String def) { if (ROOT_OBJ.equals(key)) { Object obj = getRootPrimitive(); return obj == def ? null : String.valueOf(obj); } Object o = getMapVal(key); return o == null ? def : String.valueOf(o); }
/** * Get all the values from the metadata for the command * without the specified keys */ public Map<String, Object> getValuesExcluding(String... keys) { getMapVal(null); if (hasError()) return emptyMap();//just to verify the type is Map @SuppressWarnings("unchecked") LinkedHashMap<String, Object> cp = new LinkedHashMap<>((Map<String, Object>) commandData); if (keys == null) return cp; for (String key : keys) { cp.remove(key); } return cp; }
/** * Get collection of values for a key. If only one val is present a * single value collection is returned */ public List<String> getStrs(String key, List<String> def) { Object v = null; if (ROOT_OBJ.equals(key)) { v = getRootPrimitive(); } else { v = getMapVal(key); } if (v == null) { return def; } else { if (v instanceof List) { ArrayList<String> l = new ArrayList<>(); for (Object o : (List) v) { l.add(String.valueOf(o)); } if (l.isEmpty()) return def; return l; } else { return singletonList(String.valueOf(v)); } } }
public Map getMap(String key, Map def) { Object o = getMapVal(key); if (o == null) return def; if (!(o instanceof Map)) { addError(StrUtils.formatString("''{0}'' must be a map", key)); return def; } else { return (Map) o; } }