Skip to content

Commit 366ee98

Browse files
committed
[ISSUE 3203] Replace the class 'StringBuffer' by 'StringBuilder'
1 parent 9e8fea9 commit 366ee98

File tree

13 files changed

+54
-21
lines changed

13 files changed

+54
-21
lines changed

acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public RangeRemoteAddressStrategy(String remoteAddr) {
167167
String[] strArray = StringUtils.split(remoteAddr, ".");
168168
if (analysis(strArray, 1) || analysis(strArray, 2) || analysis(strArray, 3)) {
169169
AclUtils.verify(remoteAddr, index - 1);
170-
StringBuffer sb = new StringBuffer();
170+
StringBuilder sb = new StringBuilder();
171171
for (int j = 0; j < index; j++) {
172172
sb.append(strArray[j].trim()).append(".");
173173
}

common/src/main/java/org/apache/rocketmq/common/UtilAll.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,11 @@ public static String list2String(List<String> list, String splitor) {
565565
if (list == null || list.size() == 0) {
566566
return null;
567567
}
568-
StringBuffer str = new StringBuffer();
568+
StringBuilder str = new StringBuilder();
569569
for (int i = 0; i < list.size(); i++) {
570570
str.append(list.get(i));
571571
if (i == list.size() - 1) {
572-
continue;
572+
break;
573573
}
574574
str.append(splitor);
575575
}

common/src/main/java/org/apache/rocketmq/common/message/Message.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ public Message(String topic, String tags, String keys, int flag, byte[] body, bo
4343
this.flag = flag;
4444
this.body = body;
4545

46-
if (tags != null && tags.length() > 0)
46+
if (tags != null && tags.length() > 0) {
4747
this.setTags(tags);
48+
}
4849

49-
if (keys != null && keys.length() > 0)
50+
if (keys != null && keys.length() > 0) {
5051
this.setKeys(keys);
52+
}
5153

5254
this.setWaitStoreMsgOK(waitStoreMsgOK);
5355
}
@@ -127,7 +129,7 @@ public String getKeys() {
127129
}
128130

129131
public void setKeys(Collection<String> keys) {
130-
StringBuffer sb = new StringBuffer();
132+
StringBuilder sb = new StringBuilder();
131133
for (String k : keys) {
132134
sb.append(k);
133135
sb.append(MessageConst.KEY_SEPARATOR);
@@ -151,8 +153,9 @@ public void setDelayTimeLevel(int level) {
151153

152154
public boolean isWaitStoreMsgOK() {
153155
String result = this.getProperty(MessageConst.PROPERTY_WAIT_STORE_MSG_OK);
154-
if (null == result)
156+
if (null == result) {
155157
return true;
158+
}
156159

157160
return Boolean.parseBoolean(result);
158161
}

common/src/main/java/org/apache/rocketmq/common/protocol/NamespaceUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static String wrapNamespaceAndRetry(String namespace, String consumerGrou
120120
return null;
121121
}
122122

123-
return new StringBuffer()
123+
return new StringBuilder()
124124
.append(MixAll.RETRY_GROUP_TOPIC_PREFIX)
125125
.append(wrapNamespace(namespace, consumerGroup))
126126
.toString();

common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919

2020
import java.net.InetAddress;
2121
import java.net.UnknownHostException;
22+
import java.util.Arrays;
23+
import java.util.Collections;
24+
import java.util.List;
2225
import java.util.Properties;
2326
import org.junit.Test;
2427

2528
import static org.assertj.core.api.Assertions.assertThat;
2629
import static org.assertj.core.api.Assertions.within;
30+
import static org.junit.Assert.assertEquals;
2731

2832
public class UtilAllTest {
2933

@@ -109,6 +113,15 @@ public void testIPv6Check() throws UnknownHostException {
109113
assertThat(UtilAll.ipToIPv6Str(nonInternal.getAddress()).toUpperCase()).isEqualTo("2408:4004:0180:8100:3FAA:1DDE:2B3F:898A");
110114
}
111115

116+
@Test
117+
public void testList2String() {
118+
List<String> list = Arrays.asList("groupA=DENY", "groupB=PUB|SUB", "groupC=SUB");
119+
String comma = ",";
120+
assertEquals("groupA=DENY,groupB=PUB|SUB,groupC=SUB", UtilAll.list2String(list, comma));
121+
assertEquals(null, UtilAll.list2String(null, comma));
122+
assertEquals(null, UtilAll.list2String(Collections.emptyList(), comma));
123+
}
124+
112125
static class DemoConfig {
113126
private int demoWidth = 0;
114127
private int demoLength = 0;

common/src/test/java/org/apache/rocketmq/common/utils/IOTinyUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void testCopy() throws Exception {
8282

8383
@Test
8484
public void testReadLines() throws Exception {
85-
StringBuffer sb = new StringBuffer();
85+
StringBuilder sb = new StringBuilder();
8686
for (int i = 0; i < 10; i++) {
8787
sb.append("testReadLines").append("\n");
8888
}
@@ -95,7 +95,7 @@ public void testReadLines() throws Exception {
9595

9696
@Test
9797
public void testToBufferedReader() throws Exception {
98-
StringBuffer sb = new StringBuffer();
98+
StringBuilder sb = new StringBuilder();
9999
for (int i = 0; i < 10; i++) {
100100
sb.append("testToBufferedReader").append("\n");
101101
}

filter/src/main/java/org/apache/rocketmq/filter/expression/UnaryExpression.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public UnaryExpression(Expression left, UnaryType unaryType) {
5353

5454
public static Expression createNegate(Expression left) {
5555
return new UnaryExpression(left, UnaryType.NEGATE) {
56+
@Override
5657
public Object evaluate(EvaluationContext context) throws Exception {
5758
Object rvalue = right.evaluate(context);
5859
if (rvalue == null) {
@@ -64,6 +65,7 @@ public Object evaluate(EvaluationContext context) throws Exception {
6465
return null;
6566
}
6667

68+
@Override
6769
public String getExpressionSymbol() {
6870
return "-";
6971
}
@@ -85,6 +87,7 @@ public static BooleanExpression createInExpression(PropertyExpression right, Lis
8587
final Collection inList = t;
8688

8789
return new UnaryInExpression(right, UnaryType.IN, inList, not) {
90+
@Override
8891
public Object evaluate(EvaluationContext context) throws Exception {
8992

9093
Object rvalue = right.evaluate(context);
@@ -103,8 +106,9 @@ public Object evaluate(EvaluationContext context) throws Exception {
103106

104107
}
105108

109+
@Override
106110
public String toString() {
107-
StringBuffer answer = new StringBuffer();
111+
StringBuilder answer = new StringBuilder();
108112
answer.append(right);
109113
answer.append(" ");
110114
answer.append(getExpressionSymbol());
@@ -124,6 +128,7 @@ public String toString() {
124128
return answer.toString();
125129
}
126130

131+
@Override
127132
public String getExpressionSymbol() {
128133
if (not) {
129134
return "NOT IN";
@@ -139,6 +144,7 @@ public BooleanUnaryExpression(Expression left, UnaryType unaryType) {
139144
super(left, unaryType);
140145
}
141146

147+
@Override
142148
public boolean matches(EvaluationContext context) throws Exception {
143149
Object object = evaluate(context);
144150
return object != null && object == Boolean.TRUE;
@@ -147,6 +153,7 @@ public boolean matches(EvaluationContext context) throws Exception {
147153

148154
public static BooleanExpression createNOT(BooleanExpression left) {
149155
return new BooleanUnaryExpression(left, UnaryType.NOT) {
156+
@Override
150157
public Object evaluate(EvaluationContext context) throws Exception {
151158
Boolean lvalue = (Boolean) right.evaluate(context);
152159
if (lvalue == null) {
@@ -155,6 +162,7 @@ public Object evaluate(EvaluationContext context) throws Exception {
155162
return lvalue.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
156163
}
157164

165+
@Override
158166
public String getExpressionSymbol() {
159167
return "NOT";
160168
}
@@ -163,6 +171,7 @@ public String getExpressionSymbol() {
163171

164172
public static BooleanExpression createBooleanCast(Expression left) {
165173
return new BooleanUnaryExpression(left, UnaryType.BOOLEANCAST) {
174+
@Override
166175
public Object evaluate(EvaluationContext context) throws Exception {
167176
Object rvalue = right.evaluate(context);
168177
if (rvalue == null) {
@@ -174,10 +183,12 @@ public Object evaluate(EvaluationContext context) throws Exception {
174183
return ((Boolean) rvalue).booleanValue() ? Boolean.TRUE : Boolean.FALSE;
175184
}
176185

186+
@Override
177187
public String toString() {
178188
return right.toString();
179189
}
180190

191+
@Override
181192
public String getExpressionSymbol() {
182193
return "";
183194
}
@@ -233,20 +244,23 @@ public void setUnaryType(UnaryType unaryType) {
233244
/**
234245
* @see Object#toString()
235246
*/
247+
@Override
236248
public String toString() {
237249
return "(" + getExpressionSymbol() + " " + right.toString() + ")";
238250
}
239251

240252
/**
241253
* @see Object#hashCode()
242254
*/
255+
@Override
243256
public int hashCode() {
244257
return toString().hashCode();
245258
}
246259

247260
/**
248261
* @see Object#equals(Object)
249262
*/
263+
@Override
250264
public boolean equals(Object o) {
251265

252266
if (o == null || !this.getClass().equals(o.getClass())) {

filter/src/main/java/org/apache/rocketmq/filter/parser/ParseException.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static String initialise(Token currentToken,
106106
int[][] expectedTokenSequences,
107107
String[] tokenImage) {
108108
String eol = System.getProperty("line.separator", "\n");
109-
StringBuffer expected = new StringBuffer();
109+
StringBuilder expected = new StringBuilder();
110110
int maxSize = 0;
111111
for (int i = 0; i < expectedTokenSequences.length; i++) {
112112
if (maxSize < expectedTokenSequences[i].length) {
@@ -123,8 +123,9 @@ private static String initialise(Token currentToken,
123123
String retval = "Encountered \"";
124124
Token tok = currentToken.next;
125125
for (int i = 0; i < maxSize; i++) {
126-
if (i != 0)
126+
if (i != 0) {
127127
retval += " ";
128+
}
128129
if (tok.kind == 0) {
129130
retval += tokenImage[0];
130131
break;
@@ -157,7 +158,7 @@ private static String initialise(Token currentToken,
157158
* string literal.
158159
*/
159160
static String add_escapes(String str) {
160-
StringBuffer retval = new StringBuffer();
161+
StringBuilder retval = new StringBuilder();
161162
char ch;
162163
for (int i = 0; i < str.length(); i++) {
163164
switch (str.charAt(i)) {

filter/src/main/java/org/apache/rocketmq/filter/parser/TokenMgrError.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class TokenMgrError extends Error {
6666
* equivalents in the given string
6767
*/
6868
protected static final String addEscapes(String str) {
69-
StringBuffer retval = new StringBuffer();
69+
StringBuilder retval = new StringBuilder();
7070
char ch;
7171
for (int i = 0; i < str.length(); i++) {
7272
switch (str.charAt(i)) {
@@ -141,6 +141,7 @@ protected static String LexicalError(boolean eofSeen, int lexState, int errorLin
141141
* <p/>
142142
* from this method for such cases in the release version of your parser.
143143
*/
144+
@Override
144145
public String getMessage() {
145146
return super.getMessage();
146147
}

filter/src/test/java/org/apache/rocketmq/filter/ParserTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void testParse_decimalOverFlow() {
8484
@Test
8585
public void testParse_floatOverFlow() {
8686
try {
87-
StringBuffer sb = new StringBuffer(210000);
87+
StringBuilder sb = new StringBuilder(210000);
8888
sb.append("1");
8989
for (int i = 0; i < 2048; i ++) {
9090
sb.append("111111111111111111111111111111111111111111111111111");

0 commit comments

Comments
 (0)