<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<!--NewPage-->
<html>
<head>
<!-- Generated by javadoc on Wed Jul 28 01:21:15 GMT 1999 -->
<title>
  Class java.text.RuleBasedCollator
</title>
</head>
<body>
<a name="_top_"></a>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.text.html">This Package</a>  <a href="java.text.ParsePosition.html#_top_">Previous</a>  <a href="java.text.SimpleDateFormat.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
<hr>
<h1>
  Class java.text.RuleBasedCollator
</h1>
<pre>
<a href="java.lang.Object.html#_top_">java.lang.Object</a>
   |
   +----<a href="java.text.Collator.html#_top_">java.text.Collator</a>
           |
           +----java.text.RuleBasedCollator
</pre>
<hr>
<dl>
  <dt> public class <b>RuleBasedCollator</b>
  <dt> extends <a href="java.text.Collator.html#_top_">Collator</a>
</dl>
The <code>RuleBasedCollator</code> class is a concrete subclass of
 <code>Collator</code> that provides a simple, data-driven, table collator.
 With this class you can create a customized table-based <code>Collator</code>.
 <code>RuleBasedCollator</code> maps characters to sort keys.
 <p>
 <code>RuleBasedCollator</code> has the following restrictions
 for efficiency (other subclasses may be used for more complex languages) :
 <ol>
 <li>If a French secondary ordering is specified it applies to the
     whole collator object.
 <li>All non-mentioned Unicode characters are at the end of the
     collation order.
 <li>Private use characters are treated as identical.  The private
     use area in Unicode is <code>0xE800</code>-<code>0xF8FF</code>.
 </ol>
 <p>
 The collation table is composed of a list of collation rules, where each
 rule is of three forms:
 <pre>
    < modifier >
    < relation > < text-argument >
    < reset > < text-argument >
 </pre>
 The following demonstrates how to create your own collation rules:
 <UL Type=round>
    <LI><strong>Text-Argument</strong>: A text-argument is any sequence of
        characters, excluding special characters (that is, whitespace
        characters and the characters used in modifier, relation and reset).
        If those characters are desired, you can put them in single quotes
        (e.g. ampersand => '&').  Note that unquoted white space characters
        are ignored; e.g. <code>b c</code> is treated as <code>bc</code>.
    <LI><strong>Modifier</strong>: There is a single modifier
        which is used to specify that all accents (secondary differences) are
        backwards.
        <p>'@' : Indicates that accents are sorted backwards, as in French.
    <LI><strong>Relation</strong>: The relations are the following:
        <UL Type=square>
            <LI>'<' : Greater, as a letter difference (primary)
            <LI>';' : Greater, as an accent difference (secondary)
            <LI>',' : Greater, as a case difference (tertiary)
            <LI>'=' : Equal
        </UL>
    <LI><strong>Reset</strong>: There is a single reset
        which is used primarily for contractions and expansions, but which
        can also be used to add a modification at the end of a set of rules.
        <p>'&' : Indicates that the next rule follows the position to where
            the reset text-argument would be sorted.
 </UL>
 <p>
 This sounds more complicated than it is in practice. For example, the
 following are equivalent ways of expressing the same thing:
 <blockquote>
 <pre>
 a < b < c
 a < b & b < c
 a < c & a < b
 </pre>
 </blockquote>
 Notice that the order is important, as the subsequent item goes immediately
 after the text-argument. The following are not equivalent:
 <blockquote>
 <pre>
 a < b & a < c
 a < c & a < b
 </pre>
 </blockquote>
 Either the text-argument must already be present in the sequence, or some
 initial substring of the text-argument must be present. (e.g. "a < b & ae <
 e" is valid since "a" is present in the sequence before "ae" is reset). In
 this latter case, "ae" is not entered and treated as a single character;
 instead, "e" is sorted as if it were expanded to two characters: "a"
 followed by an "e". This difference appears in natural languages: in
 traditional Spanish "ch" is treated as though it contracts to a single
 character (expressed as "c < ch < d"), while in traditional German ""
 (a-umlaut) is treated as though it expands to two characters (expressed as
 "a & ae ;  < b").
 <p>
 <strong>Ignorable Characters</strong>
 <p>
 For ignorable characters, the first rule must start with a relation (the
 examples we have used above are really fragments; "a < b" really should be
 "< a < b"). If, however, the first relation is not "<", then all the all
 text-arguments up to the first "<" are ignorable. For example, ", - < a < b"
 makes "-" an ignorable character, as we saw earlier in the word
 "black-birds". In the samples for different languages, you see that most
 accents are ignorable.
 <p><strong>Normalization and Accents</strong>
 <p>
 The <code>Collator</code> object automatically normalizes text internally
 to separate accents from base characters where possible. This is done both when
 processing the rules, and when comparing two strings. <code>Collator</code>
 also uses the Unicode canonical mapping to ensure that combining sequences
 are sorted properly (for more information, see
 <A HREF="http://www.aw.com/devpress">The Unicode Standard, Version 2.0</A>.)</P>
 <p><strong>Errors</strong>
 <p>
 The following are errors:
 <UL Type=round>
     <LI>A text-argument contains unquoted punctuation symbols
        (e.g. "a < b-c < d").
     <LI>A relation or reset character not followed by a text-argument
        (e.g. "a < , b").
     <LI>A reset where the text-argument (or an initial substring of the
         text-argument) is not already in the sequence.
         (e.g. "a < b & e < f")
 </UL>
 If you produce one of these errors, a <code>RuleBasedCollator</code> throws
 a <code>ParseException</code>.
 <p><strong>Examples</strong>
 <p>Simple:     "< a < b < c < d"
 <p>Norwegian:  "< 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
                 < =a?,=A?
                 ;aa,AA< ,< ,"
 <p>
 Normally, to create a rule-based Collator object, you will use
 <code>Collator</code>'s factory method <code>getInstance</code>.
 However, to create a rule-based Collator object with specialized
 rules tailored to your needs, you construct the <code>RuleBasedCollator</code>
 with the rules contained in a <code>String</code> object. For example:
 <blockquote>
 <pre>
 String Simple = "< a < b < c < d";
 RuleBasedCollator mySimple = new RuleBasedCollator(Simple);
 </pre>
 </blockquote>
 Or:
 <blockquote>
 <pre>
 String Norwegian = "< 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" +
                 "< =a?,=A?" +
                 ";aa,AA< ,< ,";
 RuleBasedCollator myNorwegian = new RuleBasedCollator(Norwegian);
 </pre>
 </blockquote>
 <p>
 Combining <code>Collator</code>s is as simple as concatenating strings.
 Here's an example that combines two <code>Collator</code>s from two
 different locales:
 <blockquote>
 <pre>
 // 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
 </pre>
 </blockquote>
 <p>
 Another more interesting example would be to make changes on an existing
 table to create a new <code>Collator</code> object.  For example, add
 "& C < ch, cH, Ch, CH" to the <code>en_USCollator</code> object to create
 your own:
 <blockquote>
 <pre>
 // Create a new Collator object with additional rules
 String addRules = "& C < ch, cH, Ch, CH";
 RuleBasedCollator myCollator =
     new RuleBasedCollator(en_USCollator + addRules);
 // myCollator contains the new rules
 </pre>
 </blockquote>
 <p>
 The following example demonstrates how to change the order of
 non-spacing accents,
 <blockquote>
 <pre>
 // old rule
 String oldRules = "=?;?;?;?"    // main accents
                 + ";?;?;?;?"    // main accents
                 + ";?;?;?;?"    // main accents
                 + ";?;?;?;?"    // main accents
                 + ";?;?;?;?"    // main accents
                 + "< a , A ; ae, AE ;  , "
                 + "< b , B < c, C < e, E & C < d, D";
 // change the order of accent characters
 String addOn = "& ? ; ? ; ?";
 RuleBasedCollator myCollator = new RuleBasedCollator(oldRules + addOn);
 </pre>
 </blockquote>
 <p>
 The last example shows how to put new primary ordering in before the
 default setting. For example, in Japanese <code>Collator</code>, you
 can either sort English characters before or after Japanese characters,
 <blockquote>
 <pre>
 // 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 ?
 String jaString = "& ? < ?, ? < ?, ?";
 RuleBasedCollator myJapaneseCollator = new
     RuleBasedCollator(en_USCollator.getRules() + jaString);
 </pre>
 </blockquote>
<p>
<dl>
    <dt> <b>See Also:</b>
    <dd> <a href="java.text.Collator.html#_top_">Collator</a>, <a href="java.text.CollationElementIterator.html#_top_">CollationElementIterator</a>
</dl>
<hr>
<a name="index"></a>
<h2>
  <img src="images/constructor-index.gif" width=275 height=38 alt="Constructor Index">
</h2>
<dl>
  <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#RuleBasedCollator(java.lang.String)"><b>RuleBasedCollator</b></a>(String)
  <dd>  RuleBasedCollator constructor.
</dl>
<h2>
  <img src="images/method-index.gif" width=207 height=38 alt="Method Index">
</h2>
<dl>
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#clone()"><b>clone</b></a>()
  <dd>  Standard override; no change in semantics.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#compare(java.lang.String, java.lang.String)"><b>compare</b></a>(String, String)
  <dd>  Compares the character data stored in two different strings based on the
 collation rules.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#equals(java.lang.Object)"><b>equals</b></a>(Object)
  <dd>  Compares the equality of two collation objects.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getCollationElementIterator(java.lang.String)"><b>getCollationElementIterator</b></a>(String)
  <dd>  Return a CollationElementIterator for the given String.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getCollationKey(java.lang.String)"><b>getCollationKey</b></a>(String)
  <dd>  Transforms the string into a series of characters that can be compared
 with CollationKey.compareTo.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getRules()"><b>getRules</b></a>()
  <dd>  Gets the table-based rules for the collation object.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#hashCode()"><b>hashCode</b></a>()
  <dd>  Generates the hash code for the table-based collation object

</dl>
<a name="constructors"></a>
<h2>
  <img src="images/constructors.gif" width=231 height=38 alt="Constructors">
</h2>
<a name="RuleBasedCollator"></a>
<a name="RuleBasedCollator(java.lang.String)"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a>
<b>RuleBasedCollator</b>
<pre>
 public RuleBasedCollator(<a href="java.lang.String.html#_top_">String</a> rules) throws <a href="java.text.ParseException.html#_top_">ParseException</a>
</pre>
<dl>
  <dd> RuleBasedCollator constructor.  This takes the table rules and builds
 a collation table out of them.  Please see RuleBasedCollator class
 description for more details on the collation rule syntax.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> rules - the collation rules to build the collation table from.
    <dt> <b>Throws:</b> <a href="java.text.ParseException.html#_top_">ParseException</a>
    <dd> A format exception
 will be thrown if the build process of the rules fails. For
 example, build rule "a < ? < d" will cause the constructor to
 throw the ParseException because the '?' is not quoted.
    <dt> <b>See Also:</b>
    <dd> <a href="java.util.Locale.html#_top_">Locale</a>
  </dl></dd>
</dl>
<a name="methods"></a>
<h2>
  <img src="images/methods.gif" width=151 height=38 alt="Methods">
</h2>
<a name="getRules()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getRules"><b>getRules</b></a>
<pre>
 public <a href="java.lang.String.html#_top_">String</a> getRules()
</pre>
<dl>
  <dd> Gets the table-based rules for the collation object.
<p>
  <dd><dl>
    <dt> <b>Returns:</b>
    <dd> returns the collation rules that the table collation object
 was created from.
  </dl></dd>
</dl>
<a name="getCollationElementIterator(java.lang.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getCollationElementIterator"><b>getCollationElementIterator</b></a>
<pre>
 public <a href="java.text.CollationElementIterator.html#_top_">CollationElementIterator</a> getCollationElementIterator(<a href="java.lang.String.html#_top_">String</a> source)
</pre>
<dl>
  <dd> Return a CollationElementIterator for the given String.
<p>
  <dd><dl>
    <dt> <b>See Also:</b>
    <dd> <a href="java.text.CollationElementIterator.html#_top_">CollationElementIterator</a>
  </dl></dd>
</dl>
<a name="compare(java.lang.String, java.lang.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="compare"><b>compare</b></a>
<pre>
 public int compare(<a href="java.lang.String.html#_top_">String</a> source,
                    <a href="java.lang.String.html#_top_">String</a> target)
</pre>
<dl>
  <dd> Compares the character data stored in two different strings based on the
 collation rules.  Returns information about whether a string is less
 than, greater than or equal to another string in a language.
 This can be overriden in a subclass.
<p>
  <dd><dl>
    <dt> <b>Overrides:</b>
    <dd> <a href="java.text.Collator.html#compare(java.lang.String, java.lang.String)">compare</a> in class <a href="java.text.Collator.html#_top_">Collator</a>
  </dl></dd>
</dl>
<a name="getCollationKey(java.lang.String)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getCollationKey"><b>getCollationKey</b></a>
<pre>
 public <a href="java.text.CollationKey.html#_top_">CollationKey</a> getCollationKey(<a href="java.lang.String.html#_top_">String</a> source)
</pre>
<dl>
  <dd> Transforms the string into a series of characters that can be compared
 with CollationKey.compareTo. This overrides java.text.Collator.getCollationKey.
 It can be overriden in a subclass.
<p>
  <dd><dl>
    <dt> <b>Overrides:</b>
    <dd> <a href="java.text.Collator.html#getCollationKey(java.lang.String)">getCollationKey</a> in class <a href="java.text.Collator.html#_top_">Collator</a>
  </dl></dd>
</dl>
<a name="clone()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="clone"><b>clone</b></a>
<pre>
 public <a href="java.lang.Object.html#_top_">Object</a> clone()
</pre>
<dl>
  <dd> Standard override; no change in semantics.
<p>
  <dd><dl>
    <dt> <b>Overrides:</b>
    <dd> <a href="java.text.Collator.html#clone()">clone</a> in class <a href="java.text.Collator.html#_top_">Collator</a>
  </dl></dd>
</dl>
<a name="equals(java.lang.Object)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="equals"><b>equals</b></a>
<pre>
 public boolean equals(<a href="java.lang.Object.html#_top_">Object</a> obj)
</pre>
<dl>
  <dd> Compares the equality of two collation objects.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> obj - the table-based collation object to be compared with this.
    <dt> <b>Returns:</b>
    <dd> true if the current table-based collation object is the same
 as the table-based collation object obj; false otherwise.
    <dt> <b>Overrides:</b>
    <dd> <a href="java.text.Collator.html#equals(java.lang.Object)">equals</a> in class <a href="java.text.Collator.html#_top_">Collator</a>
  </dl></dd>
</dl>
<a name="hashCode()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="hashCode"><b>hashCode</b></a>
<pre>
 public int hashCode()
</pre>
<dl>
  <dd> Generates the hash code for the table-based collation object
<p>
  <dd><dl>
    <dt> <b>Overrides:</b>
    <dd> <a href="java.text.Collator.html#hashCode()">hashCode</a> in class <a href="java.text.Collator.html#_top_">Collator</a>
  </dl></dd>
</dl>
<hr>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.text.html">This Package</a>  <a href="java.text.ParsePosition.html#_top_">Previous</a>  <a href="java.text.SimpleDateFormat.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
</body>
</html>
