Example #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();
  }
Example #2
0
  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();

    builder.append(getClass().getSimpleName());
    builder.append("[path='");
    builder.append(getCurrentPath());
    builder.append("', root='");
    builder.append(root.getClass().getSimpleName());
    builder.append("']");

    return builder.toString();
  }