Class PathPatternFinder


public class PathPatternFinder
extends Object
Finds a pattern in a list of paths via a set of rules.

The rules are (in order):

  1. finds any common file-path roots
  2. then treats the remaining file-paths as a list of strings with / or \ as directory seperators (OS dependent)
  3. repeat until no more operations possible
    1. from the left:
      1. looks for maximum-constant strings
      2. looks for maximally-sized integer patterns
      3. looks for any variable strings, which are ended by constant character always at the same index
    2. do the same from the right
  4. if there is a remaining "unmatched" strings, consider splitting by special characters _ or - or ( or ) into tokens
  5. apply step 3 to each of the split tokens
Owen Feehan
  • Constructor Details

  • Method Details

    • findPatternPaths

      public static Pattern findPatternPaths​(List<Path> paths, IOCase ioCase, boolean avoidExtensionSplit)
      Finds the pattern in a list of paths, using rules outlined above.
      paths - a list of paths to match against
      ioCase - how to treat the case in paths
      avoidExtensionSplit - if true, splits will be avoided in file extensions in the paths (defined as anything after the right-most period)
      the pattern-found
    • findPatternStrings

      public static Pattern findPatternStrings​(List<String> strings, IOCase ioCase)
      Finds the pattern in a list of strings, using rules outlined above (from Step 3 onwards).
      strings - a list of strings to match against
      ioCase - how to treat the case in paths
      the pattern-found
    • main

      public static void main​(String[] args)
      Derives a pattern from the paths passed as command-line arguments.
      1. Accepts a globs or file/directory paths as command-line arguments
      2. Derives a list of paths from these parameters
      3. Derives a pattern from the list of paths
      args - command-line arguments