private static String getDesc(ConfigValue refValue) { if (refValue instanceof AbstractConfigObject) { AbstractConfigObject obj = (AbstractConfigObject) refValue; if (obj.isEmpty()) return "object"; else return "object with keys " + obj.keySet(); } else if (refValue instanceof SimpleConfigList) { return "list"; } else { return refValue.valueType().name().toLowerCase(); } }
@Override public final int hashCode() { // we do the "41*" just so our hash code won't match that of the // underlying object. there's no real reason it can't match, but // making it not match might catch some kinds of bug. return 41 * object.hashCode(); }
@Override public final boolean equals(Object other) { if (other instanceof SimpleConfig) { return object.equals(((SimpleConfig) other).object); } else { return false; } }
// path is null if we're at the root private static void checkValidObject( Path path, AbstractConfigObject reference, AbstractConfigObject value, List<ConfigException.ValidationProblem> accumulator) { for (Map.Entry<String, ConfigValue> entry : reference.entrySet()) { String key = entry.getKey(); Path childPath; if (path != null) childPath = Path.newKey(key).prepend(path); else childPath = Path.newKey(key); AbstractConfigValue v = value.get(key); if (v == null) { addMissing(accumulator, entry.getValue(), childPath, value.origin()); } else { checkValid(childPath, entry.getValue(), v, accumulator); } } }
@Override public boolean hasPath(String pathExpression) { Path path = Path.newPath(pathExpression); ConfigValue peeked; try { peeked = object.peekPath(path); } catch (ConfigException.NotResolved e) { throw ConfigImpl.improveNotResolved(path, e); } return peeked != null && peeked.valueType() != ConfigValueType.NULL; }
private static AbstractConfigValue findKey( AbstractConfigObject self, String key, ConfigValueType expected, Path originalPath) { AbstractConfigValue v = self.peekAssumingResolved(key, originalPath); if (v == null) throw new ConfigException.Missing(originalPath.render()); if (expected != null) v = DefaultTransformer.transform(v, expected); if (v.valueType() == ConfigValueType.NULL) throw new ConfigException.Null( v.origin(), originalPath.render(), expected != null ? expected.name() : null); else if (expected != null && v.valueType() != expected) throw new ConfigException.WrongType( v.origin(), originalPath.render(), expected.name(), v.valueType().name()); else return v; }
private static void findPaths( Set<Map.Entry<String, ConfigValue>> entries, Path parent, AbstractConfigObject obj) { for (Map.Entry<String, ConfigValue> entry : obj.entrySet()) { String elem = entry.getKey(); ConfigValue v = entry.getValue(); Path path = Path.newKey(elem); if (parent != null) path = path.prepend(parent); if (v instanceof AbstractConfigObject) { findPaths(entries, path, (AbstractConfigObject) v); } else if (v instanceof ConfigNull) { // nothing; nulls are conceptually not in a Config } else { entries.add(new AbstractMap.SimpleImmutableEntry<String, ConfigValue>(path.render(), v)); } } }
@Override public boolean isEmpty() { return object.isEmpty(); }
@Override public ConfigOrigin origin() { return object.origin(); }
@Override public String toString() { return "Config(" + object.toString() + ")"; }
@Override public SimpleConfig withFallback(ConfigMergeable other) { // this can return "this" if the withFallback doesn't need a new // ConfigObject return object.withFallback(other).toConfig(); }
private static AbstractConfigValue findInObject( AbstractConfigObject obj, ResolveContext context, SubstitutionExpression subst) throws NotPossibleToResolve { return obj.peekPath(subst.path(), context); }