Skip to content

Instantly share code, notes, and snippets.

@strelchenya
Created April 28, 2021 17:20
Show Gist options
  • Save strelchenya/154ab10eaea6d78fec21c85eb8e94933 to your computer and use it in GitHub Desktop.
Save strelchenya/154ab10eaea6d78fec21c85eb8e94933 to your computer and use it in GitHub Desktop.
package com.javarush.task.task21.task2106;
import java.util.Date;
import java.util.Objects;
/*
Ошибка в equals/hashCode
*/
public class Solution {
private int anInt;
private String string;
private double aDouble;
private Date date;
private Solution solution;
public Solution(int anInt, String string, double aDouble, Date date, Solution solution) {
this.anInt = anInt;
this.string = string;
this.aDouble = aDouble;
this.date = date;
this.solution = solution;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Solution)) return false;
Solution solution1 = (Solution) o;
if (Double.compare(solution1.aDouble, aDouble) != 0) return false;
if (anInt != solution1.anInt) return false;
if (date != null ? !date.equals(solution1.date) : solution1.date != null) return false;
if (solution != null ? !solution.equals(solution1.solution) : solution1.solution != null) return false;
return string != null ? string.equals(solution1.string) : solution1.string == null;
}
@Override
public int hashCode() {
int result;
long temp;
result = anInt;
result = 31 * result + (string != null ? string.hashCode() : 0);
temp = aDouble != +0.0d ? Double.doubleToLongBits(aDouble) : 0L;
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (date != null ? date.hashCode() : 0);
result = 31 * result + (solution != null ? solution.hashCode() : 0);
return result;
}
/* @Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Solution)) return false;
Solution solution1 = (Solution) o;
if (Double.compare(solution1.aDouble, aDouble) != 0) return false;
if (anInt != solution1.anInt) return false;
if (date != null ? !date.equals(solution1.date) : solution1.date == null) return false;
if (solution != null ? !solution.equals(solution1.solution) : solution1.solution == null) return false;
if (string != null ? !string.equals(solution1.string) : solution1.string == null) return false;
return true;
}
@Override
public int hashCode() {
int result;
long temp;
result = anInt;
temp = aDouble != +0.0d ? Double.doubleToLongBits(aDouble) : 0L;
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (solution != null ? solution.hashCode() : 0);
return result;
}*/
public static void main(String[] args) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment