Package java.text

Examples of java.text.RuleBasedCollator


    /*
     * Class under test for int compare(java.lang.String, java.lang.String)
     */
    public void testCompareStringString() throws ParseException {
        String rule = "< c < b < a";
        RuleBasedCollator coll = new RuleBasedCollator(rule);
        assertEquals(-1, coll.compare("c", "a"));
    }
View Full Code Here


        RuleBasedCollator coll = new RuleBasedCollator(rule);
        assertEquals(-1, coll.compare("c", "a"));
    }

    public void testGetCollationKey() {
        RuleBasedCollator coll = (RuleBasedCollator) Collator
                .getInstance(Locale.GERMAN);
        String source = "abc";
        CollationKey key1 = coll.getCollationKey(source);
        assertEquals(source, key1.getSourceString());
        String source2 = "abb";
        CollationKey key2 = coll.getCollationKey(source2);
        assertEquals(source2, key2.getSourceString());
        assertTrue(key1.compareTo(key2) > 0);
        assertTrue(coll.compare(source, source2) > 0);

    }
View Full Code Here

    }

    public void testGetRules() throws ParseException {
        String rule = "< a = b < c";
        RuleBasedCollator coll = new RuleBasedCollator(rule);
        assertEquals(rule, coll.getRules());
    }
View Full Code Here

     * getCollationElementIterator(java.lang.String)
     */
    public void testGetCollationElementIteratorString() throws Exception {
        {
            Locale locale = new Locale("es", "", "TRADITIONAL");
            RuleBasedCollator coll = (RuleBasedCollator) Collator
                    .getInstance(locale);
            String source = "cha";
            CollationElementIterator iterator = coll
                    .getCollationElementIterator(source);
            int[] e_offset = { 0, 2, 3 };
            int offset = iterator.getOffset();
            int i = 0;
            assertEquals(e_offset[i++], offset);
            while (offset != source.length()) {
                iterator.next();
                offset = iterator.getOffset();
                assertEquals(e_offset[i++], offset);
            }
        }

        {
            Locale locale = new Locale("de", "DE");
            RuleBasedCollator coll = (RuleBasedCollator) Collator
                    .getInstance(locale);
            String source = "\u00E6b";
            CollationElementIterator iterator = coll
                    .getCollationElementIterator(source);
            int[] e_offset = { 0, 1, 1, 2 };
            int offset = iterator.getOffset();
            int i = 0;
            assertEquals(e_offset[i++], offset);
            while (offset != source.length()) {
                iterator.next();
                offset = iterator.getOffset();
                assertEquals(e_offset[i++], offset);
            }
        }
        //Regression for HARMONY-1352
        try {
            new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((String)null);
            fail("NullPointerException expected");
        } catch (NullPointerException e) {
            //expected
        }
    }
View Full Code Here

     * getCollationElementIterator(java.text.CharacterIterator)
     */
    public void testGetCollationElementIteratorCharacterIterator() throws Exception {
        {
            Locale locale = new Locale("es", "", "TRADITIONAL");
            RuleBasedCollator coll = (RuleBasedCollator) Collator
                    .getInstance(locale);
            String text = "cha";
            StringCharacterIterator source = new StringCharacterIterator(text);
            CollationElementIterator iterator = coll
                    .getCollationElementIterator(source);
            int[] e_offset = { 0, 2, 3 };
            int offset = iterator.getOffset();
            int i = 0;
            assertEquals(e_offset[i++], offset);
            while (offset != text.length()) {
                iterator.next();
                offset = iterator.getOffset();
                // System.out.println(offset);
                assertEquals(e_offset[i++], offset);
            }
        }

        {
            Locale locale = new Locale("de", "DE");
            RuleBasedCollator coll = (RuleBasedCollator) Collator
                    .getInstance(locale);
            String text = "\u00E6b";
            StringCharacterIterator source = new StringCharacterIterator(text);
            CollationElementIterator iterator = coll
                    .getCollationElementIterator(source);
            int[] e_offset = { 0, 1, 1, 2 };
            int offset = iterator.getOffset();
            int i = 0;
            assertEquals(e_offset[i++], offset);
            while (offset != text.length()) {
                iterator.next();
                offset = iterator.getOffset();
                assertEquals(e_offset[i++], offset);
            }
        }
        //Regression for HARMONY-1352
        try {
            new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((CharacterIterator)null);
            fail("NullPointerException expected");
        } catch (NullPointerException e) {
            //expected
        }
    }
View Full Code Here

            //expected
        }
    }

    public void testStrength() {
        RuleBasedCollator coll = (RuleBasedCollator) Collator
                .getInstance(Locale.US);
        for (int i = 0; i < 4; i++) {
            coll.setStrength(i);
            assertEquals(i, coll.getStrength());
        }

    }
View Full Code Here

        }

    }

    public void testDecomposition() {
        RuleBasedCollator coll = (RuleBasedCollator) Collator
                .getInstance(Locale.US);
        for (int i = 0; i < 2; i++) {
            coll.setDecomposition(i);
            assertEquals(i, coll.getDecomposition());
        }
    }
View Full Code Here

     * @tests java.text.RuleBasedCollator.RuleBasedCollator(java.lang.String)
     */
    public void testNullPointerException() throws Exception {
        //Regression for HARMONY-241
        try {
            new RuleBasedCollator(null);
            fail("Constructor RuleBasedCollator(null) "
                    + "should throw NullPointerException");
        } catch (NullPointerException e) {}
    }
View Full Code Here

     * @tests java.text.RuleBasedCollator.RuleBasedCollator(java.lang.String)
     */
    public void testEmptyStringException() {
        //Regression for HARMONY-241
        try {
            new RuleBasedCollator("");
            fail("Constructor RuleBasedCollator(\"\") "
                    + "should throw ParseException");
        } catch (ParseException e) {
            assertEquals("java.text.ParseException", e.getClass().getName());
            assertEquals(0, e.getErrorOffset());
View Full Code Here

   *
   * The default is DIN 5007-1, this shows how to tailor a collator to get DIN 5007-2 behavior.
   *  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4423383
   */
  public void testCustomRules() throws Exception {
    RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new Locale("de", "DE"));

    String DIN5007_2_tailorings =
      "& ae , a\u0308 & AE , A\u0308"+
      "& oe , o\u0308 & OE , O\u0308"+
      "& ue , u\u0308 & UE , u\u0308";

    RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
    String tailoredRules = tailoredCollator.getRules();
    //
    // at this point, you would save these tailoredRules to a file,
    // and use the custom parameter.
    //
    String germanUmlaut = "Töne";
View Full Code Here

TOP

Related Classes of java.text.RuleBasedCollator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.