diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2017-05-08 21:28:02 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2017-05-29 21:02:54 +0200 |
commit | 8b7a7cbc813653a3248d6cf3a7779e220957bc85 (patch) | |
tree | b9acfb9d68c6866acc3cfb9ee59d72ff43f1ebc3 /website/usageExamples/BuilderExample_post.jpage | |
parent | 72fd50b9f1db1ab6bfc1753ba6a1e686a2f0f22c (diff) | |
download | lombok-8b7a7cbc813653a3248d6cf3a7779e220957bc85.tar.gz lombok-8b7a7cbc813653a3248d6cf3a7779e220957bc85.tar.bz2 lombok-8b7a7cbc813653a3248d6cf3a7779e220957bc85.zip |
The great rename: the old ‘website’ is now ‘website-old’, and ‘website2’ is now ‘website’.
Diffstat (limited to 'website/usageExamples/BuilderExample_post.jpage')
-rw-r--r-- | website/usageExamples/BuilderExample_post.jpage | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/website/usageExamples/BuilderExample_post.jpage b/website/usageExamples/BuilderExample_post.jpage new file mode 100644 index 00000000..54b064d7 --- /dev/null +++ b/website/usageExamples/BuilderExample_post.jpage @@ -0,0 +1,74 @@ +import java.util.Set; + +public class BuilderExample { + private String name; + private int age; + private Set<String> occupations; + + BuilderExample(String name, int age, Set<String> occupations) { + this.name = name; + this.age = age; + this.occupations = occupations; + } + + public static BuilderExampleBuilder builder() { + return new BuilderExampleBuilder(); + } + + public static class BuilderExampleBuilder { + private String name; + private int age; + private java.util.ArrayList<String> occupations; + + BuilderExampleBuilder() { + } + + public BuilderExampleBuilder name(String name) { + this.name = name; + return this; + } + + public BuilderExampleBuilder age(int age) { + this.age = age; + return this; + } + + public BuilderExampleBuilder occupation(String occupation) { + if (this.occupations == null) { + this.occupations = new java.util.ArrayList<String>(); + } + + this.occupations.add(occupation); + return this; + } + + public BuilderExampleBuilder occupations(Collection<? extends String> occupations) { + if (this.occupations == null) { + this.occupations = new java.util.ArrayList<String>(); + } + + this.occupations.addAll(occupations); + return this; + } + + public BuilderExampleBuilder clearOccupations() { + if (this.occupations != null) { + this.occupations.clear(); + } + + return this; + } + + public BuilderExample build() { + // complicated switch statement to produce a compact properly sized immutable set omitted. + // go to https://projectlombok.org/features/Singular-snippet.html to see it. + Set<String> occupations = ...; + return new BuilderExample(name, age, occupations); + } + + @java.lang.Override + public String toString() { + return "BuilderExample.BuilderExampleBuilder(name = " + this.name + ", age = " + this.age + ", occupations = " + this.occupations + ")"; + } + } +}
\ No newline at end of file |