package com.javarush.task.task21.task2106; import java.util.Date; /* ÐÑибка в equals/hashCode ÐÑпÑавÑÑе оÑибки ÑеализаÑий меÑодов equals и hashCode Ð´Ð»Ñ ÐºÐ»Ð°ÑÑа Solution. ТÑебованиÑ: 1.âХеÑÐºÐ¾Ð´Ñ Ð¾Ð´Ð¸Ð½Ð°ÐºÐ¾Ð²ÑÑ Ð¾Ð±ÑекÑов Ð´Ð¾Ð»Ð¶Ð½Ñ Ð±ÑÑÑ ÑавнÑ. 2.âÐеÑод equals должен пÑовеÑÑÑÑ Ñавен ли пеÑеданнÑй обÑÐµÐºÑ Ñавен ÑекÑÑÐµÐ¼Ñ (ÑÑавнение ÑеÑез ==). 3.âÐеÑод equals должен пÑовеÑÑÑÑ ÑвлÑеÑÑÑ Ð»Ð¸ пеÑеданнÑй обÑÐµÐºÑ Ð¾Ð±ÑекÑом клаÑÑа Solution. 4.âÐеÑод equals должен пÑовеÑÑÑÑ Ð·Ð½Ð°ÑÐµÐ½Ð¸Ñ Ð²ÑÐµÑ Ð¿Ð¾Ð»ÐµÐ¹ Ñ Ð¿ÐµÑеданного обÑекÑа и ÑекÑÑего (ÑÑÑи ÑÑо некоÑоÑÑе из Ð½Ð¸Ñ Ð¼Ð¾Ð³ÑÑ Ð±ÑÑÑ ÑÐ°Ð²Ð½Ñ null). 5.âÐолжно бÑÑÑ Ð¾Ð±ÐµÑпеÑено коÑÑекÑное поведение HashSet Ñ Ñипом ÑлеменÑов Solution. 6.âРклаÑÑе Solution должен бÑÑÑ Ñеализован меÑод 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 == null || getClass() != o.getClass()) return false; Solution solution1 = (Solution) o; if (anInt != solution1.anInt) return false; if (Double.compare(solution1.aDouble, aDouble) != 0) return false; if (string != null ? !string.equals(solution1.string) : solution1.string != null) return false; if (date != null ? !date.equals(solution1.date) : solution1.date != null) return false; return solution != null ? solution.equals(solution1.solution) : solution1.solution == null; } @Override public int hashCode() { int result; long temp; result = anInt; result = 31 * result + (string != null ? string.hashCode() : 0); temp = Double.doubleToLongBits(aDouble); 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; } public static void main(String[] args) { } }