aboutsummaryrefslogtreecommitdiff
path: root/usage_examples/DataExample_post.jpage
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-07-12 00:39:18 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-07-12 00:39:18 +0200
commit2adf65aeb38ef33d665c1bfd85039f28659ceb27 (patch)
tree5854866fca4cdc557d92c439fcc263ebd6e7336f /usage_examples/DataExample_post.jpage
parent5fef32c1f59403ef2978942ac2838731b1406413 (diff)
downloadlombok-2adf65aeb38ef33d665c1bfd85039f28659ceb27.tar.gz
lombok-2adf65aeb38ef33d665c1bfd85039f28659ceb27.tar.bz2
lombok-2adf65aeb38ef33d665c1bfd85039f28659ceb27.zip
Example for the @Data annotation.
Diffstat (limited to 'usage_examples/DataExample_post.jpage')
-rw-r--r--usage_examples/DataExample_post.jpage111
1 files changed, 111 insertions, 0 deletions
diff --git a/usage_examples/DataExample_post.jpage b/usage_examples/DataExample_post.jpage
new file mode 100644
index 00000000..27e3db22
--- /dev/null
+++ b/usage_examples/DataExample_post.jpage
@@ -0,0 +1,111 @@
+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 name;
+ }
+
+ void setAge(int age) {
+ this.age = age;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setScore(double score) {
+ this.score = score;
+ }
+
+ public double getScore() {
+ return score;
+ }
+
+ public String[] getTags() {
+ return tags;
+ }
+
+ public void setTags(String[] tags) {
+ this.tags = tags;
+ }
+
+ @Override public String toString() {
+ return "DataExample(" + name + ", " + age + ", " + score + ", " + Arrays.deepToString(tags) + ")";
+ }
+
+ @Override public boolean equals(Object o) {
+ if (o == this) return true;
+ if (o == null) return false;
+ if (o.getClass() != this.getClass()) return false;
+ DataExample other = (DataExample) o;
+ if (name == null ? other.name != null : !name.equals(other.name)) return false;
+ if (age != other.age) return false;
+ if (Double.compare(score, other.score) != 0) return false;
+ if (!Arrays.deepEquals(tags, other.tags)) return false;
+ return true;
+ }
+
+ @Override public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ final long temp1 = Double.doubleToLongBits(score);
+ result = (result*PRIME) + (name == null ? 0 : name.hashCode());
+ result = (result*PRIME) + age;
+ result = (result*PRIME) + (int)(temp1 ^ (temp1 >>> 32));
+ result = (result*PRIME) + Arrays.deepHashCode(tags);
+ 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 name;
+ }
+
+ public T getValue() {
+ return value;
+ }
+
+ @Override public String toString() {
+ return "Exercise(" + name + ", " + value + ")";
+ }
+
+ @Override public boolean equals(Object o) {
+ if (o == this) return true;
+ if (o == null) return false;
+ if (o.getClass() != this.getClass()) return false;
+ Exercise<?> other = (Exercise<?>) o;
+ if (name == null ? other.name != null : !name.equals(other.name)) return false;
+ if (value == null ? other.value != null : !value.equals(other.value)) return false;
+ return true;
+ }
+
+ @Override public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = (result*PRIME) + (name == null ? 0 : name.hashCode());
+ result = (result*PRIME) + (value == null ? 0 : value.hashCode());
+ return result;
+ }
+ }
+}