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 extracted
delimiter - the delimiter pattern used to separate suffixes in the source string
suffixes - a list of extracted suffixes in the order of significance
extendedSuffix - 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 Details

    • DEFAULT_DELIMITER_PATTERN

      public static final Pattern DEFAULT_DELIMITER_PATTERN
  • Constructor Details

    • PathSuffixes

      public PathSuffixes(String src, Pattern delimiter)
    • PathSuffixes

      public PathSuffixes(String src, Pattern delimiter, List<String> suffixes, String extendedSuffix)
      Creates an instance of a PathSuffixes record class.
      Parameters:
      src - the value for the src record component
      delimiter - the value for the delimiter record component
      suffixes - the value for the suffixes record component
      extendedSuffix - the value for the extendedSuffix record component
  • Method Details

    • extractSuffixes

      public static List<String> extractSuffixes(String suffixesSrc, Pattern delim)
      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 found
      delimiter - optional delimiter to use, defaults to the pattern "\\."
      Throws:
      IllegalArgumentException - if src is null or empty
    • extendedSuffix

      public 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. 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

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • src

      public String src()
      Returns the value of the src record component.
      Returns:
      the value of the src record component
    • delimiter

      public Pattern delimiter()
      Returns the value of the delimiter record component.
      Returns:
      the value of the delimiter record component
    • suffixes

      public List<String> suffixes()
      Returns the value of the suffixes record component.
      Returns:
      the value of the suffixes record component
    • extendedSuffix

      public String extendedSuffix()
      Returns the value of the extendedSuffix record component.
      Returns:
      the value of the extendedSuffix record component