コード例 #1
0
ファイル: MemorySection.java プロジェクト: Worzaii/Bukkit
  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);
  }
コード例 #2
0
ファイル: MemorySection.java プロジェクト: Worzaii/Bukkit
  public ConfigurationSection createSection(String path) {
    if (path == null) {
      throw new IllegalArgumentException("Path cannot be null");
    } else if (path.length() == 0) {
      throw new IllegalArgumentException("Cannot create section at empty path");
    }

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

    for (int i = 0; i < split.length - 1; i++) {
      ConfigurationSection last = section;

      section = last.getConfigurationSection(split[i]);

      if (section == null) {
        section = last.createSection(split[i]);
      }
    }

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

    if (section == this) {
      ConfigurationSection result = new MemorySection(this, key);
      map.put(key, result);
      return result;
    } else {
      return section.createSection(key);
    }
  }
コード例 #3
0
ファイル: MemorySection.java プロジェクト: Worzaii/Bukkit
  public void set(String path, Object value) {
    String[] split =
        path.split(Pattern.quote(Character.toString(getRoot().options().pathSeparator())));
    ConfigurationSection section = this;

    if (path.length() == 0) {
      throw new IllegalArgumentException("Cannot set to an empty path");
    }

    for (int i = 0; i < split.length - 1; i++) {
      ConfigurationSection last = section;

      section = last.getConfigurationSection(split[i]);

      if (section == null) {
        section = last.createSection(split[i]);
      }
    }

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

    if (section == this) {
      if (value == null) {
        map.remove(key);
      } else {
        map.put(key, value);
      }
    } else {
      section.set(key, value);
    }
  }