class ProviderByPersonNameComparator implements Comparator<Provider>, Serializable {

	@Override
	public int compare(Provider provider1, Provider provider2) {
		
		// test for null cases (sorting them to be last in a list)
		boolean provider1IsNull = (provider1 == null || provider1.getPerson() == null);
		boolean provider2IsNull = (provider2 == null || provider2.getPerson() == null);
		
		if (provider1IsNull && provider2IsNull) {
			return 0;
		} else if (provider1IsNull) {
			return 1;
		} else if (provider2IsNull) {
			return -1;
		}
		
		// delegate to the person by name comparator
		return new PersonByNameComparator().compare(provider1.getPerson(), provider2.getPerson());
	}

}