package map;

import java.util.Calendar;
import java.util.Objects;

/**
 * Created by admin on 24.12.2016.
 */
public class UserWithEqualsAndHash {
    /**
     * Field name of user.
     */
    private String name;
    /**
     * Count of user's children.
     */
    private int children;
    /**
     * User's birthday.
     */
    private Calendar birthday;

    /**
     * Constructor.
     * @param name name
     * @param children cout of children
     * @param birthday birthday
     */
    public UserWithEqualsAndHash(String name, int children, Calendar birthday) {
        this.name = name;
        this.children = children;
        this.birthday = birthday;
    }

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


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof UserWithEqualsAndHash)) {
            return false;
        }
        UserWithEqualsAndHash that = (UserWithEqualsAndHash) o;
        return children == that.children
                && Objects.equals(name, that.name)
                && Objects.equals(birthday, that.birthday);
    }
}
