Examples of RuleBasedCollator


Examples of java.text.RuleBasedCollator

     * 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

Examples of java.text.RuleBasedCollator

            //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

Examples of java.text.RuleBasedCollator

        }

    }

    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

Examples of java.text.RuleBasedCollator

     * @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

Examples of java.text.RuleBasedCollator

     * @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

Examples of java.text.RuleBasedCollator

   *
   * 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

Examples of java.text.RuleBasedCollator

  private Collator createFromRules(String fileName, ResourceLoader loader) throws IOException {
    InputStream input = null;
    try {
     input = loader.openResource(fileName);
     String rules = toUTF8String(input);
     return new RuleBasedCollator(rules);
    } catch (ParseException e) {
      // invalid rules
      throw new IOException("ParseException thrown while parsing rules", e);
    } finally {
      IOUtils.closeWhileHandlingException(input);
View Full Code Here

Examples of java.text.RuleBasedCollator

        doTest(comp);
    }


    public void testRuleComparator() {
        RuleBasedCollator comp = (RuleBasedCollator)RuleBasedCollator.getInstance();
        doTest(comp);
    }
View Full Code Here

Examples of java.text.RuleBasedCollator

  private TestHarness harness;

  private void constructorTests()
  {
    harness.checkPoint("constructor rule parsing");
    RuleBasedCollator r;
    final String[] GOOD_RULES = {
      // Examples from the Sun javadocs
      "< a < b < c < d",
      ("< a,A< b,B< c,C< d,D< e,E< f,F< g,G< h,H< i,I< j,J < k,K< l,L< m,M" +
       "< n,N< o,O< p,P< q,Q< r,R< s,S< t,T < u,U< v,V< w,W< x,X< y,Y< z,Z " +
       "< \u00E5=a\u030A,\u00C5=A\u030A ;aa,AA< \u00E6,\u00C6< \u00F8,\u00D8"),
      ("=\u0301;\u0300;\u0302;\u0308;\u0327;\u0303;\u0304;\u0305" +
       ";\u0306;\u0307;\u0309;\u030A;\u030B;\u030C;\u030D;\u030E" +
       ";\u030F;\u0310;\u0311;\u0312< a , A ; ae, AE ; \u00e6 , \u00c6" +
       "< b , B < c, C < e, E & C < d, D & \u0300 ; \u0308 ; \u0302"),
      // Real collation rules
      EN_US_RULES, FR_CA_RULES,
      // Cases involving non-significant white-space
      "=A ", "=A\t", "=A\n",
      "=A B", "=A\tB", "=A\nB",
      "= A", "=\tA", "=\nA",
      " =A", "\t=A", "\n=A",
      // Dodgy cases that JDKs accept
      " ",
      "='\n''\n'",
      "='\n'\n'\n'",
      // Dodgy cases with unbalanced quotes.  JDKs allow these (though a
      // couple result in IndexOutOfBoundsExceptions).  However, the spec
      // does not say what they mean.
      "='", /* <- JDK 1.4.0 exception */ "=' ", "='=A", "='=A'",
      "=''", "='' ","=''=A", "=''=A'",
      "=''''", /* <- JDK 1.4.0 exception */ "=''''=A", "=''''=A'",
    };
   
    for (int i = 0; i < GOOD_RULES.length; i++) {
      try {
  r = new RuleBasedCollator(GOOD_RULES[i]);
  harness.check(true);
      }
      catch (ParseException ex) {
  harness.debug(ex);
  harness.debug("unexpected ParseException (offset is " +
          ex.getErrorOffset() + ")");
  harness.check(false);
      }
      catch (Throwable ex) {
  harness.debug(ex);
  harness.check(false);
      }
    }

    try {
      r = new RuleBasedCollator(null);
      harness.check(false);
    }
    catch (ParseException ex) {
      harness.check(false);
    }
    catch (NullPointerException ex) {
      harness.check(true);
    }
   
    harness.checkPoint("constructor rule parsing errors");
    final String[] BAD_RULES = {
      // Empty rule list
      "",
      // No relation
      "A",
      // No text following relation
      "=", "<", ";", ",",
      // Special chars should be quoted
      "=\n", "=#", "==",
    };

    for (int i = 0; i < BAD_RULES.length; i++) {
      try {
  r = new RuleBasedCollator(BAD_RULES[i]);
  harness.check(false);
      }
      catch (ParseException ex) {
  harness.check(true);
      }
View Full Code Here

Examples of java.text.RuleBasedCollator

      {"Z", "Z", "="},
      {"Abc", "aZbZc", ">"},
    };

    try {
      RuleBasedCollator r = new RuleBasedCollator(TEST_RULES);
      doComparisons(r, TESTS);
    }
    catch (ParseException ex) {
      harness.debug(ex);
      harness.fail("ignorable characters: ParseException (offset is " +
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.