StringBuffer => StringBuilder where being used as a local-only buffer
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1391112 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3ab8e13026
commit
89c6497228
|
@ -330,7 +330,7 @@ public class ExtendedMessageFormat extends MessageFormat {
|
|||
private int readArgumentIndex(String pattern, ParsePosition pos) {
|
||||
int start = pos.getIndex();
|
||||
seekNonWs(pattern, pos);
|
||||
StringBuffer result = new StringBuffer();
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean error = false;
|
||||
for (; !error && pos.getIndex() < pattern.length(); next(pos)) {
|
||||
char c = pattern.charAt(pos.getIndex());
|
||||
|
|
|
@ -413,14 +413,14 @@ public class DurationFormatUtils {
|
|||
*/
|
||||
static String format(Token[] tokens, int years, int months, int days, int hours, int minutes, int seconds,
|
||||
int milliseconds, boolean padWithZeros) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
boolean lastOutputSeconds = false;
|
||||
int sz = tokens.length;
|
||||
for (int i = 0; i < sz; i++) {
|
||||
Token token = tokens[i];
|
||||
Object value = token.getValue();
|
||||
int count = token.getCount();
|
||||
if (value instanceof StringBuffer) {
|
||||
if (value instanceof StringBuilder) {
|
||||
buffer.append(value.toString());
|
||||
} else {
|
||||
if (value == y) {
|
||||
|
@ -485,7 +485,9 @@ public class DurationFormatUtils {
|
|||
ArrayList<Token> list = new ArrayList<Token>(array.length);
|
||||
|
||||
boolean inLiteral = false;
|
||||
StringBuffer buffer = null;
|
||||
// Although the buffer is stored in a Token, the Tokens are only
|
||||
// used internally, so cannot be accessed by other threads
|
||||
StringBuilder buffer = null;
|
||||
Token previous = null;
|
||||
int sz = array.length;
|
||||
for(int i=0; i<sz; i++) {
|
||||
|
@ -502,7 +504,7 @@ public class DurationFormatUtils {
|
|||
buffer = null;
|
||||
inLiteral = false;
|
||||
} else {
|
||||
buffer = new StringBuffer();
|
||||
buffer = new StringBuilder();
|
||||
list.add(new Token(buffer));
|
||||
inLiteral = true;
|
||||
}
|
||||
|
@ -516,7 +518,7 @@ public class DurationFormatUtils {
|
|||
case 'S' : value = S; break;
|
||||
default :
|
||||
if(buffer == null) {
|
||||
buffer = new StringBuffer();
|
||||
buffer = new StringBuilder();
|
||||
list.add(new Token(buffer));
|
||||
}
|
||||
buffer.append(ch);
|
||||
|
@ -625,7 +627,7 @@ public class DurationFormatUtils {
|
|||
if (this.count != tok2.count) {
|
||||
return false;
|
||||
}
|
||||
if (this.value instanceof StringBuffer) {
|
||||
if (this.value instanceof StringBuilder) {
|
||||
return this.value.toString().equals(tok2.value.toString());
|
||||
} else if (this.value instanceof Number) {
|
||||
return this.value.equals(tok2.value);
|
||||
|
|
|
@ -111,7 +111,7 @@ public class ExtendedMessageFormatTest {
|
|||
nf = NumberFormat.getCurrencyInstance(locale);
|
||||
emf = new ExtendedMessageFormat(pattern, locale, registry);
|
||||
}
|
||||
StringBuffer expected = new StringBuffer();
|
||||
StringBuilder expected = new StringBuilder();
|
||||
expected.append("Name: ");
|
||||
expected.append(args[0].toString().toUpperCase());
|
||||
expected.append(" DOB: ");
|
||||
|
@ -338,7 +338,7 @@ public class ExtendedMessageFormatTest {
|
|||
* @param locale Locale
|
||||
*/
|
||||
private void checkBuiltInFormat(String pattern, Map<String, ?> registry, Object[] args, Locale locale) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("Pattern=[");
|
||||
buffer.append(pattern);
|
||||
buffer.append("], locale=[");
|
||||
|
|
|
@ -47,7 +47,7 @@ public class DateFormatUtilsTest {
|
|||
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
c.set(2005,0,1,12,0,0);
|
||||
c.setTimeZone(TimeZone.getDefault());
|
||||
StringBuffer buffer = new StringBuffer ();
|
||||
StringBuilder buffer = new StringBuilder ();
|
||||
int year = c.get(Calendar.YEAR);
|
||||
int month = c.get(Calendar.MONTH) + 1;
|
||||
int day = c.get(Calendar.DAY_OF_MONTH);
|
||||
|
@ -71,7 +71,7 @@ public class DateFormatUtilsTest {
|
|||
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
c.set(2005,0,1,12,0,0);
|
||||
c.setTimeZone(TimeZone.getDefault());
|
||||
StringBuffer buffer = new StringBuffer ();
|
||||
StringBuilder buffer = new StringBuilder ();
|
||||
int year = c.get(Calendar.YEAR);
|
||||
int month = c.get(Calendar.MONTH) + 1;
|
||||
int day = c.get(Calendar.DAY_OF_MONTH);
|
||||
|
|
|
@ -347,30 +347,30 @@ public class DurationFormatUtilsTest {
|
|||
// tests the ISO8601-like
|
||||
assertArrayEquals(new DurationFormatUtils.Token[]{
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.H, 1),
|
||||
new DurationFormatUtils.Token(new StringBuffer(":"), 1),
|
||||
new DurationFormatUtils.Token(new StringBuilder(":"), 1),
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.m, 2),
|
||||
new DurationFormatUtils.Token(new StringBuffer(":"), 1),
|
||||
new DurationFormatUtils.Token(new StringBuilder(":"), 1),
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.s, 2),
|
||||
new DurationFormatUtils.Token(new StringBuffer("."), 1),
|
||||
new DurationFormatUtils.Token(new StringBuilder("."), 1),
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.S, 3)}, DurationFormatUtils.lexx("H:mm:ss.SSS"));
|
||||
|
||||
// test the iso extended format
|
||||
assertArrayEquals(new DurationFormatUtils.Token[]{
|
||||
new DurationFormatUtils.Token(new StringBuffer("P"), 1),
|
||||
new DurationFormatUtils.Token(new StringBuilder("P"), 1),
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.y, 4),
|
||||
new DurationFormatUtils.Token(new StringBuffer("Y"), 1),
|
||||
new DurationFormatUtils.Token(new StringBuilder("Y"), 1),
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.M, 1),
|
||||
new DurationFormatUtils.Token(new StringBuffer("M"), 1),
|
||||
new DurationFormatUtils.Token(new StringBuilder("M"), 1),
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.d, 1),
|
||||
new DurationFormatUtils.Token(new StringBuffer("DT"), 1),
|
||||
new DurationFormatUtils.Token(new StringBuilder("DT"), 1),
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.H, 1),
|
||||
new DurationFormatUtils.Token(new StringBuffer("H"), 1),
|
||||
new DurationFormatUtils.Token(new StringBuilder("H"), 1),
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.m, 1),
|
||||
new DurationFormatUtils.Token(new StringBuffer("M"), 1),
|
||||
new DurationFormatUtils.Token(new StringBuilder("M"), 1),
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.s, 1),
|
||||
new DurationFormatUtils.Token(new StringBuffer("."), 1),
|
||||
new DurationFormatUtils.Token(new StringBuilder("."), 1),
|
||||
new DurationFormatUtils.Token(DurationFormatUtils.S, 1),
|
||||
new DurationFormatUtils.Token(new StringBuffer("S"), 1)}, DurationFormatUtils
|
||||
new DurationFormatUtils.Token(new StringBuilder("S"), 1)}, DurationFormatUtils
|
||||
.lexx(DurationFormatUtils.ISO_EXTENDED_FORMAT_PATTERN));
|
||||
|
||||
// test failures in equals
|
||||
|
|
Loading…
Reference in New Issue