foursBool выдает false, остальные true. Не могу разобраться почему.
С HashSet тоже непонятно.
package com.javarush.task.task21.task2106;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/*
Ошибка в 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;
boolean firstBool = (aDouble == solution1.aDouble);
boolean secondBool = (anInt == solution1.anInt);
boolean thirdBool = (solution1.date != null && this.date != null && date.equals(solution1.date));
boolean foursBool = (solution1.solution != null && this.solution != null && solution.equals(solution1.solution));
boolean fifthBool = (solution1.string != null && this.string != null && string.equals(solution1.string));
return firstBool && secondBool && thirdBool && foursBool && fifthBool;
}
@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) {
// Date date = new Date();
// System.out.println(new Solution(0, "", 0d, date, null)
// .equals(new Solution(0, "", 0d, date, null)));
}
}