summaryrefslogtreecommitdiff
path: root/gnu/java
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2008-05-05 18:42:03 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2008-05-05 18:42:03 +0000
commit40d5f2296d816b5e5a9b18005214f7b6a1cebe4e (patch)
tree0010461e13da955bc29b7427f966c6f5ed8440c7 /gnu/java
parent8a9a69fd0582756c8f576de969cf53362f2356d5 (diff)
downloadclasspath-40d5f2296d816b5e5a9b18005214f7b6a1cebe4e.tar.gz
2008-05-05 Andrew John Hughes <gnu_andrew@member.fsf.org>
PR classpath/21869 * gnu/java/lang/CPStringBuilder.java: (CPStringBuilder(StringBuffer)): Added. (CPStringBuulder(StringBuilder)): Likewise. * gnu/java/text/AttributedFormatBuffer.java: Swap use of StringBuffer for CPStringBuilder, and make fields final. * gnu/java/text/StringFormatBuffer.java: Make fields final. * java/text/SimpleDateFormat.java: Add thread safety warning.
Diffstat (limited to 'gnu/java')
-rw-r--r--gnu/java/lang/CPStringBuilder.java38
-rw-r--r--gnu/java/text/AttributedFormatBuffer.java24
-rw-r--r--gnu/java/text/StringFormatBuffer.java2
3 files changed, 49 insertions, 15 deletions
diff --git a/gnu/java/lang/CPStringBuilder.java b/gnu/java/lang/CPStringBuilder.java
index 978a2043f..d6ddca2c5 100644
--- a/gnu/java/lang/CPStringBuilder.java
+++ b/gnu/java/lang/CPStringBuilder.java
@@ -82,7 +82,7 @@ public final class CPStringBuilder
}
/**
- * Create an empty <code>StringBuffer</code> with the specified initial
+ * Create an empty <code>CPStringBuilder</code> with the specified initial
* capacity.
*
* @param capacity the initial capacity
@@ -94,7 +94,7 @@ public final class CPStringBuilder
}
/**
- * Create a new <code>StringBuffer</code> with the characters in the
+ * Create a new <code>CPStringBuilder</code> with the characters in the
* specified <code>String</code>. Initial capacity will be the size of the
* String plus 16.
*
@@ -109,7 +109,37 @@ public final class CPStringBuilder
}
/**
- * Create a new <code>StringBuffer</code> with the characters in the
+ * Create a new <code>CPStringBuilder</code> with the characters in the
+ * specified <code>StringBuffer</code>. Initial capacity will be the size of the
+ * String plus 16.
+ *
+ * @param str the <code>String</code> to convert
+ * @throws NullPointerException if str is null
+ */
+ public CPStringBuilder(StringBuffer str)
+ {
+ count = str.length();
+ value = new char[count + DEFAULT_CAPACITY];
+ str.getChars(0, count, value, 0);
+ }
+
+ /**
+ * Create a new <code>CPStringBuilder</code> with the characters in the
+ * specified <code>StringBuilder</code>. Initial capacity will be the size of the
+ * String plus 16.
+ *
+ * @param str the <code>String</code> to convert
+ * @throws NullPointerException if str is null
+ */
+ public CPStringBuilder(StringBuilder str)
+ {
+ count = str.length();
+ value = new char[count + DEFAULT_CAPACITY];
+ str.getChars(0, count, value, 0);
+ }
+
+ /**
+ * Create a new <code>CPStringBuilder</code> with the characters in the
* specified <code>CharSequence</code>. Initial capacity will be the
* length of the sequence plus 16; if the sequence reports a length
* less than or equal to 0, then the initial capacity will be 16.
@@ -128,7 +158,7 @@ public final class CPStringBuilder
}
/**
- * Increase the capacity of this <code>StringBuffer</code>. This will
+ * Increase the capacity of this <code>CPStringBuilder</code>. This will
* ensure that an expensive growing operation will not occur until
* <code>minimumCapacity</code> is reached. The buffer is grown to the
* larger of <code>minimumCapacity</code> and
diff --git a/gnu/java/text/AttributedFormatBuffer.java b/gnu/java/text/AttributedFormatBuffer.java
index ae3e6ef70..c2aae9609 100644
--- a/gnu/java/text/AttributedFormatBuffer.java
+++ b/gnu/java/text/AttributedFormatBuffer.java
@@ -36,21 +36,25 @@ obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.text;
+import gnu.java.lang.CPStringBuilder;
+
import java.text.AttributedCharacterIterator;
import java.util.ArrayList;
import java.util.HashMap;
/**
* This class is an implementation of a FormatBuffer with attributes.
- *
+ * Note that this class is not thread-safe; external synchronisation
+ * should be used if an instance is to be accessed from multiple threads.
+ *
* @author Guilhem Lavaux <guilhem@kaffe.org>
* @date April 10, 2004
*/
public class AttributedFormatBuffer implements FormatBuffer
{
- private StringBuffer buffer;
- private ArrayList ranges;
- private ArrayList attributes;
+ private final CPStringBuilder buffer;
+ private final ArrayList ranges;
+ private final ArrayList attributes;
private int[] a_ranges;
private HashMap[] a_attributes;
private int startingRange;
@@ -60,9 +64,9 @@ public class AttributedFormatBuffer implements FormatBuffer
* This constructor accepts a StringBuffer. If the buffer contains
* already some characters they will not be attributed.
*/
- public AttributedFormatBuffer(StringBuffer buffer)
+ public AttributedFormatBuffer(CPStringBuilder buffer)
{
- this.buffer = buffer;
+ this.buffer = new CPStringBuilder(buffer);
this.ranges = new ArrayList();
this.attributes = new ArrayList();
this.defaultAttr = null;
@@ -77,7 +81,7 @@ public class AttributedFormatBuffer implements FormatBuffer
public AttributedFormatBuffer(int prebuffer)
{
- this(new StringBuffer(prebuffer));
+ this(new CPStringBuilder(prebuffer));
}
public AttributedFormatBuffer()
@@ -214,12 +218,12 @@ public class AttributedFormatBuffer implements FormatBuffer
}
/**
- * This method returns the internal StringBuffer describing
+ * This method returns the internal CPStringBuilder describing
* the attributed string.
*
- * @return An instance of StringBuffer which contains the string.
+ * @return An instance of CPStringBuilder which contains the string.
*/
- public StringBuffer getBuffer()
+ public CPStringBuilder getBuffer()
{
return buffer;
}
diff --git a/gnu/java/text/StringFormatBuffer.java b/gnu/java/text/StringFormatBuffer.java
index 19b621ce4..fc8d08ee6 100644
--- a/gnu/java/text/StringFormatBuffer.java
+++ b/gnu/java/text/StringFormatBuffer.java
@@ -47,7 +47,7 @@ import java.util.HashMap;
*/
public class StringFormatBuffer implements FormatBuffer
{
- private StringBuffer buffer;
+ private final StringBuffer buffer;
private AttributedCharacterIterator.Attribute defaultAttr;
public StringFormatBuffer(int prebuffer)