Example usage for java.text Collator PRIMARY

List of usage examples for java.text Collator PRIMARY

Introduction

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

Prototype

int PRIMARY

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

Click Source Link

Document

Collator strength value.

Usage

From source file:Main.java

public static void main(String[] args) {
    Collator collator = Collator.getInstance(Locale.FRENCH);
    collator.setStrength(Collator.PRIMARY);

    if (collator.compare("d?b?rqu?r", "debarquer") == 0) {
        System.out.println("Both Strings are equal");
    } else {//from  ww w .j  a  v  a2s.  c om
        System.out.println("Both Strings are not equal");
    }
}

From source file:IgnoreCaseComp.java

IgnoreCaseComp() {
    col = Collator.getInstance();

    col.setStrength(Collator.PRIMARY);
}

From source file:org.sakaiproject.gradebookng.business.LastNameComparator.java

@Override
public int compare(final User u1, final User u2) {
    this.collator.setStrength(Collator.PRIMARY);
    return new CompareToBuilder().append(u1.getLastName(), u2.getLastName(), this.collator)
            .append(u1.getFirstName(), u2.getFirstName(), this.collator).toComparison();
}

From source file:org.sakaiproject.gradebookng.business.FirstNameComparator.java

@Override
public int compare(final User u1, final User u2) {
    this.collator.setStrength(Collator.PRIMARY);
    return new CompareToBuilder().append(u1.getFirstName(), u2.getFirstName(), this.collator)
            .append(u1.getLastName(), u2.getLastName(), this.collator).toComparison();
}

From source file:org.sakaiproject.gradebookng.business.FirstNameComparatorGbUser.java

@Override
public int compare(final GbUser u1, final GbUser u2) {
    this.collator.setStrength(Collator.PRIMARY);
    return new CompareToBuilder().append(u1.getFirstName(), u2.getFirstName(), this.collator)
            .append(u1.getLastName(), u2.getLastName(), this.collator).toComparison();
}

From source file:org.trnltk.apps.experiments.TurkishCollatorPerformanceTest.java

@Test
@Ignore/*  w  ww  . j a  v a2s  . co m*/
public void testCollatorPerformance() {
    final Collator collator = Collator.getInstance(Constants.TURKISH_LOCALE);
    collator.setStrength(Collator.PRIMARY);

    List<String> biggerList = getList();

    System.out.println("Entry count : " + biggerList.size());

    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Collections.sort(biggerList);
    stopWatch.stop();
    System.out.println("w/o collator, it took " + stopWatch.toString());

    biggerList = getList();
    stopWatch.reset();
    stopWatch.start();
    Collections.sort(biggerList, collator);
    stopWatch.stop();
    System.out.println("w/ collator, it took " + stopWatch.toString());

}

From source file:reportestrimestrales.Vitales.java

public Vitales(String titulo, String trimestre, String pYear, String rutaCSV) {
    super(titulo, trimestre, pYear);
    capitulos = new ArrayList();
    introCapitulos = new ArrayList();
    this.rutaCSV = rutaCSV;
    rr = new SesionR();
    comparador.setStrength(Collator.PRIMARY);
    formatoSerie = "Serie histrica " + (int) (Double.parseDouble(getAnioPublicacion()) - 2) + "-"
            + getAnioPublicacion();//from w ww . j  a  v  a 2  s .  c  o m

    cargarCSV(rutaCSV);
    setCapitulos();
    setIntroCapitulos();
}

From source file:StringComparable.java

public int compareTo(Object o) {
    final String pattern = ((StringComparable) o).toString();
    if (m_text.equals(pattern)) {//Code-point equals 
        return 0;
    }// www . j  ava  2  s  . com
    final int savedStrength = m_collator.getStrength();
    int comp = 0;
    // Is there difference more significant than case-order?     
    if (((savedStrength == Collator.PRIMARY) || (savedStrength == Collator.SECONDARY))) {
        comp = m_collator.compare(m_text, pattern);
    } else {// more than SECONDARY
        m_collator.setStrength(Collator.SECONDARY);
        comp = m_collator.compare(m_text, pattern);
        m_collator.setStrength(savedStrength);
    }
    if (comp != 0) {//Difference more significant than case-order 
        return comp;
    }

    // No difference more significant than case-order.     
    // Find case difference
    comp = getCaseDiff(m_text, pattern);
    if (comp != 0) {
        return comp;
    } else {// No case differences. Less significant difference could exist 
        return m_collator.compare(m_text, pattern);
    }
}

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 {/* w ww  .j ava 2s  .  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.phoenix.expression.function.CollationKeyFunctionTest.java

@Test
public void testEqualCollationKeysForPrimaryStrength() throws Exception {
    // "a", "A", "" are considered equivalent
    testCollationKeysEqual(new String[] { "a", "A", "" }, "en", Boolean.FALSE, Collator.PRIMARY, null);
    testSortOrderNoEquals(new String[] { "b", "a" }, "en", Boolean.FALSE, Collator.PRIMARY, null,
            new Integer[] { 1, 0 });

}