how to return Comparator values



Just trying to learn how Comparator works.

Looking at:

import java.util.*;
public class EmpSort {
static final Comparator<Employee> SENIORITY_ORDER =
new Comparator<Employee>() {
public int compare(Employee e1, Employee e2) {
return e2.hireDate().compareTo(e1.hireDate());
}
};

// Employee database
static final Collection<Employee> employees = ... ;

public static void main(String[] args) {
List<Employee>e = new ArrayList<Employee>(employees);
Collections.sort(e, SENIORITY_ORDER);
System.out.println(e);
}
}

http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html

I like the line:

Collections.sort(e, SENIORITY_ORDER); //this will sort the collection
"e" by //SENIORITY_ORDER?

However, how or where is SENIORITY_ORDER ranking defined? I guess
it's in

return e2.hireDate().compareTo(e1.hireDate()); //neg, zero, pos

which returns either a negative, positive or zero. We're only
interested in negative results?

I had a specific question, but sorta answered it while writing it...

anyhow.


-Thufir
.



Relevant Pages

  • Re: Query re ADO.NET, constraints, relations, and cascading updates/deletes
    ... > and I'm running into problems with record deletions. ... > child records relating to the parent (Employee) record I'm ... > Imagine I have a staff of employees, each with zero or more Phone ... > literature that actively requires enormous training can be at best ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Best way to minimize payroll tax
    ... Depending on whether you're an employee or employer: Fire all your ... One can't get lower than ZERO! ...
    (misc.taxes)
  • RE: Adding Hours & Minutes
    ... zero, or just some number that doesn't agree with what you think it should be? ... "Tina" wrote: ... I have formulas in the cells above to calculate the number of hours when an ... employee enters their time. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Number AutoCorrect
    ... the zero is left out an expression will automatically enter it? ... and grab the four rightmost characters. ... msgbox "You forgot to enter an Employee Number" ...
    (microsoft.public.access.forms)
  • RE: How to I Start with C# Generics?
    ... > public Employee(int anId, string aName) ... > public int Id ... > public class GenericReferenceArrayListTest { ... > foreach (Employee e in employees) ...
    (microsoft.public.dotnet.languages.csharp)