package com.oreilly.jent.people;

import java.util.Comparator;


/**
 * A comparator that allows a collection of Person beans to be sorted
 * according to last name, first name.
 * 
 * @author Jim Farley
 */
public class PersonSorter implements Comparator {
    public PersonSorter() {}
    public int compare(Object o1, Object o2) {
        Person p1 = (Person)o1;
        Person p2 = (Person)o2;
        int ncomp = p1.getLastName().compareTo(p2.getLastName());
        // If the last names are equal, check the first names
        if (ncomp == 0) {
            ncomp = p1.getFirstName().compareTo(p2.getFirstName());
        }
        return ncomp;
    }
}
