public class Person implements Comparable<Person>, Encryptable<Person> {
    private final String firstName;
    private final String lastName;
    Person(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }
    String getFirstName() {
        return firstName;
    }
    String getLastName() {
        return lastName;
    }
    @Override
    public Person encrypt() {
        Person p = new Person(BadEncryption.encryptString(this.firstName),
                              BadEncryption.encryptString(this.lastName));
        return p;
    }
    @Override
    public Person decrypt() {
        Person p = new Person(BadEncryption.decryptString(firstName),
                              BadEncryption.decryptString(lastName));
        return p;
    }
    @Override
    public int compareTo(Person other) {
        return this.toStringForComparable().compareTo(other.toStringForComparable());
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        return (this.compareTo(this.getClass().cast(obj)) == 0);
        // Equivale a (sin tener que poner el nombre de la classe de this):
        // return (this.compareTo((Person) obj) == 0);
    }
    @Override
    public int hashCode() {
        return this.toStringForComparable().hashCode();
    }
    public String toStringForComparable() {
        return (lastName.toLowerCase() + "\t" + firstName.toLowerCase());
    }
    // '\t' = 9, '\n' = '10' ' ' = 32, ',' = 44
    // Si toStringForComparable() esta bien implementado los 3 metodos
    // anteriores funcionaran en cualquie classe sin cambiar nada. :-)
    @Override
    public String toString() {
        return (lastName + ", " + firstName);
    }
}
