Gridarta Editor
net.sf.gridarta.utils.PathManagerUtils Class Reference
+ Collaboration diagram for net.sf.gridarta.utils.PathManagerUtils:

Static Public Member Functions

static String absoluteToRelative (@NotNull final String reference, @NotNull final String absolute)
 
static String getAbsolutePath (@NotNull final CharSequence path)
 
static String getMapPath (@NotNull final File file, @NotNull final File baseDir)
 
static boolean isAbsolute (@NotNull final String path)
 
static boolean isRelative (@NotNull final String path)
 
static String path (@NotNull final CharSequence str)
 
static String relativeToAbsolute (@NotNull final String reference, @NotNull final String relative)
 

Private Member Functions

 PathManagerUtils ()
 

Static Private Member Functions

static int findDifference (@NotNull final CharSequence s1, @NotNull final CharSequence s2)
 
static int findOccurrences (@NotNull final CharSequence s, final char c)
 

Static Private Attributes

static final Pattern PATTERN_REDUNDANT = Pattern.compile("[^/]+/\\.\\./")
 
static final Pattern PATTERN_SLASHES = Pattern.compile("//*")
 

Detailed Description

Utility class for converting relative map paths to absolute map paths and vice versa.

Definition at line 31 of file PathManagerUtils.java.

Constructor & Destructor Documentation

◆ PathManagerUtils()

net.sf.gridarta.utils.PathManagerUtils.PathManagerUtils ( )
private

Private constructor to prevent instantiation.

Definition at line 48 of file PathManagerUtils.java.

Member Function Documentation

◆ absoluteToRelative()

static String net.sf.gridarta.utils.PathManagerUtils.absoluteToRelative ( @NotNull final String  reference,
@NotNull final String  absolute 
)
static

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
referencethe reference file the relative path works on
absolutedestination file with relative path
Returns
absolute path from the base directory

Definition at line 137 of file PathManagerUtils.java.

References net.sf.gridarta.utils.PathManagerUtils.findDifference(), net.sf.gridarta.utils.PathManagerUtils.findOccurrences(), and net.sf.gridarta.utils.PathManagerUtils.isRelative().

Referenced by net.sf.gridarta.gui.map.maptilepane.TilePanel.RASwitch.actionPerformed(), and net.sf.gridarta.utils.PathManagerUtilsTest.testAbsoluteToRelative().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findDifference()

static int net.sf.gridarta.utils.PathManagerUtils.findDifference ( @NotNull final CharSequence  s1,
@NotNull final CharSequence  s2 
)
staticprivate

Helper method that returns the first string index at which two strings denoting paths aren't identical. That is, the index always points at the beginning or a '/'-character. The return value of this method is in every case good for a String.substring() invocation start index.

Parameters
s1first string to compare
s2second string to compare
Returns
index of first / after which s1 and s2 aren't identical or 0 if they differ from start

Definition at line 165 of file PathManagerUtils.java.

Referenced by net.sf.gridarta.utils.PathManagerUtils.absoluteToRelative().

+ Here is the caller graph for this function:

◆ findOccurrences()

static int net.sf.gridarta.utils.PathManagerUtils.findOccurrences ( @NotNull final CharSequence  s,
final char  c 
)
staticprivate

Counts the occurrences of a character within a string.

Parameters
sthe string to count in
ccharacter to count
Returns
number of occurrences of
c
in
s

Definition at line 189 of file PathManagerUtils.java.

Referenced by net.sf.gridarta.utils.PathManagerUtils.absoluteToRelative().

+ Here is the caller graph for this function:

◆ getAbsolutePath()

static String net.sf.gridarta.utils.PathManagerUtils.getAbsolutePath ( @NotNull final CharSequence  path)
static

Returns the given path in absolute form.

Parameters
paththe path to convert
Returns
the absolute path

Definition at line 219 of file PathManagerUtils.java.

References net.sf.gridarta.utils.PathManagerUtils.path(), and net.sf.gridarta.utils.PathManagerUtils.relativeToAbsolute().

