• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparable

 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems that I still dont understand this, look at this example:

// Here is a class where i try to sort a list of Beans

The amounts before and after looks like this:

-14,45
123
243,54
776,33

The confused Frank !


[ June 09, 2004: Message edited by: Carl Trusiak ]
 
Frank Jacobsen
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will do it a litte bit simpler:


public class HistSortBeloebComparator implements Comparator {

/**
* @see Comparator#compare(Object, Object)
*/

public int compare(Object element0, Object element1) {

System.out.println("FJA er i HistSortBeloebComparator1");

return sammenlign(element0, element1);
}

private static int sammenlign(Object element0, Object element1) {

HistoriskViewbean hvbA = (HistoriskViewbean) element0;

HistoriskViewbean hvbB = (HistoriskViewbean) element1;

double beloebA = Double.parseDouble(hvbA.getBeloeb().trim());
double beloebB = Double.parseDouble(hvbB.getBeloeb().trim());

if (beloebA < beloebB) return -1;

if (beloebA > beloebB) return 1;

return 0;

}

}

I have + and - ammounts, but it dont sort the amount in the right order !

Help Frank
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are sorted by the logic you have, apparently they are in the correct order already. Try this for a quick test, shift the returns for a reverse order and run it.

Instead of

Try

Is the ordering different now?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic