Created
March 19, 2019 06:54
-
-
Save sahoosunilkumar/9784f4bea2284d31969640ca7428c135 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Party { | |
private final String place; | |
private final String name; | |
private final String starter; | |
private final String maincourse; | |
private final String desert; | |
private final String danceType; | |
private Party(PartyBuilder builder) { | |
this.place = builder.place; | |
this.name = builder.name; | |
this.maincourse = builder.maincourse; | |
this.starter = builder.starter; | |
this.danceType = builder.danceType; | |
this.desert = builder.desert; | |
} | |
public String getplace() { | |
return place; | |
} | |
public String getName() { | |
return name; | |
} | |
public String getstarter() { | |
return starter; | |
} | |
public String getmaincourse() { | |
return maincourse; | |
} | |
public String getdesert() { | |
return desert; | |
} | |
public String getdanceType() { | |
return danceType; | |
} | |
@Override | |
public String toString() { | |
StringBuilder sb = new StringBuilder(); | |
sb.append(" Party : ").append(name).append(" at ").append(place); | |
if (danceType != null) { | |
sb.append(" lets dance on " + danceType); | |
} | |
if (starter != null) { | |
sb.append(" start with " + starter); | |
} | |
if (maincourse != null) { | |
sb.append(" followed by ").append(maincourse); | |
} | |
if (desert != null) { | |
sb.append(" ends with ").append(desert); | |
} | |
return sb.toString(); | |
} | |
/** | |
* | |
* The builder class. | |
* | |
*/ | |
public static class PartyBuilder { | |
private final String place; | |
private final String name; | |
private String starter; | |
private String maincourse; | |
private String desert; | |
private String danceType; | |
/** | |
* Constructor | |
*/ | |
public PartyBuilder(String name, String place) { | |
if (place == null || name == null) { | |
throw new IllegalArgumentException( | |
"place and name can not be null"); | |
} | |
this.place = place; | |
this.name = name; | |
} | |
public PartyBuilder withstarter(String starter) { | |
this.starter = starter; | |
return this; | |
} | |
public PartyBuilder withmaincourse(String maincourse) { | |
this.maincourse = maincourse; | |
return this; | |
} | |
public PartyBuilder withdesert(String desert) { | |
this.desert = desert; | |
return this; | |
} | |
public PartyBuilder withdanceType(String danceType) { | |
this.danceType = danceType; | |
return this; | |
} | |
public Party build() { | |
return new Party(this); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment