Skip to content

Commit 90d5501

Browse files
author
ZhangJian He
authored
[minor] [optimize] Remove redundant toString call (#3254)
1 parent e79da7c commit 90d5501

File tree

37 files changed

+77
-98
lines changed

37 files changed

+77
-98
lines changed

bookkeeper-benchmark/src/main/java/org/apache/bookkeeper/benchmark/BenchThroughputLatency.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ public void process(WatchedEvent event) {
404404
OutputStream fos = new BufferedOutputStream(new FileOutputStream(latencyFile));
405405

406406
for (Long l: latency) {
407-
fos.write((Long.toString(l) + "\t" + (l / 1000000) + "ms\n").getBytes(UTF_8));
407+
fos.write((l + "\t" + (l / 1000000) + "ms\n").getBytes(UTF_8));
408408
}
409409
fos.flush();
410410
fos.close();

bookkeeper-common/src/main/java/org/apache/bookkeeper/common/conf/ComponentConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private Map<String, Object> toMap() {
310310
Map<String, Object> configMap = new HashMap<>();
311311
Iterator<String> iterator = this.getKeys();
312312
while (iterator.hasNext()) {
313-
String key = iterator.next().toString();
313+
String key = iterator.next();
314314
Object property = this.getProperty(key);
315315
if (property != null) {
316316
configMap.put(key, property.toString());

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Cookie.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public String toString() {
167167
}
168168
StringBuilder b = new StringBuilder();
169169
b.append(CURRENT_COOKIE_LAYOUT_VERSION).append("\n");
170-
b.append(builder.build().toString());
170+
b.append(builder.build());
171171
return b.toString();
172172
}
173173

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ journalFormatVersionToWrite, getBufferedChannelBuilder(),
12221222
LOG.info("Journal exits when shutting down");
12231223
} finally {
12241224
// There could be packets queued for forceWrite on this logFile
1225-
// That is fine as this exception is going to anyway take down the
1225+
// That is fine as this exception is going to anyway take down
12261226
// the bookie. If we execute this as a part of graceful shutdown,
12271227
// close will flush the file system cache making any previous
12281228
// cached writes durable so this is fine as well.
@@ -1277,7 +1277,6 @@ private static int fullRead(JournalChannel fc, ByteBuffer bb) throws IOException
12771277
return total;
12781278
}
12791279

1280-
//
12811280
/**
12821281
* Wait for the Journal thread to exit.
12831282
* This is method is needed in order to mock the journal, we can't mock final method of java.lang.Thread class

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@
2323

2424
import static java.nio.charset.StandardCharsets.UTF_8;
2525

26-
import com.google.common.annotations.VisibleForTesting;
27-
2826
import java.io.Closeable;
2927
import java.io.File;
3028
import java.io.IOException;
31-
import java.io.RandomAccessFile;
3229
import java.nio.ByteBuffer;
3330
import java.nio.channels.FileChannel;
3431
import java.util.Arrays;
@@ -58,7 +55,7 @@ class JournalChannel implements Closeable {
5855

5956
static final int SECTOR_SIZE = 512;
6057
private static final int START_OF_FILE = -12345;
61-
private static long cacheDropLagBytes = 8 * MB;
58+
private static final long cacheDropLagBytes = 8 * MB;
6259

6360
// No header
6461
static final int V1 = 1;
@@ -71,7 +68,7 @@ class JournalChannel implements Closeable {
7168
// 1) expanding header to 512
7269
// 2) Padding writes to align sector size
7370
static final int V5 = 5;
74-
// Adding explicitlac entry
71+
// Adding explicit lac entry
7572
public static final int V6 = 6;
7673

7774
static final int HEADER_SIZE = SECTOR_SIZE; // align header to sector size
@@ -309,12 +306,4 @@ public void forceWrite(boolean forceMetadata) throws IOException {
309306
}
310307
}
311308

312-
@VisibleForTesting
313-
public static FileChannel openFileChannel(RandomAccessFile randomAccessFile) {
314-
if (randomAccessFile == null) {
315-
throw new IllegalArgumentException("Input cannot be null");
316-
}
317-
318-
return randomAccessFile.getChannel();
319-
}
320309
}

bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ private Map<String, Object> toMap() {
12481248
Map<String, Object> configMap = new HashMap<>();
12491249
Iterator<String> iterator = this.getKeys();
12501250
while (iterator.hasNext()) {
1251-
String key = iterator.next().toString();
1251+
String key = iterator.next();
12521252
Object property = this.getProperty(key);
12531253
if (property != null) {
12541254
configMap.put(key, property.toString());

bookkeeper-server/src/main/java/org/apache/bookkeeper/net/AbstractDNSToSwitchMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public Map<String, String> getSwitchMap() {
115115
public String dumpTopology() {
116116
Map<String, String> rack = getSwitchMap();
117117
StringBuilder builder = new StringBuilder();
118-
builder.append("Mapping: ").append(toString()).append("\n");
118+
builder.append("Mapping: ").append(this).append("\n");
119119
if (rack != null) {
120120
builder.append("Map:\n");
121121
Set<String> switches = new HashSet<String>();

bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetworkTopologyImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public void add(Node node) {
421421
Node rack = getNodeForNetworkLocation(node);
422422
if (rack != null && !(rack instanceof InnerNode)) {
423423
LOG.error("Unexpected data node {} at an illegal network location", node);
424-
throw new IllegalArgumentException("Unexpected data node " + node.toString()
424+
throw new IllegalArgumentException("Unexpected data node " + node
425425
+ " at an illegal network location");
426426
}
427427
if (clusterMap.add(node)) {
@@ -436,7 +436,7 @@ public void add(Node node) {
436436
}
437437
}
438438
if (LOG.isDebugEnabled()) {
439-
LOG.debug("NetworkTopology became:\n" + this.toString());
439+
LOG.debug("NetworkTopology became:\n" + this);
440440
}
441441
} finally {
442442
netlock.writeLock().unlock();
@@ -507,7 +507,7 @@ public void remove(Node node) {
507507
}
508508
}
509509
if (LOG.isDebugEnabled()) {
510-
LOG.debug("NetworkTopology became:\n" + this.toString());
510+
LOG.debug("NetworkTopology became:\n" + this);
511511
}
512512
} finally {
513513
netlock.writeLock().unlock();

bookkeeper-server/src/main/java/org/apache/bookkeeper/net/ScriptBasedMapping.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ public List<String> resolve(List<String> names) {
210210

211211
if (m.size() != names.size()) {
212212
// invalid number of entries returned by the script
213-
LOG.error("Script " + scriptName + " returned " + Integer.toString(m.size()) + " values when "
214-
+ Integer.toString(names.size()) + " were expected.");
213+
LOG.error("Script " + scriptName + " returned " + m.size() + " values when "
214+
+ names.size() + " were expected.");
215215
return null;
216216
}
217217
} else {
@@ -239,8 +239,8 @@ private String runResolveCommand(List<String> args) {
239239
StringBuilder allOutput = new StringBuilder();
240240
int numProcessed = 0;
241241
if (maxArgs < MIN_ALLOWABLE_ARGS) {
242-
LOG.warn("Invalid value " + Integer.toString(maxArgs) + " for " + SCRIPT_ARG_COUNT_KEY
243-
+ "; must be >= " + Integer.toString(MIN_ALLOWABLE_ARGS));
242+
LOG.warn("Invalid value " + maxArgs + " for " + SCRIPT_ARG_COUNT_KEY
243+
+ "; must be >= " + MIN_ALLOWABLE_ARGS);
244244
return null;
245245
}
246246

bookkeeper-server/src/main/java/org/apache/bookkeeper/sasl/SaslServerState.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ private SaslServer createSaslServer(final Subject subject, ServerConfiguration s
7878

7979
final String servicePrincipalNameAndHostname = servicePrincipal.getName();
8080
int indexOf = servicePrincipalNameAndHostname.indexOf("/");
81-
final String serviceHostnameAndKerbDomain = servicePrincipalNameAndHostname.substring(indexOf + 1,
82-
servicePrincipalNameAndHostname.length());
81+
final String serviceHostnameAndKerbDomain = servicePrincipalNameAndHostname.substring(indexOf + 1);
8382
int indexOfAt = serviceHostnameAndKerbDomain.indexOf("@");
8483

8584
final String servicePrincipalName, serviceHostname;

0 commit comments

Comments
 (0)