Class PathProviders

java.lang.Object
me.a8kj.config.file.PathProviders

public final class PathProviders extends Object
A utility class providing common factory methods for creating PathProvider instances. This class offers various strategies for determining the base directory where configurations should be stored.
Since:
0.1
Author:
a8kj7sea
  • Constructor Details

    • PathProviders

      public PathProviders()
  • Method Details

    • currentDir

      public static PathProvider currentDir()
      Creates a provider that uses the current working directory of the application.
      Returns:
      a PathProvider pointing to the current absolute path.
      Since:
      0.1
    • userDir

      public static PathProvider userDir()
      Creates a provider that points to the current user's home directory.
      Returns:
      a PathProvider pointing to the 'user.home' system property path.
      Since:
      0.1
    • jarDir

      public static PathProvider jarDir(Class<?> mainClass)
      Creates a provider that points to the directory where the JAR file of the specified class is located. If the location cannot be determined, it fallbacks to the current working directory.
      Parameters:
      mainClass - the class used to locate the JAR's source code source.
      Returns:
      a PathProvider pointing to the JAR's parent directory.
      Since:
      0.1
    • custom

      public static PathProvider custom(String path)
      Creates a provider that uses a custom string-based absolute path.
      Parameters:
      path - the string representing the custom directory path.
      Returns:
      a PathProvider pointing to the specified path.
      Since:
      0.1
    • tempDir

      public static PathProvider tempDir()
      Creates a provider that points to the system's default temporary directory.
      Returns:
      a PathProvider pointing to the 'java.io.tmpdir' path.
      Since:
      0.1
    • hybrid

      public static PathProvider hybrid(PathProvider primary, PathProvider secondary)
      Creates a hybrid provider that attempts to use a primary directory if it exists and is writable, otherwise falls back to a secondary directory.
      Parameters:
      primary - the first choice PathProvider.
      secondary - the fallback PathProvider.
      Returns:
      a PathProvider that evaluates the best available directory.
      Since:
      0.1
    • jarWithUserFallback

      public static PathProvider jarWithUserFallback(Class<?> mainClass)
      Creates a hybrid provider that prioritizes the JAR's directory and falls back to the user's home directory if the JAR directory is not accessible/writable.
      Parameters:
      mainClass - the class used to locate the JAR.
      Returns:
      a PathProvider with a jar-to-user fallback strategy.
      Since:
      0.1