aboutsummaryrefslogtreecommitdiff
path: root/usage_examples
diff options
context:
space:
mode:
Diffstat (limited to 'usage_examples')
-rw-r--r--usage_examples/EqualsAndHashCodeExample_post.jpage16
-rw-r--r--usage_examples/GetterLazyExample_post.jpage25
-rw-r--r--usage_examples/GetterLazyExample_pre.jpage13
-rw-r--r--usage_examples/valExample_post.jpage21
-rw-r--r--usage_examples/valExample_pre.jpage20
5 files changed, 92 insertions, 3 deletions
diff --git a/usage_examples/EqualsAndHashCodeExample_post.jpage b/usage_examples/EqualsAndHashCodeExample_post.jpage
index 312bb92f..189a520e 100644
--- a/usage_examples/EqualsAndHashCodeExample_post.jpage
+++ b/usage_examples/EqualsAndHashCodeExample_post.jpage
@@ -15,8 +15,9 @@ public class EqualsAndHashCodeExample {
@Override public boolean equals(Object o) {
if (o == this) return true;
if (o == null) return false;
- if (o.getClass() != this.getClass()) return false;
+ if (!(o instanceof EqualsAndHashCodeExample)) return false;
EqualsAndHashCodeExample other = (EqualsAndHashCodeExample) o;
+ if (!other.canEqual(this)) return false;
if (this.getName() == null ? other.getName() != null : !this.getName().equals(other.getName())) return false;
if (Double.compare(this.score, other.score) != 0) return false;
if (!Arrays.deepEquals(this.tags, other.tags)) return false;
@@ -33,6 +34,10 @@ public class EqualsAndHashCodeExample {
return result;
}
+ public boolean canEqual(Object other) {
+ return other instanceof EqualsAndHashCodeExample;
+ }
+
public static class Square extends Shape {
private final int width, height;
@@ -44,9 +49,10 @@ public class EqualsAndHashCodeExample {
@Override public boolean equals(Object o) {
if (o == this) return true;
if (o == null) return false;
- if (o.getClass() != this.getClass()) return false;
- if (!super.equals(o)) return false;
+ if (!(o instanceof Square)) return false;
Square other = (Square) o;
+ if (!other.canEqual(this)) return false;
+ if (!super.equals(o)) return false;
if (this.width != other.width) return false;
if (this.height != other.height) return false;
return true;
@@ -60,5 +66,9 @@ public class EqualsAndHashCodeExample {
result = (result*PRIME) + this.height;
return result;
}
+
+ public boolean canEqual(Object other) {
+ return other instanceof Square;
+ }
}
}
diff --git a/usage_examples/GetterLazyExample_post.jpage b/usage_examples/GetterLazyExample_post.jpage
new file mode 100644
index 00000000..76101db1
--- /dev/null
+++ b/usage_examples/GetterLazyExample_post.jpage
@@ -0,0 +1,25 @@
+public class GetterLazyExample {
+ private int[] $lombok$lazy1v;
+ private volatile boolean $lombok$lazy1i;
+ private final Object $lombok$lazyLock = new Object[0];
+
+ public int[] getCached() {
+ if (!this.$lombok$lazy1i) {
+ synchronized (this.$lombok$lazyLock) {
+ if (!this.$lombok$lazy1i) {
+ this.$lombok$lazy1v = expensive();
+ this.$lombok$lazy1i = true;
+ }
+ }
+ }
+ return this.$lombok$lazy1v;
+ }
+
+ private int[] expensive() {
+ double[] result = new double[1000000];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = Math.asin(i);
+ }
+ return result;
+ }
+}
diff --git a/usage_examples/GetterLazyExample_pre.jpage b/usage_examples/GetterLazyExample_pre.jpage
new file mode 100644
index 00000000..a6ca0966
--- /dev/null
+++ b/usage_examples/GetterLazyExample_pre.jpage
@@ -0,0 +1,13 @@
+import lombok.Getter;
+
+public class GetterLazyExample {
+ @Getter(lazy=true) private final int[] cached = expensive();
+
+ private int[] expensive() {
+ double[] result = new double[1000000];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = Math.asin(i);
+ }
+ return result;
+ }
+}
diff --git a/usage_examples/valExample_post.jpage b/usage_examples/valExample_post.jpage
new file mode 100644
index 00000000..e0f983d9
--- /dev/null
+++ b/usage_examples/valExample_post.jpage
@@ -0,0 +1,21 @@
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ValExample {
+ public String example() {
+ final ArrayList<String> example = new ArrayList<String>();
+ example.add("Hello, World!");
+ String foo = example.get(0);
+ return foo.toLowerCase();
+ }
+
+ public void example2() {
+ final HashMap<Integer, String> map = new HashMap<Integer, String>();
+ map.put(0, "zero");
+ map.put(5, "five");
+ for (final Map.Entry<Integer, String> entry : map.entrySet()) {
+ System.out.printf("%d: %s\n", entry.getKey(), entry.getValue());
+ }
+ }
+}
diff --git a/usage_examples/valExample_pre.jpage b/usage_examples/valExample_pre.jpage
new file mode 100644
index 00000000..8b9dadc3
--- /dev/null
+++ b/usage_examples/valExample_pre.jpage
@@ -0,0 +1,20 @@
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class ValExample {
+ public String example() {
+ val example = new ArrayList<String>();
+ example.add("Hello, World!");
+ val foo = example.get(0);
+ return foo.toLowerCase();
+ }
+
+ public void example2() {
+ val map = new HashMap<Integer, String>();
+ map.put(0, "zero");
+ map.put(5, "five");
+ for (val entry : map.entrySet()) {
+ System.out.printf("%d: %s\n", entry.getKey(), entry.getValue());
+ }
+ }
+}