Example usage for java.text RuleBasedCollator compare

List of usage examples for java.text RuleBasedCollator compare

Introduction

In this page you can find the example usage for java.text RuleBasedCollator compare.

Prototype

public synchronized int compare(String source, String target) 

Source Link

Document

Compares the character data stored in two different strings based on the collation rules.

Usage

From source file:org.sakaiproject.component.app.roster.RosterManagerImpl.java

private Comparator<Group> sortGroups() {
    Comparator<Group> groupComparator = new Comparator<Group>() {
        public int compare(Group one, Group another) {
            try {
                RuleBasedCollator r_collator = new RuleBasedCollator(
                        ((RuleBasedCollator) Collator.getInstance()).getRules().replaceAll("<'\u005f'",
                                "<' '<'\u005f'"));
                return r_collator.compare(one.getTitle(), another.getTitle());
            } catch (ParseException e) {
                return Collator.getInstance().compare(one.getTitle(), another.getTitle());
            }//from   w w w.ja  v  a  2  s.c  o  m
        }
    };
    return groupComparator;
}

From source file:org.sakaiproject.tool.assessment.util.BeanSortComparator.java

private int subCompare(String s1, String s2) {
    //we do not want to use null values for sorting
    if (s1 == null) {
        s1 = "";//from w  ww  .  j  av a2  s  .  co m
    }

    if (s2 == null) {
        s2 = "";
    }

    // Deal with n/a case
    if (s1.toLowerCase().startsWith("n/a") && !s2.toLowerCase().startsWith("n/a"))
        return 1;

    if (s2.toLowerCase().startsWith("n/a") && !s1.toLowerCase().startsWith("n/a"))
        return -1;

    String finalS1 = s1.replaceAll("<.*?>", "");
    String finalS2 = s2.replaceAll("<.*?>", "");
    RuleBasedCollator collator_ini = (RuleBasedCollator) Collator.getInstance();
    try {
        RuleBasedCollator collator = new RuleBasedCollator(
                collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
        return collator.compare(finalS1.toLowerCase(), finalS2.toLowerCase());
    } catch (ParseException e) {
    }
    return Collator.getInstance().compare(finalS1.toLowerCase(), finalS2.toLowerCase());
}

From source file:org.sakaiproject.tool.roster.RosterGroupMembership.java

private Comparator<GroupedParticipants> sortByGroup() {
    Comparator<GroupedParticipants> groupComparator = new Comparator<GroupedParticipants>() {
        public int compare(GroupedParticipants one, GroupedParticipants another) {
            try {
                RuleBasedCollator r_collator = new RuleBasedCollator(
                        ((RuleBasedCollator) Collator.getInstance()).getRules().replaceAll("<'\u005f'",
                                "<' '<'\u005f'"));
                return r_collator.compare(one.getGroupTitle(), another.getGroupTitle());
            } catch (ParseException e) {
                return Collator.getInstance().compare(one.getGroupTitle(), another.getGroupTitle());
            }//from  ww  w. java2s  .  c  o  m
        }
    };
    return groupComparator;
}