Class PathManagerUtils


  • public class PathManagerUtils
    extends java.lang.Object
    Utility class for converting relative map paths to absolute map paths and vice versa.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static @NotNull java.lang.String absoluteToRelative​(@NotNull java.lang.String reference, @NotNull java.lang.String absolute)
      Converts an absolute path to a relative path.
      static @NotNull java.lang.String getAbsolutePath​(@NotNull java.lang.CharSequence path)
      Returns the given path in absolute form.
      static @NotNull java.lang.String getMapPath​(@NotNull java.io.File file, @NotNull java.io.File baseDir)
      Returns a relative path path for a File.
      static boolean isAbsolute​(@NotNull java.lang.String path)
      Check whether a path is absolute.
      static boolean isRelative​(@NotNull java.lang.String path)
      Check whether a path is relative.
      static @NotNull java.lang.String path​(@NotNull java.lang.CharSequence str)
      Creates a reasonable path.
      static @NotNull java.lang.String relativeToAbsolute​(@NotNull java.lang.String reference, @NotNull java.lang.String relative)
      Converts a relative path to an absolute path.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getMapPath

        @NotNull
        public static @NotNull java.lang.String getMapPath​(@NotNull
                                                           @NotNull java.io.File file,
                                                           @NotNull
                                                           @NotNull java.io.File baseDir)
        Returns a relative path path for a File.
        Parameters:
        file - the file
        baseDir - the base directory to relativize against
        Returns:
        the relative path
      • isAbsolute

        public static boolean isAbsolute​(@NotNull
                                         @NotNull java.lang.String path)
        Check whether a path is absolute. Paths starting with "/" are absolute, paths starting with other characters are relative. Empty paths are relative.
        Parameters:
        path - the path to check
        Returns:
        true if path is absolute, false otherwise
        See Also:
        which nearly is the opposite of this method
      • isRelative

        public static boolean isRelative​(@NotNull
                                         @NotNull java.lang.String path)
        Check whether a path is relative. Paths not starting with "/" are relative, paths starting with are absolute. Empty paths are relative.
        Parameters:
        path - the path to check
        Returns:
        true if path is relative, false otherwise
        See Also:
        which nearly is the opposite of this method
      • relativeToAbsolute

        @NotNull
        public static @NotNull java.lang.String relativeToAbsolute​(@NotNull
                                                                   @NotNull java.lang.String reference,
                                                                   @NotNull
                                                                   @NotNull java.lang.String relative)
        Converts a relative path to an absolute path. If the path already is absolute, this method simply returns the path. If the reference ends on "/", it is treated as being a base directory, otherwise a file that's directory is taken as base.
        Parameters:
        reference - the reference file the relative path works on
        relative - destination file with relative path
        Returns:
        absolute path from the base directory
      • absoluteToRelative

        @NotNull
        public static @NotNull java.lang.String absoluteToRelative​(@NotNull
                                                                   @NotNull java.lang.String reference,
                                                                   @NotNull
                                                                   @NotNull java.lang.String absolute)
        Converts an absolute path to a relative path. If the path already is relative, this method simply returns the path. If the reference ends on "/", it is treated as being a base directory, otherwise a file that's directory is taken as base.
        Parameters:
        reference - the reference file the relative path works on
        absolute - destination file with relative path
        Returns:
        absolute path from the base directory
      • path

        @NotNull
        public static @NotNull java.lang.String path​(@NotNull
                                                     @NotNull java.lang.CharSequence str)
        Creates a reasonable path.
        Parameters:
        str - the string to create path from
        Returns:
        path
      • getAbsolutePath

        @NotNull
        public static @NotNull java.lang.String getAbsolutePath​(@NotNull
                                                                @NotNull java.lang.CharSequence path)
        Returns the given path in absolute form.
        Parameters:
        path - the path to convert
        Returns:
        the absolute path