aboutsummaryrefslogtreecommitdiff
path: root/usage_examples
diff options
context:
space:
mode:
Diffstat (limited to 'usage_examples')
-rw-r--r--usage_examples/BuilderExample_post.jpage87
-rw-r--r--usage_examples/BuilderExample_pre.jpage11
-rw-r--r--usage_examples/DataExample_post.jpage6
-rw-r--r--usage_examples/EqualsAndHashCodeExample_post.jpage2
-rw-r--r--usage_examples/Singular-snippetExample_post.jpage160
-rw-r--r--usage_examples/Singular-snippetExample_pre.jpage14
-rw-r--r--usage_examples/ToStringExample_pre.jpage2
-rw-r--r--usage_examples/ValueExample_post.jpage6
-rw-r--r--usage_examples/experimental/BuilderExample_post.jpage40
-rw-r--r--usage_examples/experimental/BuilderExample_pre.jpage7
-rw-r--r--usage_examples/experimental/HelperExample_post.jpage14
-rw-r--r--usage_examples/experimental/HelperExample_pre.jpage15
-rw-r--r--usage_examples/experimental/UtilityClassExample_post.jpage11
-rw-r--r--usage_examples/experimental/UtilityClassExample_pre.jpage10
-rw-r--r--usage_examples/experimental/WitherExample_post.jpage10
-rw-r--r--usage_examples/experimental/onXExample_pre.jpage6
-rw-r--r--usage_examples/experimental/varExample_post.jpage21
-rw-r--r--usage_examples/experimental/varExample_pre.jpage21
18 files changed, 381 insertions, 62 deletions
diff --git a/usage_examples/BuilderExample_post.jpage b/usage_examples/BuilderExample_post.jpage
new file mode 100644
index 00000000..0b64703c
--- /dev/null
+++ b/usage_examples/BuilderExample_post.jpage
@@ -0,0 +1,87 @@
+import java.util.Set;
+
+public class BuilderExample {
+ private long created;
+ 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;
+ }
+
+ private static long $default$created() {
+ return System.currentTimeMillis();
+ }
+
+ public static BuilderExampleBuilder builder() {
+ return new BuilderExampleBuilder();
+ }
+
+ public static class BuilderExampleBuilder {
+ private long created;
+ private boolean created$set;
+ private String name;
+ private int age;
+ private java.util.ArrayList<String> occupations;
+
+ BuilderExampleBuilder() {
+ }
+
+ public BuilderExampleBuilder created(long created) {
+ this.created = created;
+ this.created$set = true;
+ return this;
+ }
+
+ 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(created$set ? created : BuilderExample.$default$created(), name, age, occupations);
+ }
+
+ @java.lang.Override
+ public String toString() {
+ return "BuilderExample.BuilderExampleBuilder(created = " + this.created + ", name = " + this.name + ", age = " + this.age + ", occupations = " + this.occupations + ")";
+ }
+ }
+} \ No newline at end of file
diff --git a/usage_examples/BuilderExample_pre.jpage b/usage_examples/BuilderExample_pre.jpage
new file mode 100644
index 00000000..3b1b0df2
--- /dev/null
+++ b/usage_examples/BuilderExample_pre.jpage
@@ -0,0 +1,11 @@
+import lombok.Builder;
+import lombok.Singular;
+import java.util.Set;
+
+@Builder
+public class BuilderExample {
+ @Builder.Default private long created = System.currentTimeMillis();
+ private String name;
+ private int age;
+ @Singular private Set<String> occupations;
+}
diff --git a/usage_examples/DataExample_post.jpage b/usage_examples/DataExample_post.jpage
index e53e999c..bef0a0f1 100644
--- a/usage_examples/DataExample_post.jpage
+++ b/usage_examples/DataExample_post.jpage
@@ -62,7 +62,7 @@ public class DataExample {
final int PRIME = 59;
int result = 1;
final long temp1 = Double.doubleToLongBits(this.getScore());
- result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode());
+ result = (result*PRIME) + (this.getName() == null ? 43 : this.getName().hashCode());
result = (result*PRIME) + this.getAge();
result = (result*PRIME) + (int)(temp1 ^ (temp1 >>> 32));
result = (result*PRIME) + Arrays.deepHashCode(this.getTags());
@@ -111,8 +111,8 @@ public class DataExample {
@Override public int hashCode() {
final int PRIME = 59;
int result = 1;
- result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode());
- result = (result*PRIME) + (this.getValue() == null ? 0 : this.getValue().hashCode());
+ result = (result*PRIME) + (this.getName() == null ? 43 : this.getName().hashCode());
+ result = (result*PRIME) + (this.getValue() == null ? 43 : this.getValue().hashCode());
return result;
}
}
diff --git a/usage_examples/EqualsAndHashCodeExample_post.jpage b/usage_examples/EqualsAndHashCodeExample_post.jpage
index f58e045b..91e78250 100644
--- a/usage_examples/EqualsAndHashCodeExample_post.jpage
+++ b/usage_examples/EqualsAndHashCodeExample_post.jpage
@@ -27,7 +27,7 @@ public class EqualsAndHashCodeExample {
final int PRIME = 59;
int result = 1;
final long temp1 = Double.doubleToLongBits(this.score);
- result = (result*PRIME) + (this.name == null ? 0 : this.name.hashCode());
+ result = (result*PRIME) + (this.name == null ? 43 : this.name.hashCode());
result = (result*PRIME) + (int)(temp1 ^ (temp1 >>> 32));
result = (result*PRIME) + Arrays.deepHashCode(this.tags);
return result;
diff --git a/usage_examples/Singular-snippetExample_post.jpage b/usage_examples/Singular-snippetExample_post.jpage
new file mode 100644
index 00000000..4e2b0460
--- /dev/null
+++ b/usage_examples/Singular-snippetExample_post.jpage
@@ -0,0 +1,160 @@
+import java.util.Collection;
+import java.util.Set;
+import java.util.SortedMap;
+import com.google.common.collect.ImmutableList;
+
+public class SingularExample<T extends Number> {
+ private Set<String> occupations;
+ private ImmutableList<String> axes;
+ private SortedMap<Integer, T> elves;
+ private Collection<?> minutiae;
+
+ SingularExample(Set<String> occupations, ImmutableList<String> axes, SortedMap<Integer, T> elves, Collection<?> minutiae) {
+ this.occupations = occupations;
+ this.axes = axes;
+ this.elves = elves;
+ this.minutiae = minutiae;
+ }
+
+ public static class SingularExampleBuilder<T extends Number> {
+ private java.util.ArrayList<String> occupations;
+ private com.google.common.collect.ImmutableList.Builder<String> axes;
+ private java.util.ArrayList<Integer> elves$key;
+ private java.util.ArrayList<T> elves$value;
+ private java.util.ArrayList<java.lang.Object> minutiae;
+
+ SingularExampleBuilder() {
+ }
+
+ public SingularExampleBuilder<T> occupation(String occupation) {
+ if (this.occupations == null) {
+ this.occupations = new java.util.ArrayList<String>();
+ }
+
+ this.occupations.add(occupation);
+ return this;
+ }
+
+ @java.lang.SuppressWarnings("all")
+ public SingularExampleBuilder<T> occupations(java.util.Collection<? extends String> occupations) {
+ if (this.occupations == null) {
+ this.occupations = new java.util.ArrayList<String>();
+ }
+
+ this.occupations.addAll(occupations);
+ return this;
+ }
+
+ public SingularExampleBuilder<T> axis(String axis) {
+ if (this.axes == null) {
+ this.axes = com.google.common.collect.ImmutableList.builder();
+ }
+
+ this.axes.add(axis);
+ return this;
+ }
+
+ public SingularExampleBuilder<T> axes(java.lang.Iterable<? extends String> axes) {
+ if (this.axes == null) {
+ this.axes = com.google.common.collect.ImmutableList.builder();
+ }
+
+ this.axes.addAll(axes);
+ return this;
+ }
+
+ public SingularExampleBuilder<T> elf(Integer elfKey, T elfValue) {
+ if (this.elves$key == null) {
+ this.elves$key = new java.util.ArrayList<Integer>();
+ this.elves$value = new java.util.ArrayList<T>();
+ }
+
+ this.elves$key.add(elfKey);
+ this.elves$value.add(elfValue);
+ return this;
+ }
+
+ public SingularExampleBuilder<T> elves(java.util.Map<? extends Integer, ? extends T> elves) {
+ if (this.elves$key == null) {
+ this.elves$key = new java.util.ArrayList<Integer>();
+ this.elves$value = new java.util.ArrayList<T>();
+ }
+
+ for (java.util.Map.Entry<? extends Integer, ? extends T> $lombokEntry : elves.entrySet()) {
+ this.elves$key.add($lombokEntry.getKey());
+ this.elves$value.add($lombokEntry.getValue());
+ }
+ return this;
+ }
+
+ public SingularExampleBuilder<T> minutia(java.lang.Object minutia) {
+ if (this.minutiae == null) {
+ this.minutiae = new java.util.ArrayList<java.lang.Object>();
+ }
+
+ this.minutiae.add(minutia);
+ return this;
+ }
+
+ public SingularExampleBuilder<T> minutiae(java.util.Collection<?> minutiae) {
+ if (this.minutiae == null) {
+ this.minutiae = new java.util.ArrayList<java.lang.Object>();
+ }
+
+ this.minutiae.addAll(minutiae);
+ return this;
+ }
+
+ public SingularExample<T> build() {
+ java.util.Set<String> occupations;
+ switch (this.occupations == null ? 0 : this.occupations.size()) {
+ case 0:
+ occupations = java.util.Collections.emptySet();
+ break;
+
+ case 1:
+ occupations = java.util.Collections.singleton(this.occupations.get(0));
+ break;
+
+ default:
+ occupations = new java.util.LinkedHashSet<String>(this.occupations.size() < 1073741824 ? 1 + this.occupations.size() + (this.occupations.size() - 3) / 3 : java.lang.Integer.MAX_VALUE);
+ occupations.addAll(this.occupations);
+ occupations = java.util.Collections.unmodifiableSet(occupations);
+
+ }
+
+ com.google.common.collect.ImmutableList<String> axes = this.axes == null ? com.google.common.collect.ImmutableList.<String>of() : this.axes.build();
+
+ java.util.SortedMap<Integer, T> elves = new java.util.TreeMap<Integer, T>();
+ if (this.elves$key != null) for (int $i = 0; $i < (this.elves$key == null ? 0 : this.elves$key.size()); $i++) elves.put(this.elves$key.get($i), this.elves$value.get($i));
+ elves = java.util.Collections.unmodifiableSortedMap(elves);
+
+ java.util.Collection<java.lang.Object> minutiae;
+ switch (this.minutiae == null ? 0 : this.minutiae.size()) {
+ case 0:
+ minutiae = java.util.Collections.emptyList();
+ break;
+
+ case 1:
+ minutiae = java.util.Collections.singletonList(this.minutiae.get(0));
+ break;
+
+ default:
+ minutiae = java.util.Collections.unmodifiableList(new java.util.ArrayList<java.lang.Object>(this.minutiae));
+
+ }
+
+ return new SingularExample<T>(occupations, axes, elves, minutiae);
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "SingularExample.SingularExampleBuilder(occupations=" + this.occupations + ", axes=" + this.axes + ", elves$key=" + this.elves$key + ", elves$value=" + this.elves$value + ", minutiae=" + this.minutiae + ")";
+ }
+ }
+
+ @java.lang.SuppressWarnings("all")
+ public static <T extends Number> SingularExampleBuilder<T> builder() {
+ return new SingularExampleBuilder<T>();
+ }
+}
diff --git a/usage_examples/Singular-snippetExample_pre.jpage b/usage_examples/Singular-snippetExample_pre.jpage
new file mode 100644
index 00000000..65f6bbc8
--- /dev/null
+++ b/usage_examples/Singular-snippetExample_pre.jpage
@@ -0,0 +1,14 @@
+import lombok.Builder;
+import lombok.Singular;
+import java.util.Collection;
+import java.util.Set;
+import java.util.SortedMap;
+import com.google.common.collect.ImmutableList;
+
+@Builder
+public class SingularExample<T extends Number> {
+ private @Singular Set<String> occupations;
+ private @Singular("axis") ImmutableList<String> axes;
+ private @Singular SortedMap<Integer, T> elves;
+ private @Singular Collection<?> minutiae;
+}
diff --git a/usage_examples/ToStringExample_pre.jpage b/usage_examples/ToStringExample_pre.jpage
index a15fb944..39b25892 100644
--- a/usage_examples/ToStringExample_pre.jpage
+++ b/usage_examples/ToStringExample_pre.jpage
@@ -9,7 +9,7 @@ public class ToStringExample {
private int id;
public String getName() {
- return this.getName();
+ return this.name;
}
@ToString(callSuper=true, includeFieldNames=true)
diff --git a/usage_examples/ValueExample_post.jpage b/usage_examples/ValueExample_post.jpage
index 4ac8654e..8a5d4836 100644
--- a/usage_examples/ValueExample_post.jpage
+++ b/usage_examples/ValueExample_post.jpage
@@ -49,7 +49,7 @@ public final class ValueExample {
final int PRIME = 59;
int result = 1;
final Object $name = this.getName();
- result = result * PRIME + ($name == null ? 0 : $name.hashCode());
+ result = result * PRIME + ($name == null ? 43 : $name.hashCode());
result = result * PRIME + this.getAge();
final long $score = Double.doubleToLongBits(this.getScore());
result = result * PRIME + (int)($score >>> 32 ^ $score);
@@ -106,9 +106,9 @@ public final class ValueExample {
final int PRIME = 59;
int result = 1;
final Object $name = this.getName();
- result = result * PRIME + ($name == null ? 0 : $name.hashCode());
+ result = result * PRIME + ($name == null ? 43 : $name.hashCode());
final Object $value = this.getValue();
- result = result * PRIME + ($value == null ? 0 : $value.hashCode());
+ result = result * PRIME + ($value == null ? 43 : $value.hashCode());
return result;
}
diff --git a/usage_examples/experimental/BuilderExample_post.jpage b/usage_examples/experimental/BuilderExample_post.jpage
deleted file mode 100644
index 624b236b..00000000
--- a/usage_examples/experimental/BuilderExample_post.jpage
+++ /dev/null
@@ -1,40 +0,0 @@
-public class BuilderExample {
- private String name;
- private int age;
-
- BuilderExample(String name, int age) {
- this.name = name;
- this.age = age;
- }
-
- public static BuilderExampleBuilder builder() {
- return new BuilderExampleBuilder();
- }
-
- public static class BuilderExampleBuilder {
- private String name;
- private int age;
-
- BuilderExampleBuilder() {
- }
-
- public BuilderExampleBuilder name(String name) {
- this.name = name;
- return this;
- }
-
- public BuilderExampleBuilder age(int age) {
- this.age = age;
- return this;
- }
-
- public BuilderExample build() {
- return new BuilderExample(name, age);
- }
-
- @java.lang.Override
- public String toString() {
- return "BuilderExample.BuilderExampleBuilder(name = " + this.name + ", age = " + this.age + ")";
- }
- }
-} \ No newline at end of file
diff --git a/usage_examples/experimental/BuilderExample_pre.jpage b/usage_examples/experimental/BuilderExample_pre.jpage
deleted file mode 100644
index 9c754352..00000000
--- a/usage_examples/experimental/BuilderExample_pre.jpage
+++ /dev/null
@@ -1,7 +0,0 @@
-import lombok.experimental.Builder;
-
-@Builder
-public class BuilderExample {
- private String name;
- private int age;
-}
diff --git a/usage_examples/experimental/HelperExample_post.jpage b/usage_examples/experimental/HelperExample_post.jpage
new file mode 100644
index 00000000..04a97b9f
--- /dev/null
+++ b/usage_examples/experimental/HelperExample_post.jpage
@@ -0,0 +1,14 @@
+public class HelperExample {
+ int someMethod(int arg1) {
+ int localVar = 5;
+
+ class Helpers {
+ int helperMethod(int arg) {
+ return arg + localVar;
+ }
+ }
+ Helpers $Helpers = new Helpers();
+
+ return $Helpers.helperMethod(10);
+ }
+}
diff --git a/usage_examples/experimental/HelperExample_pre.jpage b/usage_examples/experimental/HelperExample_pre.jpage
new file mode 100644
index 00000000..cd86ef3c
--- /dev/null
+++ b/usage_examples/experimental/HelperExample_pre.jpage
@@ -0,0 +1,15 @@
+import lombok.experimental.Helper;
+
+public class HelperExample {
+ int someMethod(int arg1) {
+ int localVar = 5;
+
+ @Helper class Helpers {
+ int helperMethod(int arg) {
+ return arg + localVar;
+ }
+ }
+
+ return helperMethod(10);
+ }
+}
diff --git a/usage_examples/experimental/UtilityClassExample_post.jpage b/usage_examples/experimental/UtilityClassExample_post.jpage
new file mode 100644
index 00000000..70810230
--- /dev/null
+++ b/usage_examples/experimental/UtilityClassExample_post.jpage
@@ -0,0 +1,11 @@
+public final class UtilityClassExample {
+ private static final int CONSTANT = 5;
+
+ private UtilityClassExample() {
+ throw new java.lang.UnsupportedOperationException("This is a utility class and cannot be instantiated");
+ }
+
+ public static void addSomething(int in) {
+ return in + CONSTANT;
+ }
+}
diff --git a/usage_examples/experimental/UtilityClassExample_pre.jpage b/usage_examples/experimental/UtilityClassExample_pre.jpage
new file mode 100644
index 00000000..85731b81
--- /dev/null
+++ b/usage_examples/experimental/UtilityClassExample_pre.jpage
@@ -0,0 +1,10 @@
+import lombok.experimental.UtilityClass;
+
+@UtilityClass
+public class UtilityClassExample {
+ private final int CONSTANT = 5;
+
+ public void addSomething(int in) {
+ return in + CONSTANT;
+ }
+}
diff --git a/usage_examples/experimental/WitherExample_post.jpage b/usage_examples/experimental/WitherExample_post.jpage
index bb5952af..3447192a 100644
--- a/usage_examples/experimental/WitherExample_post.jpage
+++ b/usage_examples/experimental/WitherExample_post.jpage
@@ -3,19 +3,19 @@ import lombok.NonNull;
public class WitherExample {
private final int age;
private @NonNull final String name;
-
+
public WitherExample(String name, int age) {
if (name == null) throw new NullPointerException();
this.name = name;
this.age = age;
}
-
+
public WitherExample withAge(int age) {
- return this.age == age ? this : new WitherExample(age, name);
+ return this.age == age ? this : new WitherExample(name, age);
}
-
+
protected WitherExample withName(@NonNull String name) {
if (name == null) throw new java.lang.NullPointerException("name");
- return this.name == name ? this : new WitherExample(age, name);
+ return this.name == name ? this : new WitherExample(name, age);
}
} \ No newline at end of file
diff --git a/usage_examples/experimental/onXExample_pre.jpage b/usage_examples/experimental/onXExample_pre.jpage
index f8fcb435..e54371ae 100644
--- a/usage_examples/experimental/onXExample_pre.jpage
+++ b/usage_examples/experimental/onXExample_pre.jpage
@@ -9,7 +9,9 @@ import javax.validation.constraints.Max;
@AllArgsConstructor(onConstructor=@__(@Inject))
public class OnXExample {
- @Getter(onMethod=@__({@Id, @Column(name="unique-id")}))
- @Setter(onParam=@__(@Max(10000)))
+// @Getter(onMethod=@__({@Id, @Column(name="unique-id")})) //JDK7
+// @Setter(onParam=@__(@Max(10000))) //JDK7
+ @Getter(onMethod_={@Id, @Column(name="unique-id")}) //JDK8
+ @Setter(onParam_=@Max(10000)) //JDK8
private long unid;
}
diff --git a/usage_examples/experimental/varExample_post.jpage b/usage_examples/experimental/varExample_post.jpage
new file mode 100644
index 00000000..d0a7c124
--- /dev/null
+++ b/usage_examples/experimental/varExample_post.jpage
@@ -0,0 +1,21 @@
+import java.util.ArrayList;
+import lombok.var;
+
+public class VarExample {
+ public String example() {
+ ArrayList<String> example = new ArrayList<String>();
+ example.add("Hello, World!");
+ final String foo = example.get(0);
+ return foo.toLowerCase();
+ }
+
+ public void example2() {
+ ArrayList<String> list = new ArrayList<String>();
+ list.add("zero");
+ list.add("one");
+ list.add("two");
+ for(int i = 0; i < list.size(); ++i) {
+ System.out.printf("%d: %s\n", i, list.get(i));
+ }
+ }
+}
diff --git a/usage_examples/experimental/varExample_pre.jpage b/usage_examples/experimental/varExample_pre.jpage
new file mode 100644
index 00000000..e58c4c0d
--- /dev/null
+++ b/usage_examples/experimental/varExample_pre.jpage
@@ -0,0 +1,21 @@
+import java.util.ArrayList;
+import lombok.var;
+
+public class VarExample {
+ public String example() {
+ var example = new ArrayList<String>();
+ example.add("Hello, World!");
+ final var foo = example.get(0);
+ return foo.toLowerCase();
+ }
+
+ public void example2() {
+ var list = new ArrayList<String>();
+ list.add("zero");
+ list.add("one");
+ list.add("two");
+ for(var i = 0; i < list.size(); ++i) {
+ System.out.printf("%d: %s\n", i, list.get(i));
+ }
+ }
+}