/[classpath]/classpath/java/text/RuleBasedCollator.java
ViewVC logotype

Diff of /classpath/java/text/RuleBasedCollator.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by mkoch, Thu Jun 26 18:03:21 2003 UTC revision 1.11 by mkoch, Wed Oct 15 16:05:11 2003 UTC
# Line 174  public class RuleBasedCollator extends C Line 174  public class RuleBasedCollator extends C
174     *     *
175     * @exception ParseException If the rule string contains syntax errors.     * @exception ParseException If the rule string contains syntax errors.
176     */     */
177    public RuleBasedCollator(String rules) throws ParseException    public RuleBasedCollator (String rules) throws ParseException
178    {    {
179      this.rules = rules;      this.rules = rules;
180    
# Line 293  public class RuleBasedCollator extends C Line 293  public class RuleBasedCollator extends C
293    }    }
294    
295    /**    /**
296     * This method returns a <code>String</code> containing the collation rules     * This method creates a copy of this object.
    * for this object.  
    *  
    * @return The collation rules for this object.  
    */  
   public String getRules()  
   {  
     return(rules);  
   }  
   
   /**  
    * This method calculates the collation element value for the specified  
    * character(s).  
    */  
   int getCollationElementValue(String str)  
   {  
     CollationElement e = null;  
   
     // The table is sorted.  Change to a binary search later.  
     for (int i = 0; i < ce_table.length; i++)  
       if (((CollationElement)ce_table[i]).char_seq.equals(str))  
         {  
           e = (CollationElement)ce_table[i];  
           break;  
         }  
   
     if (e == null)  
       e = new CollationElement(str, 0xFFFF, (short)0xFF, (short)0xFF);  
   
     int retval = (e.primary << 16) + (e.secondary << 8) + e.tertiary;  
   
     return(retval);  
   }  
   
   /**  
    * This method returns an instance for <code>CollationElementIterator</code>  
    * for the specified <code>String</code> under the collation rules for this  
    * object.  
    *  
    * @param str The <code>String</code> to return the <code>CollationElementIterator</code> instance for.  
    *  
    * @return A <code>CollationElementIterator</code> for the specified <code>String</code>.  
    */  
   public CollationElementIterator getCollationElementIterator(String str)  
   {  
     return(new CollationElementIterator(this, str));  
   }    
   
   /**  
    * This method returns an instance of <code>CollationElementIterator</code>  
    * for the <code>String</code> represented by the specified  
    * <code>CharacterIterator</code>.  
    *  
    * @param ci The <code>CharacterIterator</code> with the desired <code>String</code>.  
297     *     *
298     * @return A <code>CollationElementIterator</code> for the specified <code>String</code>.     * @return A copy of this object.
299     */     */
300    public CollationElementIterator getCollationElementIterator(CharacterIterator ci)    public Object clone()
301    {    {
302      StringBuffer sb = new StringBuffer("");      return super.clone();
   
     // Right now we assume that we will read from the beginning of the string.  
     char c = ci.first();  
     while (c != CharacterIterator.DONE)  
       {  
         sb.append(c);  
         c = ci.next();  
       }  
   
     return(getCollationElementIterator(sb.toString()));  
303    }    }
304    
305    /**    /**
# Line 377  public class RuleBasedCollator extends C Line 314  public class RuleBasedCollator extends C
314     * @return A negative integer if s1 &lt; s2, a positive integer     * @return A negative integer if s1 &lt; s2, a positive integer
315     * if s1 &gt; s2, or 0 if s1 == s2.     * if s1 &gt; s2, or 0 if s1 == s2.
316     */     */
317    public int compare(String s1, String s2)    public int compare (String s1, String s2)
318    {    {
319      CollationElementIterator cei1 = getCollationElementIterator(s1);      CollationElementIterator cei1 = getCollationElementIterator(s1);
320      CollationElementIterator cei2 = getCollationElementIterator(s2);      CollationElementIterator cei2 = getCollationElementIterator(s2);
# Line 434  public class RuleBasedCollator extends C Line 371  public class RuleBasedCollator extends C
371    }    }
372    
373    /**    /**
374       * This method tests this object for equality against the specified
375       * object.  This will be true if and only if the specified object is
376       * another reference to this object.
377       *
378       * @param obj The <code>Object</code> to compare against this object.
379       *
380       * @return <code>true</code> if the specified object is equal to this object, <code>false</code> otherwise.
381       */
382      public boolean equals (Object obj)
383      {
384        if (obj == this)
385          return(true);
386        else
387          return(false);
388      }
389    
390      /**
391       * This method returns an instance for <code>CollationElementIterator</code>
392       * for the specified <code>String</code> under the collation rules for this
393       * object.
394       *
395       * @param str The <code>String</code> to return the <code>CollationElementIterator</code> instance for.
396       *
397       * @return A <code>CollationElementIterator</code> for the specified <code>String</code>.
398       */
399      public CollationElementIterator getCollationElementIterator (String str)
400      {
401        return new CollationElementIterator (this, str);
402      }  
403    
404      /**
405       * This method returns an instance of <code>CollationElementIterator</code>
406       * for the <code>String</code> represented by the specified
407       * <code>CharacterIterator</code>.
408       *
409       * @param ci The <code>CharacterIterator</code> with the desired <code>String</code>.
410       *
411       * @return A <code>CollationElementIterator</code> for the specified <code>String</code>.
412       */
413      public CollationElementIterator getCollationElementIterator(CharacterIterator ci)
414      {
415        StringBuffer sb = new StringBuffer("");
416    
417        // Right now we assume that we will read from the beginning of the string.
418        char c = ci.first();
419        while (c != CharacterIterator.DONE)
420          {
421            sb.append(c);
422            c = ci.next();
423          }
424    
425        return(getCollationElementIterator(sb.toString()));
426      }
427    
428      /**
429     * This method returns an instance of <code>CollationKey</code> for the     * This method returns an instance of <code>CollationKey</code> for the
430     * specified <code>String</code>.  The object returned will have a     * specified <code>String</code>.  The object returned will have a
431     * more efficient mechanism for its comparison function that could     * more efficient mechanism for its comparison function that could
# Line 444  public class RuleBasedCollator extends C Line 436  public class RuleBasedCollator extends C
436     *     *
437     * @return A <code>CollationKey</code> for the specified <code>String</code>.     * @return A <code>CollationKey</code> for the specified <code>String</code>.
438     */     */
439    public CollationKey getCollationKey(String str)    public CollationKey getCollationKey (String str)
440    {    {
441      CollationElementIterator cei = getCollationElementIterator(str);      CollationElementIterator cei = getCollationElementIterator(str);
442      Vector vect = new Vector(25);      Vector vect = new Vector(25);
# Line 487  public class RuleBasedCollator extends C Line 479  public class RuleBasedCollator extends C
479    }    }
480    
481    /**    /**
482     * This method tests this object for equality against the specified     * This method returns a <code>String</code> containing the collation rules
483     * object.  This will be true if and only if the specified object is     * for this object.
    * another reference to this object.  
    *  
    * @param obj The <code>Object</code> to compare against this object.  
484     *     *
485     * @return <code>true</code> if the specified object is equal to this object, <code>false</code> otherwise.     * @return The collation rules for this object.
486     */     */
487    public boolean equals(Object obj)    public String getRules()
488    {    {
489      if (obj == this)      return(rules);
       return(true);  
     else  
       return(false);  
490    }    }
491    
492    /**    /**
# Line 514  public class RuleBasedCollator extends C Line 500  public class RuleBasedCollator extends C
500    }    }
501    
502    /**    /**
503     * This method creates a copy of this object.     * This method calculates the collation element value for the specified
504     *     * character(s).
    * @return A copy of this object.  
505     */     */
506    public Object clone()    int getCollationElementValue(String str)
507    {    {
508      return super.clone();      CollationElement e = null;
509    
510        // The table is sorted.  Change to a binary search later.
511        for (int i = 0; i < ce_table.length; i++)
512          if (((CollationElement)ce_table[i]).char_seq.equals(str))
513            {
514              e = (CollationElement)ce_table[i];
515              break;
516            }
517    
518        if (e == null)
519          e = new CollationElement(str, 0xFFFF, (short)0xFF, (short)0xFF);
520    
521        int retval = (e.primary << 16) + (e.secondary << 8) + e.tertiary;
522    
523        return(retval);
524    }    }
525  }  
526    } // class RuleBaseCollator

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26