Skip to content

Commit

Permalink
MINOR: Replace Collection.toArray(new T[size]) by Collection.toArray(…
Browse files Browse the repository at this point in the history
…new T[0]) (apache#9750)

This PR is based on the research of https://shipilev.net/blog/2016/arrays-wisdom-ancients

Reviewers: Chia-Ping Tsai <[email protected]>
  • Loading branch information
APaMio authored Dec 21, 2020
1 parent 4e7c789 commit 1670362
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void setReadOnly() {
}

public Header[] toArray() {
return headers.isEmpty() ? Record.EMPTY_HEADERS : headers.toArray(new Header[headers.size()]);
return headers.isEmpty() ? Record.EMPTY_HEADERS : headers.toArray(new Header[0]);
}

private void checkKey(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Frequencies forBooleanValues(MetricName falseMetricName, MetricNam
if (frequencies.isEmpty()) {
throw new IllegalArgumentException("Must specify at least one metric name");
}
Frequency[] frequencyArray = frequencies.toArray(new Frequency[frequencies.size()]);
Frequency[] frequencyArray = frequencies.toArray(new Frequency[0]);
return new Frequencies(2, 0.0, 1.0, frequencyArray);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public SaslClient createSaslClient(String[] mechanisms,
@Override
public String[] getMechanismNames(Map<String, ?> props) {
Collection<String> mechanisms = ScramMechanism.mechanismNames();
return mechanisms.toArray(new String[mechanisms.size()]);
return mechanisms.toArray(new String[0]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public SaslServer createSaslServer(String mechanism, String protocol, String ser
@Override
public String[] getMechanismNames(Map<String, ?> props) {
Collection<String> mechanisms = ScramMechanism.mechanismNames();
return mechanisms.toArray(new String[mechanisms.size()]);
return mechanisms.toArray(new String[0]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void createConnectors(List<String> listeners, List<String> adminListeners
}
}

jettyServer.setConnectors(connectors.toArray(new Connector[connectors.size()]));
jettyServer.setConnectors(connectors.toArray(new Connector[0]));

if (adminListeners != null && !adminListeners.isEmpty()) {
for (String adminListener : adminListeners) {
Expand Down Expand Up @@ -300,7 +300,7 @@ public void initializeResources(Herder herder) {
contextHandlers.add(new DefaultHandler());
contextHandlers.add(requestLogHandler);

handlers.setHandlers(contextHandlers.toArray(new Handler[]{}));
handlers.setHandlers(contextHandlers.toArray(new Handler[0]));
try {
context.start();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected static void configureSslContextFactoryTrustStore(SslContextFactory ssl
@SuppressWarnings("unchecked")
protected static void configureSslContextFactoryAlgorithms(SslContextFactory ssl, Map<String, Object> sslConfigValues) {
List<String> sslEnabledProtocols = (List<String>) getOrDefault(sslConfigValues, SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Arrays.asList(COMMA_WITH_WHITESPACE.split(SslConfigs.DEFAULT_SSL_ENABLED_PROTOCOLS)));
ssl.setIncludeProtocols(sslEnabledProtocols.toArray(new String[sslEnabledProtocols.size()]));
ssl.setIncludeProtocols(sslEnabledProtocols.toArray(new String[0]));

String sslProvider = (String) sslConfigValues.get(SslConfigs.SSL_PROVIDER_CONFIG);
if (sslProvider != null)
Expand All @@ -131,7 +131,7 @@ protected static void configureSslContextFactoryAlgorithms(SslContextFactory ssl

List<String> sslCipherSuites = (List<String>) sslConfigValues.get(SslConfigs.SSL_CIPHER_SUITES_CONFIG);
if (sslCipherSuites != null)
ssl.setIncludeCipherSuites(sslCipherSuites.toArray(new String[sslCipherSuites.size()]));
ssl.setIncludeCipherSuites(sslCipherSuites.toArray(new String[0]));

ssl.setKeyManagerFactoryAlgorithm((String) getOrDefault(sslConfigValues, SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG, SslConfigs.DEFAULT_SSL_KEYMANGER_ALGORITHM));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String[] storeNames() {
final Set<String> stores = new HashSet<>(storeNames1.length + storeNames2.length);
Collections.addAll(stores, storeNames1);
Collections.addAll(stores, storeNames2);
return stores.toArray(new String[stores.size()]);
return stores.toArray(new String[0]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public String[] storeNames() {
final Set<String> stores = new HashSet<>(storeNames1.length + storeNames2.length);
Collections.addAll(stores, storeNames1);
Collections.addAll(stores, storeNames2);
return stores.toArray(new String[stores.size()]);
return stores.toArray(new String[0]);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void writeToTopology(final InternalTopologyBuilder topologyBuilder) {
consumedInternal().timestampExtractor(),
consumedInternal().keyDeserializer(),
consumedInternal().valueDeserializer(),
topicNames().toArray(new String[topicNames().size()]));
topicNames().toArray(new String[0]));

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void shouldReturnMatchedWindowsOrderedByTimestamp() {
final TimeWindows windows = TimeWindows.of(ofMillis(12L)).advanceBy(ofMillis(5L));
final Map<Long, TimeWindow> matched = windows.windowsFor(21L);

final Long[] expected = matched.keySet().toArray(new Long[matched.size()]);
final Long[] expected = matched.keySet().toArray(new Long[0]);
assertEquals(expected[0].longValue(), 10L);
assertEquals(expected[1].longValue(), 15L);
assertEquals(expected[2].longValue(), 20L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void destroyTask(DestroyTaskRequest request) throws Exception {

public TasksResponse tasks(TasksRequest request) throws Exception {
UriBuilder uriBuilder = UriBuilder.fromPath(url("/coordinator/tasks"));
uriBuilder.queryParam("taskId", (Object[]) request.taskIds().toArray(new String[0]));
uriBuilder.queryParam("taskId", request.taskIds().toArray(new Object[0]));
uriBuilder.queryParam("firstStartMs", request.firstStartMs());
uriBuilder.queryParam("lastStartMs", request.lastStartMs());
uriBuilder.queryParam("firstEndMs", request.firstEndMs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ private void enableTrafficControl(Platform platform, String networkDevice, int d
List<String> delay = new ArrayList<>();
rootHandler(networkDevice, delay::add);
netemDelay(delayMs, deviationMs, delay::add);
platform.runCommand(delay.toArray(new String[]{}));
platform.runCommand(delay.toArray(new String[0]));

if (rateLimitKbps > 0) {
List<String> rate = new ArrayList<>();
childHandler(networkDevice, rate::add);
tbfRate(rateLimitKbps, rate::add);
platform.runCommand(rate.toArray(new String[]{}));
platform.runCommand(rate.toArray(new String[0]));
}
} else if (rateLimitKbps > 0) {
List<String> rate = new ArrayList<>();
rootHandler(networkDevice, rate::add);
tbfRate(rateLimitKbps, rate::add);
platform.runCommand(rate.toArray(new String[]{}));
platform.runCommand(rate.toArray(new String[0]));
} else {
log.warn("Not applying any rate limiting or latency");
}
Expand Down

0 comments on commit 1670362

Please sign in to comment.