classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch to 1.4 for java.lang.StringBuffer


From: Isaac Jones
Subject: patch to 1.4 for java.lang.StringBuffer
Date: 24 Aug 2001 16:22:56 -0400
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Artificial Intelligence)

This is a patch to make the Classpath project's java.lang.StringBuffer
compatable with the JDK 1.4 Beta API.  I've added a few functions and
made small changes.  This patch is, of course, given under the GPL (do
I have to sign anything?)

It is submitted on behalf of the Ohio State Opensource Club
(http://www.cis.ohio-state.edu/opensource).

Please find a diff below the following changelog entry - I hope I got
the changelog syntax right.


2001-08-24  Isaac Jones  <address@hidden>

        * java/lang/StringBuffer.java: Updated to JDK 1.4 beta.  The
        "extends Object" was added for compatibility with the JDK 1.4
        (Beta) API.
        * java/lang/StringBuffer.java (subSequence): is new in JDK 1.4,
        though it was already implemented in classpath.  I added the
        "@since 1.4" tag to make it compatable with 1.4. I
        altered the exception thrown to be IndexOutOfBoundsException to
        make the documentation compatable with 1.4.
        * java/lang/StringBuffer.java (indexOf, lastIndexOf): I copied the
        Javadoc in the classpath String class.  The functions call through
        to those functions, so they behave exactly the same.  The JDK 1.4
        API also copies their own String class Javadoc.



Index: StringBuffer.java
===================================================================
RCS file: /cvs/classpath/java/lang/StringBuffer.java,v
retrieving revision 1.15
diff -c -r1.15 StringBuffer.java
*** StringBuffer.java   2001/07/10 00:01:45     1.15
--- StringBuffer.java   2001/08/24 19:36:18
***************
*** 35,40 ****
--- 35,41 ----
  /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
   * Updated using online JDK 1.2 docs.
   * Believed complete and correct to JDK 1.2.
+  * JDK 1.4 (Beta) compatibility August 22, 2001 - Isaac Jones
   * Merged with Classpath.
   */
  
***************
*** 73,79 ****
   * @author Tom Tromey
   * @see java.lang.String
   */
! public final class StringBuffer implements Serializable, CharSequence
  {
    /** Append the <code>String</code> value of the argument to this 
<code>StringBuffer</code>.
     *  Uses <code>String.valueOf()</code> to convert to
--- 74,80 ----
   * @author Tom Tromey
   * @see java.lang.String
   */
! public final class StringBuffer extends Object implements Serializable, 
CharSequence
  {
    /** Append the <code>String</code> value of the argument to this 
<code>StringBuffer</code>.
     *  Uses <code>String.valueOf()</code> to convert to
***************
*** 145,150 ****
--- 146,165 ----
    {
      return append (String.valueOf(dnum));
    }
+     
+   /** Append the <code>StringBuffer</code> value of the argument to this 
<code>StringBuffer</code>.
+    *  Uses <code>StringBuffer.toString()</code> to convert to
+    *  <code>String</code>.
+    *
+    *  @param stringBuffer the <code>StringBuffer</code> to convert and append.
+    *  @return this <code>StringBuffer</code>.
+    *  @see java.lang.StringBuffer.toString()
+    *  @since 1.4
+    */
+   public StringBuffer append (StringBuffer stringBuffer)
+   {
+     return append (stringBuffer.toString());
+   }
  
    /** Append the <code>String</code> value of the argument to this 
<code>StringBuffer</code>.
     *  Uses <code>String.valueOf()</code> to convert to
***************
*** 679,699 ****
     * To implement <code>CharSequence</code>.
     * Calls <code>substring(beginIndex, endIndex)</code>.
     *
     * @param beginIndex index to start substring (base 0)
     * @param endIndex index after the last character to be 
     *   copied into the substring
     * 
     * @return new String which is a substring of this StringBuffer
     *
!    * @exception StringIndexOutOfBoundsException 
     *   if (beginIndex < 0 || endIndex > this.length() || beginIndex > 
endIndex)
     */
    public CharSequence subSequence (int beginIndex, int endIndex) 
    {
      return substring(beginIndex, endIndex);
    }
  
- 
    /** Convert this <code>StringBuffer</code> to a <code>String</code>.
     *  @return the characters in this StringBuffer
     */
--- 694,717 ----
     * To implement <code>CharSequence</code>.
     * Calls <code>substring(beginIndex, endIndex)</code>.
     *
+    * As of JDK 1.4, this is part of the official (Beta) API.
+    *
     * @param beginIndex index to start substring (base 0)
     * @param endIndex index after the last character to be 
     *   copied into the substring
     * 
     * @return new String which is a substring of this StringBuffer
     *
!    * @exception IndexOutOfBoundsException 
     *   if (beginIndex < 0 || endIndex > this.length() || beginIndex > 
endIndex)
+    *
+    * @since 1.4
     */
    public CharSequence subSequence (int beginIndex, int endIndex) 
    {
      return substring(beginIndex, endIndex);
    }
  
    /** Convert this <code>StringBuffer</code> to a <code>String</code>.
     *  @return the characters in this StringBuffer
     */
***************
*** 702,707 ****
--- 720,797 ----
      // Note: in libgcj this causes the StringBuffer to be shared.  In
      // Classpath it does not.
      return new String (this);
+   }
+ 
+   /** Finds the first instance of a String in this StringBuffer.
+    *
+    *  @param str String to find
+    * 
+    *  @return location (base 0) of the String, or -1 if not found
+    *
+    *  @exception NullPointerException if `str' is null
+    * 
+    *  @since 1.4
+    */
+   public int indexOf (String string)
+   {
+     return this.toString().indexOf(string, 0);
+     //save a call in String.java by passing second argument
+   }
+   
+   /** Finds the first instance of a String in this StringBuffer,
+    *  starting at a given index.  If starting index is less than 0,
+    *  the search starts at the beginning of this String.  If the
+    *  starting index is greater than the length of this String, -1 is
+    *  returned.
+    *
+    *  @param str String to find
+    *  @param fromIndex index to start the search
+    *
+    *  @return location (base 0) of the String, or -1 if not found
+    *
+    *  @exception NullPointerException if `str' is null
+    *
+    *  @since 1.4
+    */
+   public int indexOf (String string,
+                     int fromIndex)
+   {
+     return this.toString().indexOf(string, fromIndex);
+   }
+ 
+   /** Finds the last instance of a String in this StringBuffer.
+    *
+    *  @param str String to find
+    * 
+    *  @return location (base 0) of the String, or -1 if not found
+    *
+    *  @exception NullPointerException if `str' is null
+    *
+    *  @since 1.4
+    */
+   public int lastIndexOf(String str) throws NullPointerException
+   {
+     return this.toString().lastIndexOf(str, count-1);
+   }
+ 
+   /** Finds the last instance of a String in this StringBuffer,
+    *  starting at a given index.  If starting index is greater than the
+    *  maximum valid index, then the search begins at the end of this
+    *  String.  If the starting index is less than zero, -1 is returned.
+    *
+    *  @param str String to find
+    *  @param fromIndex index to start the search
+    *
+    *  @return location (base 0) of the String, or -1 if not found
+    *
+    *  @exception NullPointerException if `str' is null
+    * 
+    *  @since 1.4
+    */
+   public int lastIndexOf(String str, int fromIndex)
+     throws NullPointerException
+   {
+     return this.toString().lastIndexOf(str, fromIndex);
    }
  
    // Index of next available character.  Note that this has




reply via email to

[Prev in Thread] Current Thread [Next in Thread]