Example usage for java.text Collator FULL_DECOMPOSITION

List of usage examples for java.text Collator FULL_DECOMPOSITION

Introduction

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

Prototype

int FULL_DECOMPOSITION

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

Click Source Link

Document

Decomposition mode value.

Usage

From source file:Decomposition.java

public void compare(Collator c, String a, String b) {
    switch (c.getDecomposition()) {
    case Collator.NO_DECOMPOSITION:
        System.out.print(" NO DECOMPOSITION: ");
        break;//from  w  w w  . ja  v  a  2  s . com
    case Collator.CANONICAL_DECOMPOSITION:
        System.out.print(" CANONICAL DECOMPOSITION: ");
        break;
    case Collator.FULL_DECOMPOSITION:
        System.out.print(" FULL DECOMPOSITION: ");
        break;
    default:
        System.out.print(" UNKNOWN DECOMPOSITION: ");
    }

    if (c.equals(a, b))
        System.out.println("The strings are equal.");
    else
        System.out.println("The strings are NOT equal.");
}

From source file:Decomposition.java

public Decomposition() {
    String pairs[][] = new String[3][3];
    pairs[0][0] = "Half-Width and full-width A";
    pairs[0][1] = "A";
    pairs[0][2] = "\uFF21"; // full-width A
    pairs[1][0] = "A with Ring and Angstrom Sign";
    pairs[1][1] = "\u00c5"; // A with ring
    pairs[1][2] = "\u212b"; // Angstrom
    pairs[2][0] = "a + umlaut and precomposed a-umlaut";
    pairs[2][1] = "a\u0308";
    pairs[2][2] = "\u00e4";

    for (int i = 0; i < 3; i++) {
        Collator collate = Collator.getInstance(Locale.US);
        collate.setStrength(Collator.IDENTICAL);

        System.out.println("Comparing " + pairs[i][0]);
        collate.setDecomposition(Collator.NO_DECOMPOSITION);
        compare(collate, pairs[i][1], pairs[i][2]);

        collate.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
        compare(collate, pairs[i][1], pairs[i][2]);

        collate.setDecomposition(Collator.FULL_DECOMPOSITION);
        compare(collate, pairs[i][1], pairs[i][2]);
        System.out.println("");
    }/*  w w w  .java  2s  . c  o  m*/
}

From source file:com.evolveum.midpoint.web.component.prism.ContainerValueWrapper.java

public void sort() {
    Locale locale = WebModelServiceUtils.getLocale();
    if (locale == null) {
        locale = Locale.getDefault();
    }/*from  w ww . jav  a2 s.c  o m*/
    Collator collator = Collator.getInstance(locale);
    if (isSorted()) {
        collator.setStrength(Collator.SECONDARY); // e.g. "a" should be different from ""
        collator.setDecomposition(Collator.FULL_DECOMPOSITION); // slower but more precise

        Collections.sort(properties, new Comparator<ItemWrapper>() {
            @Override
            public int compare(ItemWrapper pw1, ItemWrapper pw2) {

                if (pw1 instanceof ContainerWrapper) {
                    ((ContainerWrapper) pw1).sort();
                }

                if (pw2 instanceof ContainerWrapper) {
                    ((ContainerWrapper) pw2).sort();
                }

                if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw1.getClass())
                        && pw2 instanceof ContainerWrapper) {
                    return -1;
                }

                if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw2.getClass())
                        && pw1 instanceof ContainerWrapper) {
                    return 1;
                }
                //               
                return compareByDisplayNames(pw1, pw2, collator);
            }
        });
    } else {
        Collections.sort(properties, new Comparator<ItemWrapper>() {
            @Override
            public int compare(ItemWrapper pw1, ItemWrapper pw2) {

                if (pw1 instanceof ContainerWrapper) {
                    ((ContainerWrapper) pw1).sort();
                }

                if (pw2 instanceof ContainerWrapper) {
                    ((ContainerWrapper) pw2).sort();
                }

                if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw1.getClass())
                        && pw2 instanceof ContainerWrapper) {
                    return -1;
                }

                if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw2.getClass())
                        && pw1 instanceof ContainerWrapper) {
                    return 1;
                }

                ItemDefinition id1 = pw1.getItemDefinition();
                ItemDefinition id2 = pw2.getItemDefinition();

                int displayOrder1 = (id1 == null || id1.getDisplayOrder() == null) ? Integer.MAX_VALUE
                        : id1.getDisplayOrder();
                int displayOrder2 = (id2 == null || id2.getDisplayOrder() == null) ? Integer.MAX_VALUE
                        : id2.getDisplayOrder();
                if (displayOrder1 == displayOrder2) {
                    return compareByDisplayNames(pw1, pw2, collator);
                } else {
                    return Integer.compare(displayOrder1, displayOrder2);
                }
            }
        });
    }

}

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

/**
 * Just test that changing the decomposition mode works for basic sorting.
 * TODO: Actually test for the accented characters and languages where this
 * actually matters.//  ww  w.  ja va2s .  c  o  m
 */
@Test
public void testCollationKeyBytesForFullDecomposition() throws Exception {
    testCollationKeysEqual(new String[] { "a", "A" }, "en", Boolean.FALSE, null, Collator.FULL_DECOMPOSITION);
}

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.com*/
        // 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
 *//*from w w  w .ja va  2s. c  o  m*/
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);
}