public class Address implements Comparable{
    private int streetNumber;
    private String street;
    private String city;
    private int postCode;
    private String country;

    public Address(int streetNumber, String street, String city,
                   int postCode, String country) {
        this.streetNumber = streetNumber;
        this.street = street;
        this.city = city;
        this.postCode = postCode;
        this.country = country;
    }

    private String getCity() {
        return this.city;
    }

    private String getCountry() {
        return this.country;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;

        Address other = (Address) obj;
        if (city == null) {
            if (other.city != null) {return false;}
        } else if (!city.equals(other.city)) {return false;}
        if (country == null) {
            if (other.country != null) {return false;}
        } else if (!country.equals(other.country)) {return false;}
        if (postCode != other.postCode) {return false;}
        if (street == null) {
            if (other.street != null) {return false;}
        } else if (!street.equals(other.street)) {return false;}
        if (streetNumber != other.streetNumber) {return false;}
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((city == null) ? 0 :
                city.hashCode());
        result = prime * result + ((country == null) ? 0 :
                country.hashCode());
        result = prime * result + postCode;
        result = prime * result + ((street == null) ? 0 :
                street.hashCode());
        result = prime * result + streetNumber;
        return result;
    }

    @Override
    public int compareTo(Object o) {
        if (o instanceof Address) {
            Address other = (Address)o;
            return country.compareTo(other.getCountry());
        } else {
            return 0;
        }
    }

    @Override
    public String toString() {
        return streetNumber + " " + street + ", " +
                city + ", " + country + "\n";
    }
}

public class Person implements Comparable{
    String firstName;
    String lastName;

    public Person(String firstName, String lastName ) {
        this.firstName = firstName;
        this.lastName = lastName;
    }
    @Override
    public String toString() {
        return "Person [firstName=" + firstName +
                ", lastName=" + lastName + "]";
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result +
                ((firstName == null) ? 0 : firstName.hashCode());
        result = prime * result +
                ((lastName == null) ? 0 : lastName.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {return true;}
        if (obj == null) {return false;}
        if (getClass() != obj.getClass()) {return false;}

        Person other = (Person) obj;
        if (firstName == null) {
            if (other.firstName != null) {return false;}
        } else if (!firstName.equals(other.firstName)) {
            return false;
        }
        if (lastName == null) {
            if (other.lastName != null) {return false;}
        } else if (!lastName.equals(other.lastName)) {
            return false;
        }
        return true;
    }
    @Override
    public int compareTo(Object o) {
        if (o instanceof Person) {
            Person other = (Person) o;
            return lastName.compareTo(other.lastName);
        } else {
            return 0;
        }
    }
}

public class HashMapMain {
    public static void main(String[] args) {
        HashMap<String, String> names = new HashMap<>();
        names.put("Stephen", "Hole");
        names.put("Tim", "Bashford");
        names.put("Mike", "Dacey");
        System.out.println(names);
        System.out.println("The Hash Key for Stephen Hole is: " + names.get("Stephen"));

        Map people = new HashMap();
        people.put("Stephen", "Hole");
        people.put("Tim", "Bashford");
        people.put("Gary", "Williams");
        System.out.println("The Hash Key for Gary Williams is: " + people.get("Gary"));

        Address a1 = new Address(24, "Woodlands", "Swansea", 234, "Wales");
        Address a2 = new Address(214, "Cecil Road", "London", 104, "England");
        Address a3 = new Address(98, "Islwyn Road", "Glasgow", 834, "Scotland");

        Person p1 = new Person("Andrew", "Myles");
        Person p2 = new Person("Eifion", "Singh");
        Person p3 = new Person("William", "Davies");

        Map staff = new HashMap();
        staff.put(p1, a3);
        staff.put(p2, a1);
        staff.put(p3, a2);
        System.out.println("Andrew lives at " + staff.get(p1) );
        // Change address for Andrew
        staff.put(p1, a2);
        System.out.println("Andrew now lives at " + staff.get(p1) );
    }
}
