Ejemplo n.º 1
0
  public Object get(String path, Object def) {

    if (path.length() == 0) {
      return this;
    }

    Configuration root = getRoot();
    if (root == null) {
      throw new IllegalStateException("Cannot access section without a root");
    }

    final char separator = root.options().pathSeparator();
    // i1 is the leading (higher) index
    // i2 is the trailing (lower) index
    int i1 = -1, i2;
    ConfigurationSection section = this;
    while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) {
      section = section.getConfigurationSection(path.substring(i2, i1));
      if (section == null) {
        return def;
      }
    }

    String key = path.substring(i2);
    if (section == this) {
      Object result = map.get(key);
      return (result == null) ? def : result;
    }
    return section.get(key, def);
  }
Ejemplo n.º 2
0
  public Object get(String path, Object def) {
    if (path == null) {
      throw new IllegalArgumentException("Path cannot be null");
    } else if (path.length() == 0) {
      return this;
    }

    Object result = null;
    String[] split =
        path.split(Pattern.quote(Character.toString(getRoot().options().pathSeparator())));
    ConfigurationSection section = this;

    for (int i = 0; i < split.length - 1; i++) {
      section = section.getConfigurationSection(split[i]);

      if (section == null) {
        return def;
      }
    }

    String key = split[split.length - 1];

    if (section == this) {
      result = map.get(key);
      return (result == null) ? def : result;
    }
    return section.get(key, def);
  }