Referenced by net.sf.gridarta.utils.PathManagerUtils.getMapPath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMapPath()

static String net.sf.gridarta.utils.PathManagerUtils.getMapPath ( @NotNull final File  file,
@NotNull final File  baseDir 
)
static

Returns a relative path path for a File.

Parameters
filethe file
baseDirthe base directory to relativize against
Returns
the relative path

Definition at line 58 of file PathManagerUtils.java.

References net.sf.gridarta.utils.PathManagerUtils.getAbsolutePath().

Referenced by net.sf.gridarta.model.io.PathManager.getMapPath(), net.sf.gridarta.gui.utils.JFileField.getRelativeFile(), and net.sf.gridarta.plugin.parameter.AbstractPathParameter< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.setFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAbsolute()

static boolean net.sf.gridarta.utils.PathManagerUtils.isAbsolute ( @NotNull final String  path)
static

Check whether a path is absolute. Paths starting with "/" are absolute, paths starting with other characters are relative. Empty paths are relative.

Parameters
paththe path to check
Returns
true
if is absolute,
false
otherwise
See also
#isRelative(String) which nearly is the opposite of this method

Definition at line 86 of file PathManagerUtils.java.

References net.sf.gridarta.utils.PathManagerUtils.path().

Referenced by net.sf.gridarta.utils.PathManagerUtils.relativeToAbsolute(), and net.sf.gridarta.utils.PathManagerUtilsTest.testIsAbsolute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRelative()

static boolean net.sf.gridarta.utils.PathManagerUtils.isRelative ( @NotNull final String  path)
static

Check whether a path is relative. Paths not starting with "/" are relative, paths starting with are absolute. Empty paths are relative.

Parameters
paththe path to check
Returns
true
if is relative,
false
otherwise
See also
#isAbsolute(String) which nearly is the opposite of this method

Definition at line 97 of file PathManagerUtils.java.

References net.sf.gridarta.utils.PathManagerUtils.path().

Referenced by net.sf.gridarta.utils.PathManagerUtils.absoluteToRelative(), net.sf.gridarta.utils.PathManagerUtilsTest.testIsRelative(), and net.sf.gridarta.gui.map.maptilepane.TilePanel.RASwitch.updateRAState().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ path()

◆ relativeToAbsolute()

static String net.sf.gridarta.utils.PathManagerUtils.relativeToAbsolute ( @NotNull final String  reference,
@NotNull final String  relative 
)
static

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
referencethe reference file the relative path works on
relativedestination file with relative path
Returns
absolute path from the base directory

Definition at line 111 of file PathManagerUtils.java.

References net.sf.gridarta.utils.PathManagerUtils.isAbsolute(), and net.sf.gridarta.utils.PathManagerUtils.PATTERN_REDUNDANT.

Referenced by net.sf.gridarta.gui.map.maptilepane.TilePanel.RASwitch.actionPerformed(), net.sf.gridarta.utils.PathManagerUtils.getAbsolutePath(), and net.sf.gridarta.utils.PathManagerUtilsTest.testRelativeToAbsolute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ PATTERN_REDUNDANT

final Pattern net.sf.gridarta.utils.PathManagerUtils.PATTERN_REDUNDANT = Pattern.compile("[^/]+/\\.\\./")
staticprivate

A Pattern that matches redundant directory parts like "dir/../".

Definition at line 37 of file PathManagerUtils.java.

Referenced by net.sf.gridarta.utils.PathManagerUtils.relativeToAbsolute().

◆ PATTERN_SLASHES

final Pattern net.sf.gridarta.utils.PathManagerUtils.PATTERN_SLASHES = Pattern.compile("//*")
staticprivate

A Pattern that matches redundant directory separators.

Definition at line 43 of file PathManagerUtils.java.

Referenced by net.sf.gridarta.utils.PathManagerUtils.path().


The documentation for this class was generated from the following file:
net.sf.gridarta.utils.PathManagerUtils.path
static String path(@NotNull final CharSequence str)
Definition: PathManagerUtils.java:205