• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Two Level Ascending Sort with Nulls to the Bottom
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Two Level Ascending Sort with Nulls to the Bottom


  • Subject: Two Level Ascending Sort with Nulls to the Bottom
  • From: James Cicenia <email@hidden>
  • Date: Wed, 23 Feb 2005 17:30:46 -0600

OK -

For anyone else who will need something like this I am posting it here. It wasn't pretty
and it was my first NSComparator. (OK PA and the rest, I drank my poison a year ago
and figured I stay with it. Maybe someone will come out with an eclipse converter one
day and make it all pure clear water again). Oh, those fcking nulls.. they always make
thing so much more tedious.


Hold your nose, here it is:

public static NSComparator q1Comparator = new NSComparator() {
public int compare(Object o1, Object o2){
if(((PortfolioProject) o1).assignedProjectManager() == null && ((PortfolioProject) o2).assignedProjectManager() != null){
return 1;
}
if(((PortfolioProject) o1).assignedProjectManager() != null && ((PortfolioProject) o2).assignedProjectManager() == null){
return -1;
}
if(((PortfolioProject) o1).assignedProjectManager() == null && ((PortfolioProject) o2).assignedProjectManager() == null){
NSTimestamp date1 = ((PortfolioProject) o1).currentRolloutDate();
NSTimestamp date2 = ((PortfolioProject) o2).currentRolloutDate();
if(date1==null && date2 !=null){
return 1;
}
if(date1!=null && date2 ==null){
return -1;
}
if(date1==null && date2 ==null){
return 0;
}
return date1.compareTo(date2);
}


if(((PortfolioProject) o1).assignedProjectManager().lastName()==null && ((PortfolioProject) o2).assignedProjectManager().lastName() !=null){
return 1;
}
if(((PortfolioProject) o1).assignedProjectManager().lastName()!=null && ((PortfolioProject) o2).assignedProjectManager().lastName() ==null){
return -1;
}
if(((PortfolioProject) o1).assignedProjectManager().lastName()==null && ((PortfolioProject) o2).assignedProjectManager().lastName() ==null){
return 0;
}

String lastName1 = ((PortfolioProject) o1).assignedProjectManager().lastName().toUpperCase();
String lastName2 = ((PortfolioProject) o2).assignedProjectManager().lastName().toUpperCase();


if (!(lastName1.equals(lastName2))){
return lastName1.compareTo(lastName2);
}else{
if(((PortfolioProject) o1).assignedProjectManager().firstName()==null && ((PortfolioProject) o2).assignedProjectManager().firstName() !=null){
return 1;
}
if(((PortfolioProject) o1).assignedProjectManager().firstName()!=null && ((PortfolioProject) o2).assignedProjectManager().firstName() ==null){
return -1;
}
if(((PortfolioProject) o1).assignedProjectManager().firstName()==null && ((PortfolioProject) o2).assignedProjectManager().firstName() ==null){
return 0;
}

String firstName1 = ((PortfolioProject) o1).assignedProjectManager().firstName().toUpperCase();
String firstName2 = ((PortfolioProject) o2).assignedProjectManager().firstName().toUpperCase();

if(!(firstName1.equals(firstName2)))
return firstName1.compareTo(firstName2);
else{
NSTimestamp date1 = ((PortfolioProject) o1).currentRolloutDate();
NSTimestamp date2 = ((PortfolioProject) o2).currentRolloutDate();
if(date1==null && date2 !=null){
return 1;
}
if(date1!=null && date2 ==null){
return -1;
}
if(date1==null && date2 ==null){
return 0;
}
return date1.compareTo(date2);
}
}
}
};


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Sort Algorithm Question
  • Next by Date: [OT] Design Question : People getting married
  • Previous by thread: Re: eo modeler problem
  • Next by thread: [OT] Design Question : People getting married
  • Index(es):
    • Date
    • Thread