Interface Strings.TextFlow

All Superinterfaces:
BiFunction<Strings.TextConsumer,Strings.TextConsumer,Strings.TextConsumer>, BinaryOperator<Strings.TextConsumer>
Enclosing class:
Strings
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public static interface Strings.TextFlow extends BinaryOperator<Strings.TextConsumer>
Functional interface for composable partial transformations of text.

Two text consumers are passed as arguments to the apply(eu.bandm.tools.util.java.Strings.TextConsumer, eu.bandm.tools.util.java.Strings.TextConsumer) method. The result should be a text consumer that forwards transformed/untransformed text to the first/second one, respectively.

  • Field Details

  • Method Details

    • apply

      Specified by:
      apply in interface BiFunction<Strings.TextConsumer,Strings.TextConsumer,Strings.TextConsumer>
    • applyAlways

      default Strings.TextConsumer applyAlways(Strings.TextConsumer downstream)
      Passes the same downstream consumer for transformed and untransformed text.

      This method is a convenient shorthand for apply(downstream, downstream).

      Parameters:
      downstream - the textconsumer to forward both transformed and untransformed text to
      Returns:
      a text consumer that forwards both transformed and untransformed text to downstream
      Throws:
      NullPointerException - if downstream is null
    • identity

      static Strings.TextFlow identity()
      Returns a text flow that forwards all text as if transformed.
      Returns:
      a text flow that forwards all text to downstream, without any transformation
    • empty

      static Strings.TextFlow empty()
      Returns a text flow that forwards all text untransformed.
      Returns:
      a text flow that forwards all text to alternative
    • map

      Returns a text flow that transforms each code point according to a given function.
      Parameters:
      op - the function to transform code points with
      Returns:
      a text flow that transforms each code point by applying op
      Throws:
      NullPointerException - if op is null
    • select

      static Strings.TextFlow select(IntPredicate which)
    • andAlways

      default Strings.TextFlow andAlways(Strings.TextFlow other)
      Returns a variant of this text flow that forwards both transformed and untransformed text to the given text flow.
      Parameters:
      other - the text flow to forward to
      Returns:
      a variant of this text flow that forwards both transformed and untransformed text to other
      Throws:
      NullPointerException - if other is null
    • andThen

      default Strings.TextFlow andThen(Strings.TextFlow other)
      Returns a text flow that forwards transformed text to the given text flow. Untransformed text bypasses the given text flow.
      Parameters:
      other - the text flow to forward transformed text to
      Returns:
      a variant of this text flow that forwards transformed text to other
      Throws:
      NullPointerException - if other is null
    • orElse

      default Strings.TextFlow orElse(Strings.TextFlow other)
      Returns a text flow that forwards untransformed text to the given text flow. Transformed text bypasses the given text flow.
      Parameters:
      other - the text flow to forward untransformed text to
      Returns:
      a variant of this text flow that forwards untransformed text to other
      Throws:
      NullPointerException - if other is null
    • drop

      static Strings.TextFlow drop()
      Returns a text flow that drops all text.

      This is useful in conjunction with andThen(eu.bandm.tools.util.java.Strings.TextFlow) and orElse. For example, a positive filter operation can be expressed as select(p).orElse(drop()), and a negative filter operation can be expressed as select(p).andThen(drop()).

      Returns:
      a text flow that drops all text
    • escapeNumeric

      static Strings.TextFlow escapeNumeric(String prefix, String suffix, int radix, int minWidth, int maxWidth)
      Returns a text flow that encodes code points numerically.

      The resulting consumer will throw IllegalArgumentException later, if a code point is encountered whose numerical escape sequence has more digits than specified by maxWidth. By contrast, if the sequence has fewer digits than specified by minWidth, leading zeroes are silently added.

      This transformation applies to all code points. Use select(java.util.function.IntPredicate) and andThen(eu.bandm.tools.util.java.Strings.TextFlow) or orElse(eu.bandm.tools.util.java.Strings.TextFlow) to restrict the transformation to a subset.

      Parameters:
      prefix - the common prefix of numerical escape sequences
      suffix - the common suffix of numerical escape sequences
      radix - the radix to use in numerical escape sequences
      minWidth - the minimum number of digits in numerical escape sequences
      maxWidth - the maximum number of digits in numerical escape sequences
      Returns:
      a text flow that encodes code points numerically
      Throws:
      NullPointerException - if any of prefix, suffix is null
      IllegalArgumentException - if radix is out of the meaningful bounds, or if minWidth is less than one or greater than maxWidth
      See Also:
    • geminate

      static Strings.TextFlow geminate()
    • escapeSymbolic

      static Strings.TextFlow escapeSymbolic(String prefix, String suffix, Map<Integer,String> which)
    • utf16

      static Strings.TextFlow utf16()