Class SimpleFilePattern

java.lang.Object
eu.bandm.tools.util.SimpleFilePattern

public class SimpleFilePattern extends Object
Maps an input file name to an output file name according to a very simple pattern rule inspired by "patsubst" from "make". A SimpleFilePattern is constructed giving two(2) Strings which contain exactly one(1) place holder character. Then it is applied to some input String, yielding the output String.
  patterns   =    inpre%inpost 
                  outpre%outpost
  inputname  =   XXXXinpreYYYYinpost
       (with inpre  = latest occurrence in inpattern before inpost)
  outputname =   XXXXoutpreYYYYoutpost
  stem       =             YYYY
  
All four components (inpre,inpost,outpre,outpost) may be empty.
As a variant, there is the case "multiple=false", in which neither of the Strings contains a place holder character. In this case the input must be identical with the first string to yield the second.
  • Field Details

    • defaultPlaceholder

      public static final String defaultPlaceholder
      Evident
      See Also:
    • placeholder

      public final String placeholder
      The place holder character as set by the constructor.
    • multiple

      public final boolean multiple
      Whether in and out pattern contain a place holder character.
    • inPre

      @Opt final @Opt String inPre
      The part of the input pattern before the placeholder-
    • inPost

      @Opt final @Opt String inPost
      The part of the input pattern after the placeholder-
    • outPre

      @Opt final @Opt String outPre
      The part of the output pattern before the placeholder-
    • outPost

      @Opt final @Opt String outPost
      The part of the output pattern after the placeholder-
    • inPreLength

      final int inPreLength
      Length of the part of the input pattern before the placeholder-
    • inPostLength

      final int inPostLength
      Length of the part of the input pattern after the placeholder-
    • inText

      final String inText
      The complete input pattern, as given to the constructor call. (Needs not contain a placeholder character.)
    • outText

      final String outText
      The complete output pattern, as given to the constructor call. (Needs not contain a placeholder character.)
    • stem

      @Opt protected @Opt String stem
      The string matching the placeholder from the last executed call to match(String). Is != null in multiple mode.
  • Constructor Details

    • SimpleFilePattern

      public SimpleFilePattern(String in, String out)
      Construct a transformation with the given input and output pattern and the defaultPlaceholder.
    • SimpleFilePattern

      public SimpleFilePattern(String in, String out, String placeholder)
      Construct a transformation with the given input and output pattern and the given place holder. Input and output pattern must both contain exactly one placeholder character, or both none.
      Parameters:
      placeholder - must be a string of length==1.
  • Method Details

    • validMultiple

      public static boolean validMultiple(String in)
      Whether the string is a valid multiple input or output pattern with the defaultPlaceholder.
    • validMultiple

      public static boolean validMultiple(String in, String placeholder)
      Whether the string is a valid multiple input or output pattern with the given placeholder.
    • match

      @Opt public @Opt String match(String in)
      Matches the input pattern and returns the derived output string.

      Case not-multiple: The input string must be identical with the input pattern, and the output pattern is returned (no pattern contains a placeholder character)

      Case multiple: The output is calculated as follows (blanks to be ignored):

                                       
           inpattern           jjjj %   lll
                                    stemstart
                               p2   |   p3
                               v    v   v
           in             iiijjjjjj kkk lll
           outpattern           ooo %   ppp
           returned       iiijj ooo kkk ppp
           stem                     kkk
        
    • getStem

      public String getStem()
      Return the stem which has been recognized by the most recent call to match(java.lang.String). Must be called only if this call was in multiple mode.