Skip to content

Commit 48c9fb7

Browse files
authored
Customize TextProcessor (#42)
1 parent ea5b8a7 commit 48c9fb7

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

DesignPatterns/src/main/java/pl/mperor/lab/java/design/pattern/structural/decorator/lambda/expression/TextProcessor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package pl.mperor.lab.java.design.pattern.structural.decorator.lambda.expression;
22

33
import java.util.Arrays;
4-
import java.util.function.UnaryOperator;
54

65
@FunctionalInterface
7-
public interface TextProcessor extends UnaryOperator<String> {
6+
public interface TextProcessor {
7+
8+
String process(String text);
89

910
default TextProcessor chain(TextProcessor after) {
10-
return input -> after.apply(this.apply(input));
11+
return input -> after.process(this.process(input));
1112
}
1213

1314
static TextProcessor identity() {
14-
return s -> s;
15+
return text -> text;
1516
}
1617

1718
static TextProcessor of(TextProcessor processor) {

DesignPatterns/src/test/java/pl/mperor/lab/java/design/pattern/structural/decorator/lambda/expression/TextProcessorAndValidatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ public void shouldAllowToCreateTextProcessorAsChainOfFunctions() {
1111
TextProcessor.of(String::strip)
1212
.chain(s -> "prefix" + s)
1313
.chain(s -> s + "suffix")
14-
.apply(" @Hello World@")
14+
.process(" @Hello World@")
1515
);
1616

1717
Assertions.assertEquals("HEX",
1818
TextProcessor.of(
1919
String::toUpperCase,
2020
s -> s.replace("L", "X"),
2121
s -> s.substring(0, 3)
22-
).apply("Hello World")
22+
).process("Hello World")
2323
);
2424
}
2525

0 commit comments

Comments
 (0)