package cn.edu.bjut.chapter6; public class Name2 implements Comparable { private String firstName, lastName; public Name2(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } @Override public String toString() { return "[" + lastName + ", " + firstName + "]"; } @Override public boolean equals(Object obj) { if ((obj == null) || !(obj instanceof Name2)) { return false; } if (this == obj) { return true; } Name2 other = (Name2) obj; return (firstName.equalsIgnoreCase(other.firstName) && lastName.equalsIgnoreCase(other.lastName)); } @Override public int hashCode() { return (firstName.toLowerCase().hashCode() * 10 + lastName.toLowerCase().hashCode()); } @Override public int compareTo(Name2 name) { if (!lastName.equalsIgnoreCase(name.lastName)) { return lastName.compareTo(name.lastName); } else { return firstName.compareTo(name.firstName); } } }