You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2012/03/14 11:01:55 UTC

svn commit: r1300491 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CharBuffer.java test/java/org/apache/commons/csv/CharBufferTest.java

Author: ebourg
Date: Wed Mar 14 10:01:55 2012
New Revision: 1300491

URL: http://svn.apache.org/viewvc?rev=1300491&view=rev
Log:
Removed unused methods from CharBuffer

Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CharBuffer.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CharBufferTest.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CharBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CharBuffer.java?rev=1300491&r1=1300490&r2=1300491&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CharBuffer.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CharBuffer.java Wed Mar 14 10:01:55 2012
@@ -46,7 +46,7 @@ class CharBuffer {
      * Creates a new CharBuffer with an initial capacity
      * of <code>length</code> characters.
      */
-    CharBuffer(final int length) {
+    CharBuffer(int length) {
         if (length == 0) {
             throw new IllegalArgumentException("Can't create an empty CharBuffer");
         }
@@ -84,13 +84,12 @@ class CharBuffer {
      *
      * @param cb the CharBuffer to append or null
      */
-    void append(final CharBuffer cb) {
-        if (cb == null) {
-            return;
-        }
-        provideCapacity(length + cb.length);
-        System.arraycopy(cb.c, 0, c, length, cb.length);
-        length += cb.length;
+    void append(CharBuffer cb) {
+        if (cb != null) {
+            ensureCapacity(length + cb.length);
+            System.arraycopy(cb.c, 0, c, length, cb.length);
+            length += cb.length;
+        }
     }
 
     /**
@@ -99,11 +98,10 @@ class CharBuffer {
      *
      * @param s the String to append or null
      */
-    void append(final String s) {
-        if (s == null) {
-            return;
+    void append(String s) {
+        if (s != null) {
+            append(s.toCharArray());
         }
-        append(s.toCharArray());
     }
 
     /**
@@ -112,13 +110,12 @@ class CharBuffer {
      *
      * @param data the char[] to append or null
      */
-    void append(final char[] data) {
-        if (data == null) {
-            return;
-        }
-        provideCapacity(length + data.length);
-        System.arraycopy(data, 0, c, length, data.length);
-        length += data.length;
+    void append(char[] data) {
+        if (data != null) {
+            ensureCapacity(length + data.length);
+            System.arraycopy(data, 0, c, length, data.length);
+            length += data.length;
+        }
     }
 
     /**
@@ -127,26 +124,13 @@ class CharBuffer {
      *
      * @param data the char to append
      */
-    void append(final char data) {
-        provideCapacity(length + 1);
+    void append(char data) {
+        ensureCapacity(length + 1);
         c[length] = data;
         length++;
     }
 
     /**
-     * Shrinks the capacity of the buffer to the current length if necessary.
-     * This method involves copying the data once!
-     */
-    void shrink() {
-        if (c.length == length) {
-            return;
-        }
-        char[] newc = new char[length];
-        System.arraycopy(c, 0, newc, 0, length);
-        c = newc;
-    }
-
-    /**
      * Removes trailing whitespace.
      */
     void trimTrailingWhitespace() {
@@ -156,31 +140,6 @@ class CharBuffer {
     }
 
     /**
-     * Returns the contents of the buffer as a char[]. The returned array may
-     * be the internal array of the buffer, so the caller must take care when
-     * modifying it.
-     * This method allows to avoid copying if the caller knows the exact capacity
-     * before.
-     *
-     * @return
-     */
-    char[] getCharacters() {
-        if (c.length == length) {
-            return c;
-        }
-        char[] chars = new char[length];
-        System.arraycopy(c, 0, chars, 0, length);
-        return chars;
-    }
-
-    /**
-     * Returns the character at the specified position.
-     */
-    char charAt(int pos) {
-        return c[pos];
-    }
-
-    /**
      * Converts the contents of the buffer into a StringBuffer.
      * This method involves copying the new data once!
      *
@@ -196,13 +155,12 @@ class CharBuffer {
      *
      * @param capacity
      */
-    void provideCapacity(final int capacity) {
-        if (c.length >= capacity) {
-            return;
-        }
-        int newcapacity = ((capacity * 3) >> 1) + 1;
-        char[] newc = new char[newcapacity];
-        System.arraycopy(c, 0, newc, 0, length);
-        c = newc;
+    void ensureCapacity(int capacity) {
+        if (c.length < capacity) {
+            int newcapacity = ((capacity * 3) >> 1) + 1;
+            char[] newc = new char[newcapacity];
+            System.arraycopy(c, 0, newc, 0, length);
+            c = newc;
+        }
     }
 }

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CharBufferTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CharBufferTest.java?rev=1300491&r1=1300490&r2=1300491&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CharBufferTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CharBufferTest.java Wed Mar 14 10:01:55 2012
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.commons.csv;
 
 import junit.framework.TestCase;
@@ -86,20 +87,6 @@ public class CharBufferTest extends Test
         }
     }
 
-    public void testShrink() {
-        String data = "123456789012345678901234567890";
-
-        CharBuffer cb = new CharBuffer(data.length() + 100);
-        assertEquals(data.length() + 100, cb.capacity());
-        cb.append(data);
-        assertEquals(data.length() + 100, cb.capacity());
-        assertEquals(data.length(), cb.length());
-        cb.shrink();
-        assertEquals(data.length(), cb.capacity());
-        assertEquals(data.length(), cb.length());
-        assertEquals(data, cb.toString());
-    }
-
     //-- the following test cases have been adapted from the HttpComponents project
     //-- written by Oleg Kalnichevski
 
@@ -107,7 +94,7 @@ public class CharBufferTest extends Test
         CharBuffer buffer = new CharBuffer(16);
         assertEquals(16, buffer.capacity());
         assertEquals(0, buffer.length());
-        char[] b1 = buffer.getCharacters();
+        char[] b1 = buffer.toString().toCharArray();
         assertNotNull(b1);
         assertEquals(0, b1.length);
         assertEquals(0, buffer.length());
@@ -117,7 +104,7 @@ public class CharBufferTest extends Test
         assertEquals(16, buffer.capacity());
         assertEquals(4, buffer.length());
 
-        char[] b2 = buffer.getCharacters();
+        char[] b2 = buffer.toString().toCharArray();
         assertNotNull(b2);
         assertEquals(4, b2.length);
         for (int i = 0; i < tmp.length; i++) {
@@ -172,9 +159,9 @@ public class CharBufferTest extends Test
 
     public void testProvideCapacity() throws Exception {
         CharBuffer buffer = new CharBuffer(4);
-        buffer.provideCapacity(2);
+        buffer.ensureCapacity(2);
         assertEquals(4, buffer.capacity());
-        buffer.provideCapacity(8);
+        buffer.ensureCapacity(8);
         assertTrue(buffer.capacity() >= 8);
     }
 }