public int compare(WorkEntity work1, WorkEntity work2) { if (work2 == null) { throw new NullPointerException("Can't compare with null"); } // Negate the result (Multiply it by -1) to reverse the order. int comparison = work1.comparePublicationDate(work2) * -1; if (comparison == 0) { comparison = work1.compareTitles(work2); if (comparison == 0) { return work1.compareIds(work2); } } return comparison; }