int (final OptionDescription o) { String hit1 = StringUtil.notNullize(myHit); String hit2 = StringUtil.notNullize(o.getHit()); int diff = hit1.compareTo(hit2); if (diff != 0) return diff; String option1 = myOption; String option2 = o.getOption(); if (option1 != null && option2 != null) { return option1.compareTo(option2); } else if (option1 != null || option2 != null) { return option1 == null ? 1 : -1; // nulls go last } else { return 0; } }