Пример #1
0
 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();
   }
 }
Пример #2
0
 @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();
 }
Пример #3
0
 @Override
 public final boolean equals(Object other) {
   if (other instanceof SimpleConfig) {
     return object.equals(((SimpleConfig) other).object);
   } else {
     return false;
   }
 }
Пример #4
0
  // 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);
      }
    }
  }
Пример #5
0
 @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;
 }
Пример #6
0
  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;
  }
Пример #7
0
 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));
     }
   }
 }
Пример #8
0
 @Override
 public boolean isEmpty() {
   return object.isEmpty();
 }
Пример #9
0
 @Override
 public ConfigOrigin origin() {
   return object.origin();
 }
Пример #10
0
 @Override
 public String toString() {
   return "Config(" + object.toString() + ")";
 }
Пример #11
0
 @Override
 public SimpleConfig withFallback(ConfigMergeable other) {
   // this can return "this" if the withFallback doesn't need a new
   // ConfigObject
   return object.withFallback(other).toConfig();
 }
Пример #12
0
 private static AbstractConfigValue findInObject(
     AbstractConfigObject obj, ResolveContext context, SubstitutionExpression subst)
     throws NotPossibleToResolve {
   return obj.peekPath(subst.path(), context);
 }