Interface FileId
-
- All Superinterfaces:
Comparable<FileId>
public interface FileId extends Comparable<FileId>
An identifier for aTextFile
. This is not a path, but provides several methods to be rendered into path-like strings in different formats (for use mostly byRenderer
instances). File IDs are used to identify files e.g. inRuleViolation
,FileLocation
,TextFile
.Note that the addressed file may not be an actual file on a file system. For instance, you can create file ids from strings (
fromPathLikeString(String)
), or useSTDIN
to address standard input. The rendering methods of this interface (likegetAbsolutePath()
) do not have to return actual paths for those exotic files, and operate on a best-effort basis.- Author:
- Clément Fournier
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static FileId
asChildOf(FileId self, FileId parentFsPath)
Return a file ID whose methods behave the same as the first parameter, and whosegetParentFsPath()
returns the second parameter.default int
compareTo(FileId o)
boolean
equals(Object o)
Two file IDs are equal if they have the samegetUriString()
.static FileId
fromAbsolutePath(String absPath, @Nullable FileId outer)
Return a file ID which interprets the first parameter as an absolute path.static FileId
fromPath(Path path)
Return a file ID for the given path.static FileId
fromPath(Path path, @Nullable FileId fsPath)
Return a new path id for the given path.static FileId
fromPathLikeString(String str)
Return a path ID for the given string.static FileId
fromURI(String uriStr)
Return a file ID for a URI.String
getAbsolutePath()
Return an absolute path to this file in its containing file system.String
getFileName()
Return the simple file name, likePath.getFileName()
.String
getOriginalPath()
Return the path as it was input by the user.@Nullable FileId
getParentFsPath()
If this file is in a nested filesystem (eg a zip file), return the file ID of the container in the outer file system.String
getUriString()
Return a string that looks like a URI pointing to this file.String
toString()
This method is intentionally only meant for debugging, and its output is unspecified.
-
-
-
Method Detail
-
getFileName
String getFileName()
Return the simple file name, likePath.getFileName()
. This includes the extension.
-
getOriginalPath
String getOriginalPath()
Return the path as it was input by the user. This may be a relative or absolute path.
-
getAbsolutePath
String getAbsolutePath()
Return an absolute path to this file in its containing file system. If the file is in a zip file, then this returns a path from the zip root, and does not include the path of the zip itself.
-
getUriString
String getUriString()
Return a string that looks like a URI pointing to this file.
-
getParentFsPath
@Nullable FileId getParentFsPath()
If this file is in a nested filesystem (eg a zip file), return the file ID of the container in the outer file system. Return null if this is in the root file system.
-
equals
boolean equals(Object o)
Two file IDs are equal if they have the samegetUriString()
.
-
compareTo
default int compareTo(FileId o)
- Specified by:
compareTo
in interfaceComparable<FileId>
-
toString
String toString()
This method is intentionally only meant for debugging, and its output is unspecified. Code that needs a string representation should use one of the named string conversion methods.
-
fromPathLikeString
static FileId fromPathLikeString(String str)
Return a path ID for the given string. The string is interpreted as a file system path, so thatgetAbsolutePath()
andgetUriString()
may work.- Parameters:
str
- A string. Should be a valid file system path for the platform (seePaths.get(String, String...)
.- Returns:
- A new file id
-
fromPath
static FileId fromPath(Path path, @Nullable FileId fsPath)
Return a new path id for the given path.- Parameters:
path
- The pathfsPath
- The file id of the containing file system, if it is some Zip file.- Returns:
- A new file id.
-
fromPath
static FileId fromPath(Path path)
Return a file ID for the given path. This usesfromPath(Path, FileId)
and defaults the second parameter to null.
-
asChildOf
static FileId asChildOf(FileId self, FileId parentFsPath)
Return a file ID whose methods behave the same as the first parameter, and whosegetParentFsPath()
returns the second parameter.- Parameters:
self
- A file idparentFsPath
- Another file id for the parent.
-
fromAbsolutePath
static FileId fromAbsolutePath(String absPath, @Nullable FileId outer)
Return a file ID which interprets the first parameter as an absolute path. The path must be a valid path for this system (Paths.get(String, String...)
should not fail). The URI is rebuilt using the outer file ID if it is non-null.- Parameters:
absPath
- Absolute path for the fileouter
- File ID of the outer file system (Zip), if it exists- Returns:
- A new file id
-
fromURI
static FileId fromURI(String uriStr) throws IllegalArgumentException
Return a file ID for a URI. The URI must have schemefile
orjar
and be a valid URI (seeURI.create(String)
). If the scheme isjar
, then thegetParentFsPath()
is populated with the path of the jar.- Parameters:
uriStr
- A uri string- Returns:
- A new file id
- Throws:
IllegalArgumentException
-
-