Class Replacements

java.lang.Object
org.approvej.scrub.Replacements

@NullMarked public class Replacements extends Object
Collection of replacement functions (Functions that take an Integer and return an Object) for use with Scrubbers.
  • Method Details

    • numbered

      public static Replacement numbered(String label)
      Replaces with "[label #]" where label is the given label and '#' is the number of the distinct replacement.
      Parameters:
      label - a String used to identify the replacement
      Returns:
      a replacement function that replaces with "[label #]"
    • numbered

      public static Replacement numbered()
      Replaces each match with "[scrubbed #]" where '#' is the number of the distinct replacement.
      Returns:
      a replacement function that replaces with "[scrubbed #]"
    • string

      public static Replacement string(String replacement)
      Replaces each match with the given static replacement string.
      Parameters:
      replacement - the static replacement string
      Returns:
      a replacement function that always returns the same string
    • relativeDate

      public static Replacement relativeDate(DateTimeFormatter dateTimeFormatter)
      Replaces each match of the given dateTimePattern (as defined by DateTimeFormatter) with a relative description, like [today], [yesterday], [13 days from now].
      Parameters:
      dateTimeFormatter - the DateTimeFormatter to parse the date/time strings
      Returns:
      a replacement function that returns a relative description for dates of the given dateTimePattern
    • relativeDate

      public static Replacement relativeDate(String dateTimePattern)
      Replaces each match of the given dateTimePattern (as defined by DateTimeFormatter) with a relative description, like [today], [yesterday], [13 days from now].
      Parameters:
      dateTimePattern - a pattern as defined by DateTimeFormatter
      Returns:
      a replacement function that returns a relative description for dates of the given dateTimePattern
    • masking

      public static Replacement masking()
      Masks each letter or digit of the match with a generic one. E.g. all latin uppercase letters are replaced with A, hence the String "John Doe" is replaced with "Aaaa Aaa".

      This Replacement is generally useful for well-structured strings that do not vary in length or composition like order numbers, IDs, or strict date/time strings. It is not a good choice for names as they usually vary in length, or UUIDs as they are composed of random characters and digits (hexadecimal).

      Returns:
      a replacement function replaces each character with a generic one