Package org.apache.rat.document
Class DocumentName
java.lang.Object
org.apache.rat.document.DocumentName
- All Implemented Interfaces:
Comparable<DocumentName>
- Direct Known Subclasses:
ArchiveEntryName
The name for a document. The
DocumentName
is an immutable structure that handles all the intricacies of file
naming on various operating systems. DocumentNames have several components:
root
- where in the file system the name starts (e.g C: on windows). May be empty but not null.dirSeparator
- the separator between name segments (e.g. "\\" on windows, "/" on linux). May not be empty or null.name
- the name of the file relative to theroot
. May not be null. Does NOT begin with adirSeparator
baseName
- the name of a directory or file from which this file is reported. A DocumentName with aname
of "foo/bar/baz.txt" and abaseName
of "foo" will be reported as "bar/baz.txt". May not be null.isCaseSensitive
- identifies if the underlying file system is case-sensitive.
DocumentName
s are generally used to represent files on the files system. However, they are also used to represent files
within an archive. When representing a file in an archive the baseName is the name of the enclosing archive document.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
The Builder for a DocumentName.static class
The file system information needed to process document names. -
Method Summary
Modifier and TypeMethodDescriptionasFile()
Creates a file from the document name.asPath()
Creates a path from the document name.static DocumentName.Builder
builder()
Creates a Builder with the default file system info.static DocumentName.Builder
Creates a builder from a File.static DocumentName.Builder
builder
(FileSystem fileSystem) Creates a builder for the specified file system.static DocumentName.Builder
builder
(DocumentName documentName) Creates a builder from a document name.static DocumentName.Builder
builder
(DocumentName.FSInfo fsInfo) Creates a builder with the specified FSInfo instance.int
compareTo
(DocumentName other) boolean
Gets the DocumentName for the basename of this DocumentName.Gets the fully qualified basename of the document.Returns the directory separator.getName()
Gets the fully qualified name of the document.getRoot()
Gets the root for this document.Gets the last segment of the name.int
hashCode()
boolean
Gets the case sensitivity flag.Gets the portion of the name that is not part of the base name.Gets the portion of the name that is not part of the base name.Creates a new DocumentName by adding the child to the current name.toString()
Returns the localized file name.
-
Method Details
-
builder
Creates a Builder with the default file system info.- Returns:
- the builder.
- See Also:
-
builder
Creates a builder with the specified FSInfo instance.- Parameters:
fsInfo
- the FSInfo to use for the builder.- Returns:
- a new builder.
-
builder
Creates a builder for the specified file system.- Parameters:
fileSystem
- the file system to create the builder on.- Returns:
- a new builder.
-
builder
Creates a builder from a File. ThebaseName
is set to the file name if it is a directory otherwise it is set to the directory containing the file.- Parameters:
file
- The file to set defaults from.- Returns:
- the builder.
-
builder
Creates a builder from a document name. The builder will be configured to create a clone of the DocumentName.- Parameters:
documentName
- the document name to set the defaults from.- Returns:
- the builder.
-
asFile
Creates a file from the document name.- Returns:
- a new File object.
-
asPath
Creates a path from the document name.- Returns:
- a new Path object.
-
resolve
Creates a new DocumentName by adding the child to the current name. Resulting documentName will have the same base name.- Parameters:
child
- the child to add (must use directory separator from this document name).- Returns:
- the new document name with the same
baseName
, directory sensitivity and case sensitivity as this one.
-
getName
Gets the fully qualified name of the document.- Returns:
- the fully qualified name of the document.
-
getBaseName
Gets the fully qualified basename of the document.- Returns:
- the fully qualified basename of the document.
-
getRoot
Gets the root for this document.- Returns:
- the root for this document.
-
getBaseDocumentName
Gets the DocumentName for the basename of this DocumentName.- Returns:
- the DocumentName for the basename of this document name.
-
getDirectorySeparator
Returns the directory separator.- Returns:
- the directory separator.
-
localized
Gets the portion of the name that is not part of the base name. The resulting name will always start with the directory separator.- Returns:
- the portion of the name that is not part of the base name.
-
localized
Gets the portion of the name that is not part of the base name. The resulting name will always start with the directory separator.- Parameters:
dirSeparator
- The character(s) to use to separate directories in the result.- Returns:
- the portion of the name that is not part of the base name.
-
getShortName
Gets the last segment of the name. This is the part after the last directory separator.- Returns:
- the last segment of the name.
-
isCaseSensitive
public boolean isCaseSensitive()Gets the case sensitivity flag.- Returns:
true
if the name is case-sensitive.
-
toString
Returns the localized file name. -
compareTo
- Specified by:
compareTo
in interfaceComparable<DocumentName>
-
equals
-
hashCode
public int hashCode()
-