Moving from StringBuffer API to StringBuilder

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@956305 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2010-06-19 22:41:56 +00:00
parent f208babdc0
commit ae77247f97
16 changed files with 27 additions and 27 deletions

View File

@ -238,7 +238,7 @@ public class ExtendedProperties extends Hashtable {
int end = -1;
int prec = 0 - END_TOKEN.length();
String variable = null;
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
// FIXME: we should probably allow the escaping of the start token
while (((begin = base.indexOf(START_TOKEN, prec + END_TOKEN.length())) > -1)
@ -250,7 +250,7 @@ public class ExtendedProperties extends Hashtable {
if (priorVariables.contains(variable)) {
String initialBase = priorVariables.remove(0).toString();
priorVariables.add(variable);
StringBuffer priorVariableSb = new StringBuffer();
StringBuilder priorVariableSb = new StringBuilder();
// create a nice trace of interpolated variables like so:
// var1->var2->var3
@ -296,7 +296,7 @@ public class ExtendedProperties extends Hashtable {
* Inserts a backslash before every comma and backslash.
*/
private static String escape(String s) {
StringBuffer buf = new StringBuffer(s);
StringBuilder buf = new StringBuilder(s);
for (int i = 0; i < buf.length(); i++) {
char c = buf.charAt(i);
if (c == ',' || c == '\\') {
@ -311,7 +311,7 @@ public class ExtendedProperties extends Hashtable {
* Removes a backslash from every pair of backslashes.
*/
private static String unescape(String s) {
StringBuffer buf = new StringBuffer(s);
StringBuilder buf = new StringBuilder(s);
for (int i = 0; i < buf.length() - 1; i++) {
char c1 = buf.charAt(i);
char c2 = buf.charAt(i + 1);
@ -369,7 +369,7 @@ public class ExtendedProperties extends Hashtable {
* @throws IOException if there is difficulty reading the source.
*/
public String readProperty() throws IOException {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
String line = readLine();
while (line != null) {
line = line.trim();
@ -423,7 +423,7 @@ public class ExtendedProperties extends Hashtable {
* @return A String.
*/
public String nextToken() {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
while (hasMoreTokens()) {
String token = super.nextToken();
@ -757,7 +757,7 @@ public class ExtendedProperties extends Hashtable {
Object value = get(key);
if (value != null) {
if (value instanceof String) {
StringBuffer currentOutput = new StringBuffer();
StringBuilder currentOutput = new StringBuilder();
currentOutput.append(key);
currentOutput.append("=");
currentOutput.append(escape((String) value));
@ -767,7 +767,7 @@ public class ExtendedProperties extends Hashtable {
List values = (List) value;
for (Iterator it = values.iterator(); it.hasNext(); ) {
String currentElement = (String) it.next();
StringBuffer currentOutput = new StringBuffer();
StringBuilder currentOutput = new StringBuilder();
currentOutput.append(key);
currentOutput.append("=");
currentOutput.append(escape(currentElement));

View File

@ -579,7 +579,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
if (size() == 0) {
return "[]";
}
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append('[');
Iterator<E> it = uniqueSet().iterator();
while (it.hasNext()) {

View File

@ -1372,7 +1372,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> imple
if (nodeCount == 0) {
return "{}";
}
StringBuffer buf = new StringBuffer(nodeCount * 32);
StringBuilder buf = new StringBuilder(nodeCount * 32);
buf.append('{');
MapIterator<?, ?> it = getMapIterator(dataElement);
boolean hasNext = it.hasNext();

View File

@ -527,7 +527,7 @@ public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E
* @return a string representation of this heap
*/
public String toString() {
final StringBuffer sb = new StringBuffer();
final StringBuilder sb = new StringBuilder();
sb.append("[ ");

View File

@ -73,7 +73,7 @@ public abstract class AbstractKeyValue<K, V> implements KeyValue<K, V> {
* @return a String view of the entry
*/
public String toString() {
return new StringBuffer()
return new StringBuilder()
.append(getKey())
.append('=')
.append(getValue())

View File

@ -360,7 +360,7 @@ public abstract class AbstractLinkedList<E> implements List<E> {
if (size() == 0) {
return "[]";
}
StringBuffer buf = new StringBuffer(16 * size());
StringBuilder buf = new StringBuilder(16 * size());
buf.append("[");
Iterator<E> it = iterator();

View File

@ -1095,7 +1095,7 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
}
public String toString() {
return new StringBuffer().append(getKey()).append('=').append(getValue()).toString();
return new StringBuilder().append(getKey()).append('=').append(getValue()).toString();
}
}
@ -1331,7 +1331,7 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
if (size() == 0) {
return "{}";
}
StringBuffer buf = new StringBuffer(32 * size());
StringBuilder buf = new StringBuilder(32 * size());
buf.append('{');
MapIterator<K, V> it = mapIterator();

View File

@ -1128,7 +1128,7 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
if (size == 0) {
return "{}";
}
StringBuffer buf = new StringBuffer(128);
StringBuilder buf = new StringBuilder(128);
buf.append('{');
switch (size) { // drop through
case 3:

View File

@ -321,7 +321,7 @@ public class ListOrderedMap<K, V>
if (isEmpty()) {
return "{}";
}
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append('{');
boolean first = true;
for (Map.Entry<K, V> entry : entrySet()) {

View File

@ -557,7 +557,7 @@ public class SingletonMap<K, V>
* @return a string version of the map
*/
public String toString() {
return new StringBuffer(128)
return new StringBuilder(128)
.append('{')
.append((getKey() == this ? "(this Map)" : getKey()))
.append('=')

View File

@ -232,7 +232,7 @@ public abstract class AbstractTestObject extends BulkTest {
}
protected String getCanonicalEmptyCollectionName(Object object) {
StringBuffer retval = new StringBuffer();
StringBuilder retval = new StringBuilder();
retval.append("data/test/");
String colName = object.getClass().getName();
colName = colName.substring(colName.lastIndexOf(".") + 1, colName.length());
@ -244,7 +244,7 @@ public abstract class AbstractTestObject extends BulkTest {
}
protected String getCanonicalFullCollectionName(Object object) {
StringBuffer retval = new StringBuffer();
StringBuilder retval = new StringBuilder();
retval.append("data/test/");
String colName = object.getClass().getName();
colName = colName.substring(colName.lastIndexOf(".") + 1, colName.length());

View File

@ -121,7 +121,7 @@ public class TestClosureUtils extends junit.framework.TestCase {
//------------------------------------------------------------------
public void testNopClosure() {
StringBuffer buf = new StringBuffer("Hello");
StringBuilder buf = new StringBuilder("Hello");
ClosureUtils.nopClosure().execute(null);
assertEquals("Hello", buf.toString());
ClosureUtils.nopClosure().execute("Hello");
@ -132,10 +132,10 @@ public class TestClosureUtils extends junit.framework.TestCase {
//------------------------------------------------------------------
public void testInvokeClosure() {
StringBuffer buf = new StringBuffer("Hello");
StringBuilder buf = new StringBuilder("Hello");
ClosureUtils.invokerClosure("reverse").execute(buf);
assertEquals("olleH", buf.toString());
buf = new StringBuffer("Hello");
buf = new StringBuilder("Hello");
ClosureUtils.invokerClosure("setLength", new Class[] {Integer.TYPE}, new Object[] {new Integer(2)}).execute(buf);
assertEquals("He", buf.toString());
}

View File

@ -332,7 +332,7 @@ public class TestPriorityBuffer<E> extends AbstractTestCollection<E> {
*/
protected String showTree(PriorityBuffer<?> h) {
int count = 1;
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
for (int offset = 1; count < h.size() + 1; offset *= 2) {
for (int i = offset; i < offset * 2; i++) {
if (i < h.elements.length && h.elements[i] != null)

View File

@ -169,7 +169,7 @@ public abstract class AbstractTestComparator<T> extends AbstractTestObject {
}
public String getCanonicalComparatorName(Object object) {
StringBuffer retval = new StringBuffer();
StringBuilder retval = new StringBuilder();
retval.append("data/test/");
String colName = object.getClass().getName();
colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());

View File

@ -144,7 +144,7 @@ public class TestComparatorChain extends AbstractTestComparator<TestComparatorCh
}
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[");
buf.append(cols[0]);
buf.append(",");

View File

@ -397,7 +397,7 @@ public class TestFilterListIterator extends TestCase {
}
// random walk
StringBuffer walkdescr = new StringBuffer(500);
StringBuilder walkdescr = new StringBuilder(500);
for (int i = 0; i < 500; i++) {
if (random.nextBoolean()) {
// step forward