All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.shiruka.conf.Paths Maven / Gradle / Ivy

There is a newer version: 2.2.4
Show newest version
/*
 * MIT License
 *
 * Copyright (c) 2020 Shiru ka
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

package io.github.shiruka.conf;

import io.github.portlek.replaceable.rp.RpList;
import io.github.portlek.replaceable.rp.RpString;
import io.github.shiruka.conf.path.advanced.ApReplaceableList;
import io.github.shiruka.conf.path.advanced.ApReplaceableString;
import io.github.shiruka.conf.path.comment.CmBasic;
import io.github.shiruka.conf.path.simple.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * all {@link ConfigPath} list.
 */
public final class Paths {

  /**
   * ctor.
   */
  private Paths() {
  }

  /**
   * represents {@link CmBasic} instance.
   *
   * @param path the path to the value.
   * @param comments the comment to create.
   * @param  path's value type.
   *
   * @return the commentable path.
   */
  public static  CommentablePath commented(@NotNull final ConfigPath path, @NotNull final String... comments) {
    return new CmBasic<>(path, comments);
  }

  /**
   * represents {@link CpBoolean} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static CpBoolean booleanPath(@NotNull final String path, @Nullable final Boolean def) {
    return new CpBoolean(path, def);
  }

  /**
   * represents {@link CpDouble} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static CpDouble doublePath(@NotNull final String path, @Nullable final Double def) {
    return new CpDouble(path, def);
  }

  /**
   * represents {@link CpFloat} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static CpFloat floatPath(@NotNull final String path, @Nullable final Float def) {
    return new CpFloat(path, def);
  }

  /**
   * represents {@link CpInteger} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static CpInteger integerPath(@NotNull final String path, @Nullable final Integer def) {
    return new CpInteger(path, def);
  }

  /**
   * represents {@link CpLong} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static CpLong longPath(@NotNull final String path, @Nullable final Long def) {
    return new CpLong(path, def);
  }

  /**
   * represents {@link CpString} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static CpString stringPath(@NotNull final String path, @Nullable final StringBuilder def) {
    return Paths.stringPath(path, Optional.ofNullable(def)
      .map(StringBuilder::toString)
      .orElse(null));
  }

  /**
   * represents {@link CpString} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static CpString stringPath(@NotNull final String path, @Nullable final String def) {
    return new CpString(path, def);
  }

  /**
   * represents {@link ApReplaceableString} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static ApReplaceableString replaceableStringPath(final String path, final RpString def) {
    return new ApReplaceableString(path, def);
  }

  /**
   * represents {@link ApReplaceableList} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static ApReplaceableList replaceableListPath(final String path, final RpList def) {
    return new ApReplaceableList(path, def);
  }

  /**
   * represents {@link CpSimple} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static CpSimple> listStringPath(final String path, final String... def) {
    return Paths.simplePath(path, Optional.ofNullable(def)
      .map(Arrays::asList)
      .orElse(null));
  }

  /**
   * represents {@link CpSimple} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static CpSimple> listStringPath(final String path, final List def) {
    return Paths.simplePath(path, def);
  }

  /**
   * represents {@link CpSimple} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static CpSimple> mapPath(final String path, final Map def) {
    return Paths.simplePath(path, def);
  }

  /**
   * represents {@link CpSimple} instance.
   *
   * @param path the path.
   * @param def th default value.
   *
   * @return a config path instance.
   */
  @NotNull
  public static  CpSimple simplePath(final String path, final T def) {
    return new CpSimple<>(path, def);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy