package ru.matevosyan;

import java.util.Calendar;

/**
 * OverrideHashcodeUser class.
 * Created on 07.05.2017.
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class OverrideHashcodeUser {


    private String name;
    private int children;
    private Calendar birthday;

    /**
     * Constructor.
     */

    public OverrideHashcodeUser(String name, int children, Calendar birthday) {
        this.name = name;
        this.children = children;
        this.birthday = birthday;
    }

//    @Override
//    public boolean equals(Object o) {
//        if (this == o) {
//            return true;
//        }
//        if (o == null || this.getClass() != o.getClass()) {
//            return false;
//        }
//
//        OverrideHashcodeUser that = (OverrideHashcodeUser) o;
//
//        if (this.name != null ? !this.name.equals(that.name) : that.name != null) {
//            return false;
//        }
//        if (this.children != that.children) {
//            return false;
//        }
//        return  birthday != null ? birthday.equals(that.birthday) : that.birthday == null;
//    }

    @Override
    public int hashCode() {
        int code = 17;
        int result = code * 31 * (this.name != null ? this.name.hashCode() : 0) + children;
        result = result * code * 31 + (this.birthday != null ? this.birthday.hashCode() : 0);
        return result;
    }

}
package ru.matevosyan;

import java.util.Calendar;

/**
 * OverrideHashcodeUser class.
 * Created on 07.05.2017.
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class OverrideHashcodeUser {


    private final String name;
    private final int children;
    private final Calendar birthday;

    /**
     * Constructor.
     */

    public OverrideHashcodeUser(String name, int children, Calendar birthday) {
        this.name = name;
        this.children = children;
        this.birthday = birthday;
    }


    @Override
    public int hashCode() {
        int code = 17;
        int result = code * 31 * (this.name != null ? this.name.hashCode() : 0) + children;
        result = result * code * 31 + (this.birthday != null ? this.birthday.hashCode() : 0);
        return result;
    }

}
change variable to final