More of the same. This also adds a few additional
constructors to CPStringBuilder to speed up creation
from a StringBuffer or StringBuilder, and makes a few
fields final.
ChangeLog:
2008-05-05 Andrew John Hughes <[EMAIL PROTECTED]>
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.
--
Andrew :)
Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8
Index: gnu/java/lang/CPStringBuilder.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/lang/CPStringBuilder.java,v
retrieving revision 1.4
diff -u -r1.4 CPStringBuilder.java
--- gnu/java/lang/CPStringBuilder.java 17 Mar 2008 03:04:17 -0000 1.4
+++ gnu/java/lang/CPStringBuilder.java 5 May 2008 18:32:38 -0000
@@ -82,7 +82,7 @@
}
/**
- * 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 @@
}
/**
- * 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 @@
}
/**
- * 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 @@
}
/**
- * 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
Index: gnu/java/text/AttributedFormatBuffer.java
===================================================================
RCS file:
/sources/classpath/classpath/gnu/java/text/AttributedFormatBuffer.java,v
retrieving revision 1.3
diff -u -r1.3 AttributedFormatBuffer.java
--- gnu/java/text/AttributedFormatBuffer.java 7 Jan 2008 21:11:21 -0000
1.3
+++ gnu/java/text/AttributedFormatBuffer.java 5 May 2008 18:32:39 -0000
@@ -36,21 +36,25 @@
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 <[EMAIL PROTECTED]>
* @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 @@
* 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 AttributedFormatBuffer(int prebuffer)
{
- this(new StringBuffer(prebuffer));
+ this(new CPStringBuilder(prebuffer));
}
public AttributedFormatBuffer()
@@ -214,12 +218,12 @@
}
/**
- * 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;
}
Index: gnu/java/text/StringFormatBuffer.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/text/StringFormatBuffer.java,v
retrieving revision 1.3
diff -u -r1.3 StringFormatBuffer.java
--- gnu/java/text/StringFormatBuffer.java 7 May 2006 19:36:27 -0000
1.3
+++ gnu/java/text/StringFormatBuffer.java 5 May 2008 18:32:39 -0000
@@ -47,7 +47,7 @@
*/
public class StringFormatBuffer implements FormatBuffer
{
- private StringBuffer buffer;
+ private final StringBuffer buffer;
private AttributedCharacterIterator.Attribute defaultAttr;
public StringFormatBuffer(int prebuffer)
Index: java/text/SimpleDateFormat.java
===================================================================
RCS file: /sources/classpath/classpath/java/text/SimpleDateFormat.java,v
retrieving revision 1.59
diff -u -r1.59 SimpleDateFormat.java
--- java/text/SimpleDateFormat.java 24 Mar 2008 15:01:17 -0000 1.59
+++ java/text/SimpleDateFormat.java 5 May 2008 18:32:43 -0000
@@ -63,6 +63,8 @@
/**
* SimpleDateFormat provides convenient methods for parsing and formatting
* dates using Gregorian calendars (see java.util.GregorianCalendar).
+ * This class is not thread-safe; external synchronisation should be applied
+ * if an instance is to be accessed from multiple threads.
*/
public class SimpleDateFormat extends DateFormat
{