1
votes

Codename One does not accept primitive types (int), so I'm trying to write the following comparator using Integer:

private static class CelebrityPopularityComparator implements Comparator<Celebrity> {
    @Override
    public int compare(Celebrity celebrity1, Celebrity celebrity2) {
        Integer celebrity1PopularitySum = celebrity1.getCelebrityPopularitySum();
        Integer celebrity2PopularitySum = celebrity2.getCelebrityPopularitySum();
        Integer comparisonResult = Integer.valueOf(celebrity1PopularitySum.compareTo(celebrity2PopularitySum));
        return comparisonResult;
    }
}

I tried many ways and it just won't work. It won't send a build to the server. What can I do to fix it? Thanks!

1

1 Answers

2
votes

Try this:

        Integer celebrity1PopularitySum = celebrity1.getCelebrityPopularitySum();
        Integer celebrity2PopularitySum = celebrity2.getCelebrityPopularitySum();
        if(celebrity1PopularitySum.equals(celebrity2PopularitySum)){
            return 0;
        }else if(celebrity1PopularitySum.intValue() < celebrity2PopularitySum.intValue()){
            return -1;
        }else{
            return 1;
        }