Exemplo n.º 1
0
 private static boolean haveCompatibleTypes(ConfigValue reference, AbstractConfigValue value) {
   if (couldBeNull((AbstractConfigValue) reference) || couldBeNull(value)) {
     // we allow any setting to be null
     return true;
   } else if (reference instanceof AbstractConfigObject) {
     if (value instanceof AbstractConfigObject) {
       return true;
     } else {
       return false;
     }
   } else if (reference instanceof SimpleConfigList) {
     if (value instanceof SimpleConfigList) {
       return true;
     } else {
       return false;
     }
   } else if (reference instanceof ConfigString) {
     // assume a string could be gotten as any non-collection type;
     // allows things like getMilliseconds including domain-specific
     // interpretations of strings
     return true;
   } else if (value instanceof ConfigString) {
     // assume a string could be gotten as any non-collection type
     return true;
   } else {
     if (reference.valueType() == value.valueType()) {
       return true;
     } else {
       return false;
     }
   }
 }
Exemplo n.º 2
0
 @Override
 public List<Long> getNanosecondsList(String path) {
   List<Long> l = new ArrayList<Long>();
   List<? extends ConfigValue> list = getList(path);
   for (ConfigValue v : list) {
     if (v.valueType() == ConfigValueType.NUMBER) {
       l.add(TimeUnit.MILLISECONDS.toNanos(((Number) v.unwrapped()).longValue()));
     } else if (v.valueType() == ConfigValueType.STRING) {
       String s = (String) v.unwrapped();
       Long n = parseDuration(s, v.origin(), path);
       l.add(n);
     } else {
       throw new ConfigException.WrongType(
           v.origin(), path, "duration string or number of nanoseconds", v.valueType().name());
     }
   }
   return l;
 }
Exemplo n.º 3
0
 @Override
 public List<Long> getBytesList(String path) {
   List<Long> l = new ArrayList<Long>();
   List<? extends ConfigValue> list = getList(path);
   for (ConfigValue v : list) {
     if (v.valueType() == ConfigValueType.NUMBER) {
       l.add(((Number) v.unwrapped()).longValue());
     } else if (v.valueType() == ConfigValueType.STRING) {
       String s = (String) v.unwrapped();
       Long n = parseBytes(s, v.origin(), path);
       l.add(n);
     } else {
       throw new ConfigException.WrongType(
           v.origin(), path, "memory size string or number of bytes", v.valueType().name());
     }
   }
   return l;
 }
Exemplo n.º 4
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();
   }
 }
Exemplo n.º 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;
 }