Class PathPatternFinder

Object
com.owenfeehan.pathpatternfinder.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
Author:
Owen Feehan
  • Constructor Details

  • Method Details

    • findPatternPaths

      public static Pattern findPatternPaths​(List<Path> paths, IOCase ioCase)
      Finds the pattern in a list of paths, using rules outlined above.
      Parameters:
      paths - a list of paths to match against
      ioCase - how to treat the case in paths
      Returns:
      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).
      Parameters:
      strings - a list of strings to match against
      ioCase - how to treat the case in paths
      Returns:
      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
      Parameters:
      args - command-line arguments