Interface SplitUtil.Strategy

Enclosing class:

public static interface SplitUtil.Strategy
Function which applies a programmable strategy used to determine a splitting point.
See Also:
  • Field Details


      static final SplitUtil.Strategy ANYWHERE
      Strategy which splits at any character to satisfy the limit.
      This is the default strategy if none is provided, and should ideally only be the final one in your list.

      static final SplitUtil.Strategy NEWLINE
      Splits on newline characters. Specifically on '\n'.

      static final SplitUtil.Strategy WHITESPACE
      Splits on every character which is considered whitespace.
  • Method Details

    • apply

      int apply(@Nonnull String string, int offset, int limit)
      Implements a splitting strategy.

      The goal of a strategy is to implement a greedy algorithm to find the optimal point to split the string. Ideally, this should be close to the limit.

      This should not return an offset larger than limit. Any offset lower than the input offset, is interpreted as unsuccessful.

      string - The input string
      offset - The current offset where to start your substring
      limit - The maximum length your substring should be
      The exclusive end index of your chunk, negative to indicate failure. (should be in range of offset < x <= limit).
    • onChar

      @Nonnull static SplitUtil.Strategy onChar(char c)
      Strategy to split on the provided character.

      An example use-case would be to define places via '\0' and then splitting exactly on those.

      c - The splitting character
      The strategy to split on that character
    • onChar

      Strategy to split on the provided character tests.
      predicate - The splitting character test
      The strategy to split on characters that pass the test
      IllegalArgumentException - If the predicate is null