mirror of
https://github.com/tiennm99/lombok.git
synced 2026-05-25 17:57:25 +00:00
91bb3455da
Also updated usage examples for @EqualsAndHashCode, @ToString, and @Data, which also contained some other minor issues (such as missing this. qualifiers). Still to do is to detect that getters don't exist _yet_ but will later due to @Getter or @Data.
112 lines
2.9 KiB
Plaintext
112 lines
2.9 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 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()) + ")";
|
|
}
|
|
|
|
@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 (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 = 31;
|
|
int result = 1;
|
|
final long temp1 = Double.doubleToLongBits(this.getScore());
|
|
result = (result*PRIME) + (this.getName() == null ? 0 : 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() + ")";
|
|
}
|
|
|
|
@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 (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 = 31;
|
|
int result = 1;
|
|
result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode());
|
|
result = (result*PRIME) + (this.getValue() == null ? 0 : this.getValue().hashCode());
|
|
return result;
|
|
}
|
|
}
|
|
}
|