forked from mtumilowicz/java11-lambda-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMailer.java
More file actions
37 lines (29 loc) · 804 Bytes
/
Mailer.java
File metadata and controls
37 lines (29 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package dsl;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import org.apache.commons.lang3.StringUtils;
import java.util.function.UnaryOperator;
/**
* Created by mtumilowicz on 2018-11-30.
*/
@Value
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class Mailer {
private static final Mailer EMPTY = new Mailer();
String from;
String to;
private Mailer() {
this.from = "";
this.to = "";
}
Mailer from(String from) {
return new Mailer(StringUtils.defaultIfEmpty(from, ""), to);
}
Mailer to(String to) {
return new Mailer(from, StringUtils.defaultIfEmpty(to, ""));
}
static void send(UnaryOperator<Mailer> block) {
System.out.println(block.apply(EMPTY));
}
}