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.
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Strings.TextFlowA text flow that encodes text according to the rules of Java string literals.static final Strings.TextFlowA text flow that encodes text according to the rules of Pascal string literals.static final Strings.TextFlowA text flow that encodes text according to the rules of XML text. -
Method Summary
Modifier and TypeMethodDescriptiondefault Strings.TextFlowandAlways(Strings.TextFlow other) Returns a variant of this text flow that forwards both transformed and untransformed text to the given text flow.default Strings.TextFlowandThen(Strings.TextFlow other) Returns a text flow that forwards transformed text to the given text flow.apply(Strings.TextConsumer downstream, Strings.TextConsumer alternative) default Strings.TextConsumerapplyAlways(Strings.TextConsumer downstream) Passes the same downstream consumer for transformed and untransformed text.static Strings.TextFlowdrop()Returns a text flow that drops all text.static Strings.TextFlowempty()Returns a text flow that forwards all text untransformed.static Strings.TextFlowescapeNumeric(String prefix, String suffix, int radix, int minWidth, int maxWidth) Returns a text flow that encodes code points numerically.static Strings.TextFlowReturns a text flow that encodes code points symbolically.static Strings.TextFlowgeminate()Returns a text flow that encodes code points by doubling.static Strings.TextFlowidentity()Returns a text flow that forwards all text as if transformed.static Strings.TextFlowmap(IntUnaryOperator op) Returns a text flow that transforms each code point according to a given function.default Strings.TextFloworElse(Strings.TextFlow other) Returns a text flow that forwards untransformed text to the given text flow.static Strings.TextFlowselect(IntPredicate which) Returns a text flow that transforms selected code points to themselves.static Strings.TextFlowutf16()Returns a text flow that encodes code points in UTF-16.Methods inherited from interface java.util.function.BiFunction
andThen
-
Field Details
-
JAVA_STRING
A text flow that encodes text according to the rules of Java string literals. -
XML
A text flow that encodes text according to the rules of XML text. -
PASCAL_STRING
A text flow that encodes text according to the rules of Pascal string literals.
-
-
Method Details
-
apply
- Specified by:
applyin interfaceBiFunction<Strings.TextConsumer,Strings.TextConsumer, Strings.TextConsumer>
-
applyAlways
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- ifdownstreamis null
-
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
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- ifopis null
-
select
Returns a text flow that transforms selected code points to themselves.This flow does not perform any actual transformation, but demultiplexes code points to the transformed/untransformed channel, according to a given predicate. Thus is useful when followed by
andThento restrict a downstream flow to the selected code points, or followed byorElseto restrict an alternative flow to the unselected code points, respectively.- Parameters:
which- a predicate that selects code points- Returns:
- a text flow that forwards each code point as transformed if
whichreturnstrue, and as untransformed otherwise - Throws:
NullPointerException- ifwhichis null
-
andAlways
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- ifotheris null
-
andThen
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- ifotheris null
-
orElse
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- ifotheris null
-
drop
Returns a text flow that drops all text.This is useful in conjunction with
andThen(eu.bandm.tools.util.java.Strings.TextFlow)andorElse. For example, a positive filter operation can be expressed asselect(p).orElse(drop()), and a negative filter operation can be expressed asselect(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
IllegalArgumentExceptionlater, if a code point is encountered whose numerical escape sequence has more digits than specified bymaxWidth. By contrast, if the sequence has fewer digits than specified byminWidth, leading zeroes are silently added.This transformation applies to all code points. Use
select(java.util.function.IntPredicate)andandThen(eu.bandm.tools.util.java.Strings.TextFlow)ororElse(eu.bandm.tools.util.java.Strings.TextFlow)to restrict the transformation to a subset.- Parameters:
prefix- the common prefix of numerical escape sequencessuffix- the common suffix of numerical escape sequencesradix- the radix to use in numerical escape sequencesminWidth- the minimum number of digits in numerical escape sequencesmaxWidth- the maximum number of digits in numerical escape sequences- Returns:
- a text flow that encodes code points by a number in the format
specified by
radix,minWidthandmaxWidth, enclosed inprefixandsuffix - Throws:
NullPointerException- if any ofprefix,suffixis nullIllegalArgumentException- ifradixis out of the meaningful bounds, or ifminWidthis less than one or greater thanmaxWidth- See Also:
-
geminate
Returns a text flow that encodes code points by doubling.This transformation applies to all code points. Use
select(java.util.function.IntPredicate)andandThen(eu.bandm.tools.util.java.Strings.TextFlow)ororElse(eu.bandm.tools.util.java.Strings.TextFlow)to restrict the transformation to a subset.- Returns:
- a test flow that encodes each code point by forwarding it twice
-
escapeSymbolic
Returns a text flow that encodes code points symbolically.This transformation applies to the code points specified by the given map. All others are forwarded untransformed.
- Parameters:
prefix- the common prefix of symbolic escape sequencessuffix- the common suffix of symbolic escape sequenceswhich- a map of code points to their symbolic names- Returns:
- a text flow that encodes code points in the key set of
mapas the associated value, enclosed inprefixandsuffix; all other code points are forwarded untransformed. - Throws:
NullPointerException- ifprefix,suffixorwhichis null
-
utf16
Returns a text flow that encodes code points in UTF-16.Code points in the basic multilingual plane (BMP) are forwarded untransformed; all others are encoded as a surrogate pair.
- Returns:
- a text flow that encodes code points in UTF-16
-