Exemplo n.º 1
1
  /**
   * Creates a relative path to the given {@link ConfigurationSection} from the given relative
   * section.
   *
   * <p>You may use this method for any given {@link ConfigurationSection}, not only {@link
   * MemorySection}.
   *
   * @param section Section to create a path for.
   * @param key Name of the specified section.
   * @param relativeTo Section to create the path relative to.
   * @return Full path of the section from its root.
   */
  public static String createPath(
      ConfigurationSection section, String key, ConfigurationSection relativeTo) {
    StringBuilder builder = new StringBuilder();

    if (section != null) {
      for (ConfigurationSection parent = section;
          (parent != null) && (parent != relativeTo);
          parent = parent.getParent()) {
        if (builder.length() > 0) {
          builder.insert(0, section.getRoot().options().pathSeparator());
        }

        builder.insert(0, parent.getName());
      }
    }

    if ((key != null) && (key.length() > 0)) {
      if (builder.length() > 0) {
        builder.append(section.getRoot().options().pathSeparator());
      }

      builder.append(key);
    }

    return builder.toString();
  }
Exemplo n.º 2
0
  /**
   * Creates an empty MemorySection with the specified parent and path.
   *
   * @param parent Parent section that contains this own section.
   * @param path Path that you may access this section from via the root {@link Configuration}.
   * @throws IllegalArgumentException Thrown is parent or path is null, or if parent contains no
   *     root Configuration.
   */
  protected MemorySection(ConfigurationSection parent, String path) {
    if (parent == null) {
      throw new IllegalArgumentException("Parent cannot be null");
    }
    if (path == null) {
      throw new IllegalArgumentException("Path cannot be null");
    }

    this.path = path;
    this.parent = parent;
    this.root = parent.getRoot();

    if (root == null) {
      throw new IllegalArgumentException("Path cannot be orphaned");
    }

    this.fullPath = createPath(parent, path);
  }
Exemplo n.º 3
0
 /**
  * Creates a full path to the given {@link ConfigurationSection} from its root {@link
  * Configuration}.
  *
  * <p>You may use this method for any given {@link ConfigurationSection}, not only {@link
  * MemorySection}.
  *
  * @param section Section to create a path for.
  * @param key Name of the specified section.
  * @return Full path of the section from its root.
  */
 public static String createPath(ConfigurationSection section, String key) {
   return createPath(section, key, (section == null) ? null : section.getRoot());
 }