public class RelativePathBase extends Object
getRelativePathFor(File)
method returns a path string relative to
the base directory passed to the constructor of this class.Modifier and Type | Class and Description |
---|---|
static interface |
RelativePathBase.Settings
Settings used to construct relative paths.
|
Modifier and Type | Field and Description |
---|---|
static RelativePathBase.Settings |
ALL_CHILDREN_WITH_DOT_PREFIX
Alternative settings to construct relative paths similar to
DEFAULT : "." represents the base directory, "./" is used as
prefix of child paths and "../" for elements up to the common ancestor. |
static RelativePathBase.Settings |
CHILDREN_WITHOUT_PREFIX
Alternative settings to construct relative paths without prefixes for
children: "." represents the base directory, no prefix for child paths
and "../" for elements up to the common ancestor.
|
static RelativePathBase.Settings |
DEFAULT
Default settings to construct relative paths: "." represents the base
directory, "./" is used as prefix of child paths (but "" for direct
children) and "../" for elements up to the common ancestor.
|
Constructor and Description |
---|
RelativePathBase(File base)
Constructor with base directory for relative paths using
DEFAULT
settings to construct relative paths. |
RelativePathBase(File base,
RelativePathBase.Settings settings)
Constructor with base directory for relative paths using the specified
settings to construct relative paths.
|
RelativePathBase(String base)
Constructor with base directory for relative paths using
DEFAULT
settings to construct relative paths. |
RelativePathBase(String base,
RelativePathBase.Settings settings)
Constructor with base directory for relative paths using the specified
settings to construct relative paths.
|
Modifier and Type | Method and Description |
---|---|
File |
getBase()
Returns the base directory for relative paths, the directory that was
passed to the constructor.
|
String |
getRelativePathFor(File file)
Returns the path of the given
file relative to the
base directory. |
String |
getRelativePathFor(String file)
Returns the path of the given
file relative to the
base directory. |
RelativePathBase.Settings |
getSettings()
Returns the settings used to construct relative paths.
|
public static final RelativePathBase.Settings DEFAULT
public static final RelativePathBase.Settings ALL_CHILDREN_WITH_DOT_PREFIX
DEFAULT
: "." represents the base directory, "./" is used as
prefix of child paths and "../" for elements up to the common ancestor.
As opposed to the DEFAULT settings, the "./" prefix is used for all child
paths including direct children.public static final RelativePathBase.Settings CHILDREN_WITHOUT_PREFIX
public RelativePathBase(String base)
DEFAULT
settings to construct relative paths.base
- the basis for relative paths returned by
getRelativePathFor(File)
public RelativePathBase(File base)
DEFAULT
settings to construct relative paths.base
- the basis for relative paths returned by
getRelativePathFor(File)
public RelativePathBase(String base, RelativePathBase.Settings settings)
base
- the basis for relative paths returned by
getRelativePathFor(File)
settings
- the settings used to construct relative pathspublic RelativePathBase(File base, RelativePathBase.Settings settings)
base
- the basis for relative paths returned by
getRelativePathFor(File)
settings
- the settings used to construct relative pathspublic File getBase()
public RelativePathBase.Settings getSettings()
DEFAULT
settings are used.public String getRelativePathFor(File file)
file
relative to the
base
directory.
The relative path is evaluated as follows:
base
is the same as file
, "." is returnedbase
is the direct parent directory of file
, the
simple file name is returnedbase
is a non-direct parent directory of file
, the
relative path from base
to file
is returnedbase
is not parent directory of file
, the relative
path is the path from base
to the common ancestor and then to
file
base
is not parent directory of file
and the only
common ancestor of the two is the base directory, the absolute path of
file
is returnedfile
- the target file whose relative path is returnedfile
relative to the base
directorypublic String getRelativePathFor(String file)
file
relative to the
base
directory.
The relative path is evaluated as follows:
base
is the same as file
, "." is returnedbase
is the direct parent directory of file
, the
simple file name is returnedbase
is a non-direct parent directory of file
, the
relative path from base
to file
is returnedbase
is not parent directory of file
, the relative
path is the path from base
to the common ancestor and then to
file
base
is not parent directory of file
and the only
common ancestor of the two is the base directory, the absolute path of
file
is returnedfile
- the target file whose relative path is returnedfile
relative to the base
directoryCopyright © 2024. All rights reserved.