diff options
| author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2016-10-17 23:09:21 +0200 |
|---|---|---|
| committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2017-05-29 21:01:53 +0200 |
| commit | 599b6aab677439ae1bdea2cdca3233d0b763fd3f (patch) | |
| tree | 8766f124271d056c8e8c22fd1a8a1ada08284275 /website2/usageExamples | |
| parent | 4e75ed8f8661033662b2d26c4a42fafa9d61b75f (diff) | |
| download | lombok-599b6aab677439ae1bdea2cdca3233d0b763fd3f.tar.gz lombok-599b6aab677439ae1bdea2cdca3233d0b763fd3f.tar.bz2 lombok-599b6aab677439ae1bdea2cdca3233d0b763fd3f.zip | |
Updated just about all of the pages to the template-based redesign.
Added ajaxified loading for feature pages.
Diffstat (limited to 'website2/usageExamples')
46 files changed, 1431 insertions, 0 deletions
diff --git a/website2/usageExamples/BuilderExample_post.jpage b/website2/usageExamples/BuilderExample_post.jpage new file mode 100644 index 00000000..54b064d7 --- /dev/null +++ b/website2/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 diff --git a/website2/usageExamples/BuilderExample_pre.jpage b/website2/usageExamples/BuilderExample_pre.jpage new file mode 100644 index 00000000..1557fff4 --- /dev/null +++ b/website2/usageExamples/BuilderExample_pre.jpage @@ -0,0 +1,10 @@ +import lombok.Builder; +import lombok.Singular; +import java.util.Set; + +@Builder +public class BuilderExample { + private String name; + private int age; + @Singular private Set<String> occupations; +} diff --git a/website2/usageExamples/CleanupExample_post.jpage b/website2/usageExamples/CleanupExample_post.jpage new file mode 100644 index 00000000..7e87c153 --- /dev/null +++ b/website2/usageExamples/CleanupExample_post.jpage @@ -0,0 +1,26 @@ +import java.io.*; + +public class CleanupExample { + public static void main(String[] args) throws IOException { + InputStream in = new FileInputStream(args[0]); + try { + OutputStream out = new FileOutputStream(args[1]); + try { + byte[] b = new byte[10000]; + while (true) { + int r = in.read(b); + if (r == -1) break; + out.write(b, 0, r); + } + } finally { + if (out != null) { + out.close(); + } + } + } finally { + if (in != null) { + in.close(); + } + } + } +} diff --git a/website2/usageExamples/CleanupExample_pre.jpage b/website2/usageExamples/CleanupExample_pre.jpage new file mode 100644 index 00000000..9f639171 --- /dev/null +++ b/website2/usageExamples/CleanupExample_pre.jpage @@ -0,0 +1,15 @@ +import lombok.Cleanup; +import java.io.*; + +public class CleanupExample { + public static void main(String[] args) throws IOException { + @Cleanup InputStream in = new FileInputStream(args[0]); + @Cleanup OutputStream out = new FileOutputStream(args[1]); + byte[] b = new byte[10000]; + while (true) { + int r = in.read(b); + if (r == -1) break; + out.write(b, 0, r); + } + } +} diff --git a/website2/usageExamples/ConstructorExample_post.jpage b/website2/usageExamples/ConstructorExample_post.jpage new file mode 100644 index 00000000..8a2d5069 --- /dev/null +++ b/website2/usageExamples/ConstructorExample_post.jpage @@ -0,0 +1,28 @@ +public class ConstructorExample<T> { + private int x, y; + @NonNull private T description; + + private ConstructorExample(T description) { + if (description == null) throw new NullPointerException("description"); + this.description = description; + } + + public static <T> ConstructorExample<T> of(T description) { + return new ConstructorExample<T>(description); + } + + @java.beans.ConstructorProperties({"x", "y", "description"}) + protected ConstructorExample(int x, int y, T description) { + if (description == null) throw new NullPointerException("description"); + this.x = x; + this.y = y; + this.description = description; + } + + public static class NoArgsExample { + @NonNull private String field; + + public NoArgsExample() { + } + } +} diff --git a/website2/usageExamples/ConstructorExample_pre.jpage b/website2/usageExamples/ConstructorExample_pre.jpage new file mode 100644 index 00000000..ac0d3c28 --- /dev/null +++ b/website2/usageExamples/ConstructorExample_pre.jpage @@ -0,0 +1,16 @@ +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import lombok.AllArgsConstructor; +import lombok.NonNull; + +@RequiredArgsConstructor(staticName = "of") +@AllArgsConstructor(access = AccessLevel.PROTECTED) +public class ConstructorExample<T> { + private int x, y; + @NonNull private T description; + + @NoArgsConstructor + public static class NoArgsExample { + @NonNull private String field; + } +} diff --git a/website2/usageExamples/DataExample_post.jpage b/website2/usageExamples/DataExample_post.jpage new file mode 100644 index 00000000..bef0a0f1 --- /dev/null +++ b/website2/usageExamples/DataExample_post.jpage @@ -0,0 +1,119 @@ +import java.util.Arrays; + +public class DataExample { + private final String name; + private int age; + private double score; + private String[] tags; + + public DataExample(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + void setAge(int age) { + this.age = age; + } + + public int getAge() { + return this.age; + } + + public void setScore(double score) { + this.score = score; + } + + public double getScore() { + return this.score; + } + + public String[] getTags() { + return this.tags; + } + + public void setTags(String[] tags) { + this.tags = tags; + } + + @Override public String toString() { + return "DataExample(" + this.getName() + ", " + this.getAge() + ", " + this.getScore() + ", " + Arrays.deepToString(this.getTags()) + ")"; + } + + protected boolean canEqual(Object other) { + return other instanceof DataExample; + } + + @Override public boolean equals(Object o) { + if (o == this) return true; + if (!(o instanceof DataExample)) return false; + DataExample other = (DataExample) o; + if (!other.canEqual((Object)this)) return false; + if (this.getName() == null ? other.getName() != null : !this.getName().equals(other.getName())) return false; + if (this.getAge() != other.getAge()) return false; + if (Double.compare(this.getScore(), other.getScore()) != 0) return false; + if (!Arrays.deepEquals(this.getTags(), other.getTags())) return false; + return true; + } + + @Override public int hashCode() { + final int PRIME = 59; + int result = 1; + final long temp1 = Double.doubleToLongBits(this.getScore()); + 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()); + return result; + } + + public static class Exercise<T> { + private final String name; + private final T value; + + private Exercise(String name, T value) { + this.name = name; + this.value = value; + } + + public static <T> Exercise<T> of(String name, T value) { + return new Exercise<T>(name, value); + } + + public String getName() { + return this.name; + } + + public T getValue() { + return this.value; + } + + @Override public String toString() { + return "Exercise(name=" + this.getName() + ", value=" + this.getValue() + ")"; + } + + protected boolean canEqual(Object other) { + return other instanceof Exercise; + } + + @Override public boolean equals(Object o) { + if (o == this) return true; + if (!(o instanceof Exercise)) return false; + Exercise<?> other = (Exercise<?>) o; + if (!other.canEqual((Object)this)) return false; + if (this.getName() == null ? other.getValue() != null : !this.getName().equals(other.getName())) return false; + if (this.getValue() == null ? other.getValue() != null : !this.getValue().equals(other.getValue())) return false; + return true; + } + + @Override public int hashCode() { + final int PRIME = 59; + int result = 1; + 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/website2/usageExamples/DataExample_pre.jpage b/website2/usageExamples/DataExample_pre.jpage new file mode 100644 index 00000000..404d3458 --- /dev/null +++ b/website2/usageExamples/DataExample_pre.jpage @@ -0,0 +1,18 @@ +import lombok.AccessLevel; +import lombok.Setter; +import lombok.Data; +import lombok.ToString; + +@Data public class DataExample { + private final String name; + @Setter(AccessLevel.PACKAGE) private int age; + private double score; + private String[] tags; + + @ToString(includeFieldNames=true) + @Data(staticConstructor="of") + public static class Exercise<T> { + private final String name; + private final T value; + } +} diff --git a/website2/usageExamples/EqualsAndHashCodeExample_post.jpage b/website2/usageExamples/EqualsAndHashCodeExample_post.jpage new file mode 100644 index 00000000..91e78250 --- /dev/null +++ b/website2/usageExamples/EqualsAndHashCodeExample_post.jpage @@ -0,0 +1,72 @@ +import java.util.Arrays; + +public class EqualsAndHashCodeExample { + private transient int transientVar = 10; + private String name; + private double score; + private Shape shape = new Square(5, 10); + private String[] tags; + private int id; + + public String getName() { + return this.name; + } + + @Override public boolean equals(Object o) { + if (o == this) return true; + if (!(o instanceof EqualsAndHashCodeExample)) return false; + EqualsAndHashCodeExample other = (EqualsAndHashCodeExample) o; + if (!other.canEqual((Object)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; + return true; + } + + @Override public int hashCode() { + final int PRIME = 59; + int result = 1; + final long temp1 = Double.doubleToLongBits(this.score); + 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; + } + + protected boolean canEqual(Object other) { + return other instanceof EqualsAndHashCodeExample; + } + + public static class Square extends Shape { + private final int width, height; + + public Square(int width, int height) { + this.width = width; + this.height = height; + } + + @Override public boolean equals(Object o) { + if (o == this) return true; + if (!(o instanceof Square)) return false; + Square other = (Square) o; + if (!other.canEqual((Object)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; + } + + @Override public int hashCode() { + final int PRIME = 59; + int result = 1; + result = (result*PRIME) + super.hashCode(); + result = (result*PRIME) + this.width; + result = (result*PRIME) + this.height; + return result; + } + + protected boolean canEqual(Object other) { + return other instanceof Square; + } + } +} diff --git a/website2/usageExamples/EqualsAndHashCodeExample_pre.jpage b/website2/usageExamples/EqualsAndHashCodeExample_pre.jpage new file mode 100644 index 00000000..64faf59f --- /dev/null +++ b/website2/usageExamples/EqualsAndHashCodeExample_pre.jpage @@ -0,0 +1,25 @@ +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(exclude={"id", "shape"}) +public class EqualsAndHashCodeExample { + private transient int transientVar = 10; + private String name; + private double score; + private Shape shape = new Square(5, 10); + private String[] tags; + private int id; + + public String getName() { + return this.name; + } + + @EqualsAndHashCode(callSuper=true) + public static class Square extends Shape { + private final int width, height; + + public Square(int width, int height) { + this.width = width; + this.height = height; + } + } +} diff --git a/website2/usageExamples/GetterLazyExample_post.jpage b/website2/usageExamples/GetterLazyExample_post.jpage new file mode 100644 index 00000000..5f34c43e --- /dev/null +++ b/website2/usageExamples/GetterLazyExample_post.jpage @@ -0,0 +1,26 @@ +public class GetterLazyExample { + private final java.util.concurrent.AtomicReference<java.lang.Object> cached = new java.util.concurrent.AtomicReference<java.lang.Object>(); + + public double[] getCached() { + java.lang.Object value = this.cached.get(); + if (value == null) { + synchronized(this.cached) { + value = this.cached.get(); + if (value == null) { + final double[] actualValue = expensive(); + value = actualValue == null ? this.cached : actualValue; + this.cached.set(value); + } + } + } + return (double[])(value == this.cached ? null : value); + } + + private double[] expensive() { + double[] result = new double[1000000]; + for (int i = 0; i < result.length; i++) { + result[i] = Math.asin(i); + } + return result; + } +} diff --git a/website2/usageExamples/GetterLazyExample_pre.jpage b/website2/usageExamples/GetterLazyExample_pre.jpage new file mode 100644 index 00000000..ca6c9d58 --- /dev/null +++ b/website2/usageExamples/GetterLazyExample_pre.jpage @@ -0,0 +1,13 @@ +import lombok.Getter; + +public class GetterLazyExample { + @Getter(lazy=true) private final double[] cached = expensive(); + + private double[] expensive() { + double[] result = new double[1000000]; + for (int i = 0; i < result.length; i++) { + result[i] = Math.asin(i); + } + return result; + } +} diff --git a/website2/usageExamples/GetterSetterExample_post.jpage b/website2/usageExamples/GetterSetterExample_post.jpage new file mode 100644 index 00000000..241a3a4e --- /dev/null +++ b/website2/usageExamples/GetterSetterExample_post.jpage @@ -0,0 +1,42 @@ +public class GetterSetterExample { + /** + * Age of the person. Water is wet. + */ + private int age = 10; + + /** + * Name of the person. + */ + private String name; + + @Override public String toString() { + return String.format("%s (age: %d)", name, age); + } + + /** + * Age of the person. Water is wet. + * + * @return The current value of this person's age. Circles are round. + */ + public int getAge() { + return age; + } + + /** + * Age of the person. Water is wet. + * + * @param age New value for this person's age. Sky is blue. + */ + public void setAge(int age) { + this.age = age; + } + + /** + * Changes the name of this person. + * + * @param name The new value. + */ + protected void setName(String name) { + this.name = name; + } +} diff --git a/website2/usageExamples/GetterSetterExample_pre.jpage b/website2/usageExamples/GetterSetterExample_pre.jpage new file mode 100644 index 00000000..4183aa5d --- /dev/null +++ b/website2/usageExamples/GetterSetterExample_pre.jpage @@ -0,0 +1,26 @@ +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; + +public class GetterSetterExample { + /** + * Age of the person. Water is wet. + * + * @param age New value for this person's age. Sky is blue. + * @return The current value of this person's age. Circles are round. + */ + @Getter @Setter private int age = 10; + + /** + * Name of the person. + * -- SETTER -- + * Changes the name of this person. + * + * @param name The new value. + */ + @Setter(AccessLevel.PROTECTED) private String name; + + @Override public String toString() { + return String.format("%s (age: %d)", name, age); + } +} diff --git a/website2/usageExamples/LogExample_post.jpage b/website2/usageExamples/LogExample_post.jpage new file mode 100644 index 00000000..eab3b046 --- /dev/null +++ b/website2/usageExamples/LogExample_post.jpage @@ -0,0 +1,23 @@ +public class LogExample { + private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(LogExample.class.getName()); + + public static void main(String... args) { + log.error("Something's wrong here"); + } +} + +public class LogExampleOther { + private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExampleOther.class); + + public static void main(String... args) { + log.error("Something else is wrong here"); + } +} + +public class LogExampleCategory { + private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("CounterLog"); + + public static void main(String... args) { + log.error("Calling the 'CounterLog' with a message"); + } +} diff --git a/website2/usageExamples/LogExample_pre.jpage b/website2/usageExamples/LogExample_pre.jpage new file mode 100644 index 00000000..ba27dd27 --- /dev/null +++ b/website2/usageExamples/LogExample_pre.jpage @@ -0,0 +1,26 @@ +import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; + +@Log +public class LogExample { + + public static void main(String... args) { + log.error("Something's wrong here"); + } +} + +@Slf4j +public class LogExampleOther { + + public static void main(String... args) { + log.error("Something else is wrong here"); + } +} + +@CommonsLog(topic="CounterLog") +public class LogExampleCategory { + + public static void main(String... args) { + log.error("Calling the 'CounterLog' with a message"); + } +} diff --git a/website2/usageExamples/NonNullExample_post.jpage b/website2/usageExamples/NonNullExample_post.jpage new file mode 100644 index 00000000..24175e06 --- /dev/null +++ b/website2/usageExamples/NonNullExample_post.jpage @@ -0,0 +1,13 @@ +import lombok.NonNull; + +public class NonNullExample extends Something { + private String name; + + public NonNullExample(@NonNull Person person) { + super("Hello"); + if (person == null) { + throw new NullPointerException("person"); + } + this.name = person.getName(); + } +} diff --git a/website2/usageExamples/NonNullExample_pre.jpage b/website2/usageExamples/NonNullExample_pre.jpage new file mode 100644 index 00000000..47556ce7 --- /dev/null +++ b/website2/usageExamples/NonNullExample_pre.jpage @@ -0,0 +1,10 @@ +import lombok.NonNull; + +public class NonNullExample extends Something { + private String name; + + public NonNullExample(@NonNull Person person) { + super("Hello"); + this.name = person.getName(); + } +} diff --git a/website2/usageExamples/Singular-snippetExample_post.jpage b/website2/usageExamples/Singular-snippetExample_post.jpage new file mode 100644 index 00000000..4e2b0460 --- /dev/null +++ b/website2/usageExamples/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> o |
