Skip to content

Commit

Permalink
SAK-40975 - Roster - User names sorting order doesn't respect whitesp…
Browse files Browse the repository at this point in the history
…aces
  • Loading branch information
danielmerino authored and Miguel Pellicer committed Nov 26, 2018
1 parent f8a235c commit 861eed0
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

import java.util.Comparator;
import java.text.Collator;
import java.text.ParseException;
import java.text.RuleBasedCollator;

import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
Expand All @@ -49,7 +51,7 @@
@Slf4j
public class RosterMemberComparator implements Comparator<RosterMember> {
private final boolean firstNameLastName;
private final Collator collator = Collator.getInstance();
private final RuleBasedCollator collator_ini = (RuleBasedCollator)Collator.getInstance();

/**
* Compares two <code>RosterMember</code> objects according to the sorting
Expand All @@ -58,11 +60,16 @@ public class RosterMemberComparator implements Comparator<RosterMember> {
* @see java.text.Collator#compare(java.lang.String, java.lang.String)
*/
public int compare(RosterMember member1, RosterMember member2) {

if (firstNameLastName) {
return collator.compare (member1.getDisplayName(),member2.getDisplayName());
} else {
return collator.compare (member1.getSortName(),member2.getSortName());
}
try{
RuleBasedCollator collator= new RuleBasedCollator(collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
if (firstNameLastName) {
return collator.compare (member1.getDisplayName(),member2.getDisplayName());
} else {
return collator.compare (member1.getSortName(),member2.getSortName());
}
} catch (ParseException e) {
log.error("ERROR: EnrollmentTableBean had an issue parsing users: " + member1.getSortName() + " and " + member2.getSortName(),e);
}
return Collator.getInstance().compare(member1.getSortName(),member2.getSortName());
}
}

0 comments on commit 861eed0

Please sign in to comment.