1+ package com .baeldung .currying ;
2+
3+ import java .time .LocalDate ;
4+ import java .util .Objects ;
5+ import java .util .function .BiFunction ;
6+ import java .util .function .Function ;
7+
8+ public class Letter {
9+ private String returningAddress ;
10+ private String insideAddress ;
11+ private LocalDate dateOfLetter ;
12+ private String salutation ;
13+ private String body ;
14+ private String closing ;
15+
16+ Letter (String returningAddress , String insideAddress , LocalDate dateOfLetter , String salutation , String body , String closing ) {
17+ this .returningAddress = returningAddress ;
18+ this .insideAddress = insideAddress ;
19+ this .dateOfLetter = dateOfLetter ;
20+ this .salutation = salutation ;
21+ this .body = body ;
22+ this .closing = closing ;
23+ }
24+
25+ Letter (String salutation , String body ) {
26+ this (null , null , LocalDate .now (), salutation , body , null );
27+ }
28+
29+ @ Override
30+ public boolean equals (Object o ) {
31+ if (this == o ) {
32+ return true ;
33+ }
34+ if (o == null || getClass () != o .getClass ()) {
35+ return false ;
36+ }
37+ Letter letter = (Letter ) o ;
38+ return Objects .equals (returningAddress , letter .returningAddress ) &&
39+ Objects .equals (insideAddress , letter .insideAddress ) &&
40+ Objects .equals (dateOfLetter , letter .dateOfLetter ) &&
41+ Objects .equals (salutation , letter .salutation ) &&
42+ Objects .equals (body , letter .body ) &&
43+ Objects .equals (closing , letter .closing );
44+ }
45+
46+ @ Override
47+ public int hashCode () {
48+ return Objects .hash (returningAddress , insideAddress , dateOfLetter , salutation , body , closing );
49+ }
50+
51+ @ Override
52+ public String toString () {
53+ return "Letter{" + "returningAddress='" + returningAddress + '\'' + ", insideAddress='" + insideAddress + '\''
54+ + ", dateOfLetter=" + dateOfLetter + ", salutation='" + salutation + '\'' + ", body='" + body + '\''
55+ + ", closing='" + closing + '\'' + '}' ;
56+ }
57+
58+ static Letter createLetter (String salutation , String body ) {
59+ return new Letter (salutation , body );
60+ }
61+
62+ static BiFunction <String , String , Letter > SIMPLE_LETTER_CREATOR = //
63+ (salutation , body ) -> new Letter (salutation , body );
64+
65+ static Function <String , Function <String , Letter >> SIMPLE_CURRIED_LETTER_CREATOR = //
66+ saluation -> body -> new Letter (saluation , body );
67+
68+ static Function <String , Function <String , Function <LocalDate , Function <String , Function <String , Function <String , Letter >>>>>> LETTER_CREATOR = //
69+ returnAddress
70+ -> closing
71+ -> dateOfLetter
72+ -> insideAddress
73+ -> salutation
74+ -> body
75+ -> new Letter (returnAddress , insideAddress , dateOfLetter , salutation , body , closing );
76+
77+ static AddReturnAddress builder () {
78+ return returnAddress
79+ -> closing
80+ -> dateOfLetter
81+ -> insideAddress
82+ -> salutation
83+ -> body
84+ -> new Letter (returnAddress , insideAddress , dateOfLetter , salutation , body , closing );
85+ }
86+
87+ interface AddReturnAddress {
88+ Letter .AddClosing withReturnAddress (String returnAddress );
89+ }
90+
91+ interface AddClosing {
92+ Letter .AddDateOfLetter withClosing (String closing );
93+ }
94+
95+ interface AddDateOfLetter {
96+ Letter .AddInsideAddress withDateOfLetter (LocalDate dateOfLetter );
97+ }
98+
99+ interface AddInsideAddress {
100+ Letter .AddSalutation withInsideAddress (String insideAddress );
101+ }
102+
103+ interface AddSalutation {
104+ Letter .AddBody withSalutation (String salutation );
105+ }
106+
107+ interface AddBody {
108+ Letter withBody (String body );
109+ }
110+ }
0 commit comments