Class DirectoryWithPrefix
Object
org.anchoranalysis.io.output.path.prefixer.DirectoryWithPrefix
- All Implemented Interfaces:
PathCreator
public class DirectoryWithPrefix extends Object implements PathCreator
A directory into which files can be written, and a prefix for the name of each written file.
A delimeter may additionally be specified that is inserted between the prefix and a filename when a filename is specified (which may not always be the case).
- Author:
- Owen Feehan
-
Constructor Summary
Constructors Constructor Description DirectoryWithPrefix(Path directory)Creates for a directory, with no prefix.DirectoryWithPrefix(Path directory, String prefix, String delimiter) -
Method Summary
Modifier and Type Method Description PathasPath(boolean includeDelimeter)A path that combines thedirectoryandfileNamePrefixanddelimiter.PathgetDirectory()The directory in which files can be written to.PathmakePathAbsolute(Optional<String> suffix, Optional<String> extension, String fallbackSuffix)Generates a full path, given the final part (suffix) of a path.PathmakePathRelative(Path fullPath)Extracts a relative-file path, given the final part (suffix) of a path.StringprefixWithDelimeter()The prefix concatenated with the delimeter.voidsetDelimiter(String delimiter)Added betweenprefixand the filename, if the filename is defined.voidsetDirectory(Path directory)Assigns a new directory, replacing the existing directory.voidsetPrefix(String prefix)Always prepended to outputted filenames.
-
Constructor Details
-
DirectoryWithPrefix
Creates for a directory, with no prefix.- Parameters:
directory- the directory.
-
DirectoryWithPrefix
-
-
Method Details
-
setDirectory
Assigns a new directory, replacing the existing directory.- Parameters:
directory- the directory.
-
asPath
A path that combines thedirectoryandfileNamePrefixanddelimiter.- Parameters:
includeDelimeter- if true, the delimeter is included in the combined prefix.- Returns:
- the combined path
-
prefixWithDelimeter
The prefix concatenated with the delimeter.- Returns:
- the result of the concatenation above.
-
makePathAbsolute
public Path makePathAbsolute(Optional<String> suffix, Optional<String> extension, String fallbackSuffix)Description copied from interface:PathCreatorGenerates a full path, given the final part (suffix) of a path.All sub-directories are created if needed to ensure it's possible to write to the fullPath.
- Specified by:
makePathAbsolutein interfacePathCreator- Parameters:
suffix- the final part of the path, to be added to the prefixextension- a file extension (without a leading period).fallbackSuffix- if neither aprefixis defined nor asuffix, then this provides a suffix to use so a file isn't only an extension.- Returns:
- a complete absolute path with all components (prefix, suffix) etc., including the leading directory.
-
makePathRelative
Description copied from interface:PathCreatorExtracts a relative-file path, given the final part (suffix) of a path.The path will be relative to the underlying root
directory.This relative-path includes any filename-prefix added by the
DirectoryWithPrefix.- Specified by:
makePathRelativein interfacePathCreator- Parameters:
fullPath- the final part of the path, to be added to the prefix- Returns:
- a complete relative path with all components (prefix, suffix) etc., but no leading directory.
-
getDirectory
The directory in which files can be written to. -
setPrefix
Always prepended to outputted filenames. -
setDelimiter
Added betweenprefixand the filename, if the filename is defined.
-