Package lib.aide.paths
Record Class PathSuffixes
java.lang.Object
java.lang.Record
lib.aide.paths.PathSuffixes
- Record Components:
src
- the source string from which suffixes are to be extracteddelimiter
- the delimiter pattern used to separate suffixes in the source stringsuffixes
- a list of extracted suffixes in the order of significanceextendedSuffix
- the extended suffix string including the first delimiter occurrence to the end
public record PathSuffixes(String src, Pattern delimiter, List<String> suffixes, String extendedSuffix)
extends Record
The
PathSuffixes
class is designed to handle and process suffixes,
commonly known as file extensions, from a given file path or URL. The class
provides functionality to extract and manage these suffixes, which can be
used to determine the type of content based on its name and extension.
This class is particularly useful in scenarios where the identification and
manipulation of file extensions are required, such as:
- Determining the type of a file or URL based on its extension(s).
- Extracting multiple suffixes from complex file names, where multiple
extensions are used to denote special transformations of files (md -> html).
The class supports custom delimiters for suffix extraction, with a default
delimiter of "." (dot).
Example usage:
PathSuffixes suffixes = new PathSuffixes("my-file.special-type.md", PathSuffixes.DEFAULT_DELIMITER_PATTERN);
List<String> extractedSuffixes = suffixes.suffixes();
String extendedSuffix = suffixes.extendedSuffix();
In this example, the extractedSuffixes
list will contain ["md",
"special-type"], and the extendedSuffix
will be ".special-type.md".
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPathSuffixes
(String src, Pattern delimiter) Creates an instance of aPathSuffixes
record class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thedelimiter
record component.final boolean
Indicates whether some other object is "equal to" this one.Returns the value of theextendedSuffix
record component.static String
extendedSuffix
(String suffixesSrc, Pattern delim) Checks if the delim matches any part of the suffixesSrc and returns the substring from the first occurrence of the delimiter to the end of the string, including the delimiter; if no match is found, it returns the original input string.extractSuffixes
(String suffixesSrc, Pattern delim) This method processes the source string to extract suffixes separated by the provided delimiter.final int
hashCode()
Returns a hash code value for this object.src()
Returns the value of thesrc
record component.suffixes()
Returns the value of thesuffixes
record component.final String
toString()
Returns a string representation of this record class.
-
Field Details
-
DEFAULT_DELIMITER_PATTERN
-
-
Constructor Details
-
PathSuffixes
-
PathSuffixes
Creates an instance of aPathSuffixes
record class.- Parameters:
src
- the value for thesrc
record componentdelimiter
- the value for thedelimiter
record componentsuffixes
- the value for thesuffixes
record componentextendedSuffix
- the value for theextendedSuffix
record component
-
-
Method Details
-
extractSuffixes
This method processes the source string to extract suffixes separated by the provided delimiter. The suffixes are ordered such that the last suffix in the source string is considered the most significant and will appear first in the list. For example:- For the source string "my-file.md" with the default delimiter ".", the suffixes list will be ["md"].
- For the source string "my-file.special-type.md" with the default delimiter ".", the suffixes list will be ["md", "special-type"].
- Parameters:
suffixesSrc
- the string in which suffixes are founddelimiter
- optional delimiter to use, defaults to the pattern "\\."- Throws:
IllegalArgumentException
- if src is null or empty
-
extendedSuffix
Checks if the delim matches any part of the suffixesSrc and returns the substring from the first occurrence of the delimiter to the end of the string, including the delimiter; if no match is found, it returns the original input string. For the source string "my-file.special-type.md" with the default delimiter ".", the extendedSuffix will be `.special-type.md`.- Parameters:
suffixesSrc
-delim
-- Returns:
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
src
Returns the value of thesrc
record component.- Returns:
- the value of the
src
record component
-
delimiter
Returns the value of thedelimiter
record component.- Returns:
- the value of the
delimiter
record component
-
suffixes
Returns the value of thesuffixes
record component.- Returns:
- the value of the
suffixes
record component
-
extendedSuffix
Returns the value of theextendedSuffix
record component.- Returns:
- the value of the
extendedSuffix
record component
-