Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6373053

[Coll] Doc: RuleBasedCollator API doc shouldn't assume the Collator.getInstance return type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 1.1
    • core-libs
    • b76
    • generic
    • generic

      The following code samples cast the return value from the Collator factory to RuleBasedCollator. However, it's not the factory method spec to return a RuleBasedCollator.
       
      // Create an en_US Collator object
       RuleBasedCollator en_USCollator = (RuleBasedCollator)
           Collator.getInstance(new Locale("en", "US", ""));
       // Create a da_DK Collator object
       RuleBasedCollator da_DKCollator = (RuleBasedCollator)
           Collator.getInstance(new Locale("da", "DK", ""));
       // Combine the two
       // First, get the collation rules from en_USCollator
       String en_USRules = en_USCollator.getRules();
       // Second, get the collation rules from da_DKCollator
       String da_DKRules = da_DKCollator.getRules();
       RuleBasedCollator newCollator =
           new RuleBasedCollator(en_USRules + da_DKRules);
       // newCollator has the combined rules


       // get en_US Collator rules
       RuleBasedCollator en_USCollator = (RuleBasedCollator)Collator.getInstance(Locale.US);
       // add a few Japanese character to sort before English characters
       // suppose the last character before the first base letter 'a' in
       // the English collation rule is \u2212
       String jaString = "& \u2212 < \u3041, \u3042 < \u3043, \u3044";
       RuleBasedCollator myJapaneseCollator = new
           RuleBasedCollator(en_USCollator.getRules() + jaString);

            okutsu Masayoshi Okutsu
            okutsu Masayoshi Okutsu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: