Files
lombok/usage_examples/DataExample_post.jpage
T
Reinier Zwitserloot fb6be45d2b Added website feature documentation for @ToString and @EqualsAndHashCode, and modified the docs for @Data to refer to the docs of these new annotations.
The build script for the website has been updated to clean out the website build dir first, so files that used to exist but have now been tossed are no longer there.

There's also a special website-no-videos target which builds a website deployable without the videos. This makes the upload a lot faster if the videos haven't changed.
2009-07-28 17:41:56 +02:00

112 lines
2.6 KiB
Plaintext

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=" + name + ", value=" + 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;
}
}
}