Example usage for java.text Collator TERTIARY

List of usage examples for java.text Collator TERTIARY

Introduction

In this page you can find the example usage for java.text Collator TERTIARY.

Prototype

int TERTIARY

To view the source code for java.text Collator TERTIARY.

Click Source Link

Document

Collator strength value.

Usage

From source file:org.nuxeo.ecm.platform.ui.web.directory.DirectorySelectItemComparator.java

public DirectorySelectItemComparator(String ordering, Boolean caseSensitive, Locale locale) {
    this.ordering = StringUtils.split(ordering, ",");
    this.caseSensitive = caseSensitive;
    if (locale == null) {
        FacesContext context = FacesContext.getCurrentInstance();
        this.locale = context.getViewRoot().getLocale();
    } else {/*from   ww w .  ja  v  a  2  s  .c  o m*/
        this.locale = locale;
    }
    collator = Collator.getInstance(this.locale);
    if (Boolean.TRUE.equals(this.caseSensitive)) {
        collator.setStrength(Collator.TERTIARY); // TERTIARY will make a
                                                 // difference between 'a'
                                                 // and 'A'
    } else {
        collator.setStrength(Collator.SECONDARY);
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.directory.SelectItemComparator.java

public SelectItemComparator(String ordering, Boolean caseSentitive, Locale locale) {
    this.ordering = StringUtils.split(ordering, ",");
    this.caseSensitive = caseSentitive;
    if (locale == null) {
        FacesContext context = FacesContext.getCurrentInstance();
        this.locale = context.getViewRoot().getLocale();
    } else {// ww  w .  j a  va2s  .  c  o m
        this.locale = locale;
    }
    collator = Collator.getInstance(this.locale);
    if (Boolean.TRUE.equals(this.caseSensitive)) {
        collator.setStrength(Collator.TERTIARY); // TERTIARY will make a
                                                 // difference between 'a'
                                                 // and 'A'
    } else {
        collator.setStrength(Collator.SECONDARY);
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.component.SelectItemComparator.java

public SelectItemComparator(String ordering, Boolean caseSentitive, Locale locale) {
    this.ordering = StringUtils.split(ordering, ",");
    caseSensitive = caseSentitive;/*from   w  w  w .j  av a  2 s .  c om*/
    if (locale == null) {
        FacesContext context = FacesContext.getCurrentInstance();
        this.locale = context.getViewRoot().getLocale();
    } else {
        this.locale = locale;
    }
    collator = Collator.getInstance(this.locale);
    if (Boolean.TRUE.equals(caseSensitive)) {
        collator.setStrength(Collator.TERTIARY); // TERTIARY will make a
                                                 // difference between 'a'
                                                 // and 'A'
    } else {
        collator.setStrength(Collator.SECONDARY);
    }
}

From source file:StringComparable.java

private final int getCaseDiff(final String text, final String pattern) {
    final int savedStrength = m_collator.getStrength();
    final int savedDecomposition = m_collator.getDecomposition();
    m_collator.setStrength(Collator.TERTIARY);// not to ignore case  
    m_collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);// corresponds NDF

    final int diff[] = getFirstCaseDiff(text, pattern, m_locale);
    m_collator.setStrength(savedStrength);// restore
    m_collator.setDecomposition(savedDecomposition); //restore
    if (diff != null) {
        if ((m_caseOrder).equals("upper-first")) {
            if (diff[0] == UPPER_CASE) {
                return -1;
            } else {
                return 1;
            }/*from   w w  w  .j  a v  a2  s .  c o  m*/
        } else {// lower-first
            if (diff[0] == LOWER_CASE) {
                return -1;
            } else {
                return 1;
            }
        }
    } else {// No case differences
        return 0;
    }

}

From source file:org.apache.solr.analysis.CollationKeyFilterFactory.java

public void inform(ResourceLoader loader) {
    String custom = args.get("custom");
    String language = args.get("language");
    String country = args.get("country");
    String variant = args.get("variant");
    String strength = args.get("strength");
    String decomposition = args.get("decomposition");

    if (custom == null && language == null)
        throw new SolrException(ErrorCode.SERVER_ERROR, "Either custom or language is required.");

    if (custom != null && (language != null || country != null || variant != null))
        throw new SolrException(ErrorCode.SERVER_ERROR, "Cannot specify both language and custom. "
                + "To tailor rules for a built-in language, see the javadocs for RuleBasedCollator. "
                + "Then save the entire customized ruleset to a file, and use with the custom parameter");

    if (language != null) {
        // create from a system collator, based on Locale.
        collator = createFromLocale(language, country, variant);
    } else {//from w  ww  .j  a  v a  2 s. c  o  m
        // create from a custom ruleset
        collator = createFromRules(custom, loader);
    }

    // set the strength flag, otherwise it will be the default.
    if (strength != null) {
        if (strength.equalsIgnoreCase("primary"))
            collator.setStrength(Collator.PRIMARY);
        else if (strength.equalsIgnoreCase("secondary"))
            collator.setStrength(Collator.SECONDARY);
        else if (strength.equalsIgnoreCase("tertiary"))
            collator.setStrength(Collator.TERTIARY);
        else if (strength.equalsIgnoreCase("identical"))
            collator.setStrength(Collator.IDENTICAL);
        else
            throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid strength: " + strength);
    }

    // set the decomposition flag, otherwise it will be the default.
    if (decomposition != null) {
        if (decomposition.equalsIgnoreCase("no"))
            collator.setDecomposition(Collator.NO_DECOMPOSITION);
        else if (decomposition.equalsIgnoreCase("canonical"))
            collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
        else if (decomposition.equalsIgnoreCase("full"))
            collator.setDecomposition(Collator.FULL_DECOMPOSITION);
        else
            throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid decomposition: " + decomposition);
    }
}

From source file:org.apache.solr.schema.CollationField.java

/**
 * Setup the field according to the provided parameters
 *//* w  w  w . j  a  v  a  2s .c  om*/
private void setup(ResourceLoader loader, Map<String, String> args) {
    String custom = args.remove("custom");
    String language = args.remove("language");
    String country = args.remove("country");
    String variant = args.remove("variant");
    String strength = args.remove("strength");
    String decomposition = args.remove("decomposition");

    final Collator collator;

    if (custom == null && language == null)
        throw new SolrException(ErrorCode.SERVER_ERROR, "Either custom or language is required.");

    if (custom != null && (language != null || country != null || variant != null))
        throw new SolrException(ErrorCode.SERVER_ERROR, "Cannot specify both language and custom. "
                + "To tailor rules for a built-in language, see the javadocs for RuleBasedCollator. "
                + "Then save the entire customized ruleset to a file, and use with the custom parameter");

    if (language != null) {
        // create from a system collator, based on Locale.
        collator = createFromLocale(language, country, variant);
    } else {
        // create from a custom ruleset
        collator = createFromRules(custom, loader);
    }

    // set the strength flag, otherwise it will be the default.
    if (strength != null) {
        if (strength.equalsIgnoreCase("primary"))
            collator.setStrength(Collator.PRIMARY);
        else if (strength.equalsIgnoreCase("secondary"))
            collator.setStrength(Collator.SECONDARY);
        else if (strength.equalsIgnoreCase("tertiary"))
            collator.setStrength(Collator.TERTIARY);
        else if (strength.equalsIgnoreCase("identical"))
            collator.setStrength(Collator.IDENTICAL);
        else
            throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid strength: " + strength);
    }

    // set the decomposition flag, otherwise it will be the default.
    if (decomposition != null) {
        if (decomposition.equalsIgnoreCase("no"))
            collator.setDecomposition(Collator.NO_DECOMPOSITION);
        else if (decomposition.equalsIgnoreCase("canonical"))
            collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
        else if (decomposition.equalsIgnoreCase("full"))
            collator.setDecomposition(Collator.FULL_DECOMPOSITION);
        else
            throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid decomposition: " + decomposition);
    }
    analyzer = new CollationKeyAnalyzer(collator);
}

From source file:org.apache.phoenix.expression.function.CollationKeyFunctionTest.java

@Test
public void testCollationKeyBytesForTertiaryStrength() throws Exception {
    // none of these are considered equivalent
    testSortOrderNoEquals(new String[] { "b", "a", "", "A" }, "en", Boolean.FALSE, Collator.TERTIARY, null,
            new Integer[] { 1, 3, 2, 0 });
}

From source file:de.geeksfactory.opacclient.objects.Library.java

@Override
public int compareTo(Library arg0) {
    Collator deCollator = Collator.getInstance(Locale.GERMAN);
    deCollator.setStrength(Collator.TERTIARY);

    int g = deCollator.compare(country, arg0.getCountry());
    if (g == 0) {
        g = deCollator.compare(state, arg0.getState());
        if (g == 0) {
            g = deCollator.compare(city, arg0.getCity());
            if (g == 0) {
                g = deCollator.compare(title, arg0.getTitle());
            }// w  ww .j  a  v a  2 s  .c o  m
        }
    }
    return g;
}

From source file:org.nuxeo.directory.connector.SuggestDirectoryEntries.java

/**
 * @since 5.9.3//w ww.j  a  va 2  s .co m
 */
protected Collator getCollator() {
    if (collator == null) {
        collator = Collator.getInstance(getLocale());
        if (caseSensitive) {
            collator.setStrength(Collator.TERTIARY);
        } else {
            collator.setStrength(Collator.SECONDARY);
        }
    }
    return collator;
}

From source file:de.baumann.thema.RequestActivity.java

@SuppressWarnings("unchecked")
private void prepareData() // Sort the apps
{
    ArrayList<AppInfo> arrayList = new ArrayList();
    PackageManager pm = getPackageManager();
    Intent intent = new Intent("android.intent.action.MAIN", null);
    intent.addCategory("android.intent.category.LAUNCHER");
    List list = pm.queryIntentActivities(intent, 0);
    Iterator localIterator = list.iterator();
    if (DEBUG)/* ww  w . j av a 2 s  .co  m*/
        Log.v(TAG, "list.size(): " + list.size());

    for (int i = 0; i < list.size(); i++) {
        ResolveInfo resolveInfo = (ResolveInfo) localIterator.next();

        // This is the main part where the already styled apps are sorted out.
        if ((list_activities
                .indexOf(resolveInfo.activityInfo.packageName + "/" + resolveInfo.activityInfo.name) == -1)) {

            AppInfo tempAppInfo = new AppInfo(
                    resolveInfo.activityInfo.packageName + "/" + resolveInfo.activityInfo.name, //Get package/activity
                    resolveInfo.loadLabel(pm).toString(), //Get the app name
                    getHighResIcon(pm, resolveInfo) //Loads xxxhdpi icon, returns normal if it on fail
            //Unselect icon per default
            );
            arrayList.add(tempAppInfo);

            // This is just for debugging
            if (DEBUG)
                Log.i(TAG, "Added app: " + resolveInfo.loadLabel(pm));
        } else {
            // This is just for debugging
            if (DEBUG)
                Log.v(TAG, "Removed app: " + resolveInfo.loadLabel(pm));
        }
    }

    Collections.sort(arrayList, new Comparator<AppInfo>() { //Custom comparator to ensure correct sorting for characters like and apps starting with a small letter like iNex
        @Override
        public int compare(AppInfo object1, AppInfo object2) {
            Locale locale = Locale.getDefault();
            Collator collator = Collator.getInstance(locale);
            collator.setStrength(Collator.TERTIARY);

            if (DEBUG)
                Log.v(TAG, "Comparing \"" + object1.getName() + "\" to \"" + object2.getName() + "\"");

            return collator.compare(object1.getName(), object2.getName());
        }
    });

    list_activities_final = arrayList;
}