Package java.text

Examples of java.text.RuleBasedCollator$CollationElement


  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


        doTest(comp);
    }


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

  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

      {"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

  {"pqr", "xyz", "<"},
      },
    };

    try {
      RuleBasedCollator r = new RuleBasedCollator(TEST_RULES);
      for (int i = 0; i < TESTS.length; i++) {
  r.setStrength(i);
  doComparisons(r, TESTS[i]);
      }
    }
    catch (ParseException ex) {
      harness.debug(ex);
View Full Code Here

  {"chat", "dog", "<"},
      },
    };
   
    try {
      RuleBasedCollator r = new RuleBasedCollator(OLD_SPANISH_RULES);
      for (int i = 0; i < TESTS.length; i++) {
  r.setStrength(i);
  doComparisons(r, TESTS[i]);
      }
    }
    catch (ParseException ex) {
      harness.debug(ex);
View Full Code Here

  {"C\u00c6T", "CAB", ">"},
      },
    };
   
    try {
      RuleBasedCollator r = new RuleBasedCollator(OLD_ENGLISH_RULES);
      for (int i = 0; i < TESTS.length; i++) {
  r.setStrength(i);
  doComparisons(r, TESTS[i]);
      }
    }
    catch (ParseException ex) {
      harness.debug(ex);
View Full Code Here

    String SimpleRule = "< a< b< c< d";
   
    boolean pass = false;
    try
      {
        RuleBasedCollator simpleRuleCollator =
          new RuleBasedCollator(SimpleRule);
       
        pass = (simpleRuleCollator.compare("abc", "ABC") < 0);
      }
    catch (ParseException e)
      {
        pass = false;
      }
View Full Code Here

    this.harness.check(pass, "simple rule test");
  }
 
  private void orderComparision()
  {
    RuleBasedCollator c = (RuleBasedCollator)Collator.getInstance(Locale.US);
    CollationElementIterator iter = c.getCollationElementIterator("Foo");

    // given by the 1.5.0 jdk
    int [][] results =
      {
       {5767169, 88, 0, 1},
View Full Code Here

      // Used to get the collator as above, but this assumes that the
      // en_US locale's collation rules are reasonably complete.
      // Since the point of this class is test the iterator, it is
      // better to use a collator with hard-wired collation rules of
      // known quality.
      RuleBasedCollator en_USCollator =
        new RuleBasedCollator(JDK_1_4_EN_US_RULES);

      CollationElementIterator iterator =
        en_USCollator.getCollationElementIterator("abcdefg");

      // -------- methods --------
      checkOrder(iterator, 7, PRIMARY, "initial test");

      // reset()
      harness.checkPoint("reset()");
      iterator.reset();
      checkOrder(iterator, 7, PRIMARY, "initial test after reset()");

      // ------- check empty string --------
      iterator = en_USCollator.getCollationElementIterator("");
      harness.check (iterator.next(), CollationElementIterator.NULLORDER,
         "next()");

      // ------- detailed checks of collation orders -------
      for (int i = 0; i < TEST_STRINGS.length; i++) {
  iterator = en_USCollator.getCollationElementIterator(TEST_STRINGS[i]);
  checkOrder(iterator, TEST_STRINGS[i].length(), TEST_ORDERS[i],
       "test string #" + i);
      }

      // ------- detailed checks of collation equivalences -------
View Full Code Here

TOP

Related Classes of java.text.RuleBasedCollator$CollationElement

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.