BATCH-2407 Use StringBuilder instead of StringBuffer
With Java 1.5 StringBuilder is preferred over StringBuffer for single threaded access as is has less overhead. This is evidenced by the class comment of StringBuffer and Effective Java 2nd Edition Item 67: Avoid excessive synchronization. > The StringBuilder class should generally be used in preference to > this one, as it supports all of the same operations but it is faster, > as it performs no synchronization. - replace StringBuffer with StringBuilder where possible Issue: BATCH-2407
This commit is contained in:
committed by
Michael Minella
parent
7092102748
commit
dcc9da8273
@@ -99,7 +99,7 @@ final class PropertyMatches {
|
||||
* indicating the possible property matches.
|
||||
*/
|
||||
public String buildErrorMessage() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("Bean property '");
|
||||
buf.append(this.propertyName);
|
||||
buf.append("' is not writable or has an invalid setter method. ");
|
||||
|
||||
@@ -98,7 +98,7 @@ public class RangeArrayPropertyEditor extends PropertyEditorSupport {
|
||||
public String getAsText() {
|
||||
Range[] ranges = (Range[])getValue();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
if(i>0) {
|
||||
|
||||
@@ -59,7 +59,7 @@ public class SpringValidator<T> implements Validator<T>, InitializingBean {
|
||||
* @return string of field errors followed by global errors.
|
||||
*/
|
||||
private String errorsToString(Errors errors) {
|
||||
StringBuffer builder = new StringBuffer();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
appendCollection(errors.getFieldErrors(), builder);
|
||||
appendCollection(errors.getGlobalErrors(), builder);
|
||||
@@ -71,7 +71,7 @@ public class SpringValidator<T> implements Validator<T>, InitializingBean {
|
||||
* Append the string representation of elements of the collection (separated
|
||||
* by new lines) to the given StringBuilder.
|
||||
*/
|
||||
private void appendCollection(Collection<?> collection, StringBuffer builder) {
|
||||
private void appendCollection(Collection<?> collection, StringBuilder builder) {
|
||||
for (Object value : collection) {
|
||||
builder.append("\n");
|
||||
builder.append(value.toString());
|
||||
|
||||
@@ -151,7 +151,7 @@ public class SynchronizedAttributeAccessor implements AttributeAccessor {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer("SynchronizedAttributeAccessor: [");
|
||||
StringBuilder buffer = new StringBuilder("SynchronizedAttributeAccessor: [");
|
||||
synchronized (support) {
|
||||
String[] names = attributeNames();
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
|
||||
@@ -70,7 +70,7 @@ public class MethodInvokerUtils {
|
||||
* @return String
|
||||
*/
|
||||
public static String getParamTypesString(Class<?>... paramTypes) {
|
||||
StringBuffer paramTypesList = new StringBuffer("(");
|
||||
StringBuilder paramTypesList = new StringBuilder("(");
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
paramTypesList.append(paramTypes[i].getSimpleName());
|
||||
if (i + 1 < paramTypes.length) {
|
||||
|
||||
@@ -88,11 +88,11 @@ public class TransactionAwareBufferedWriter extends Writer {
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private StringBuffer getCurrentBuffer() {
|
||||
private StringBuilder getCurrentBuffer() {
|
||||
|
||||
if (!TransactionSynchronizationManager.hasResource(bufferKey)) {
|
||||
|
||||
TransactionSynchronizationManager.bindResource(bufferKey, new StringBuffer());
|
||||
TransactionSynchronizationManager.bindResource(bufferKey, new StringBuilder());
|
||||
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
||||
@Override
|
||||
@@ -113,7 +113,7 @@ public class TransactionAwareBufferedWriter extends Writer {
|
||||
}
|
||||
|
||||
private void complete() throws IOException {
|
||||
StringBuffer buffer = (StringBuffer) TransactionSynchronizationManager.getResource(bufferKey);
|
||||
StringBuilder buffer = (StringBuilder) TransactionSynchronizationManager.getResource(bufferKey);
|
||||
if (buffer != null) {
|
||||
String string = buffer.toString();
|
||||
byte[] bytes = string.getBytes(encoding);
|
||||
@@ -145,7 +145,7 @@ public class TransactionAwareBufferedWriter extends Writer {
|
||||
|
||||
}
|
||||
|
||||
return (StringBuffer) TransactionSynchronizationManager.getResource(bufferKey);
|
||||
return (StringBuilder) TransactionSynchronizationManager.getResource(bufferKey);
|
||||
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ public class TransactionAwareBufferedWriter extends Writer {
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuffer buffer = getCurrentBuffer();
|
||||
StringBuilder buffer = getCurrentBuffer();
|
||||
buffer.append(cbuf, off, len);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user