You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by mw...@apache.org on 2018/08/31 15:05:42 UTC
[accumulo] 02/04: Use streams to remove warnings
This is an automated email from the ASF dual-hosted git repository.
mwalch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git
commit 173b8f9a27175b24a1111c64d2fdefb5b39e9fc8
Author: Christopher Tubbs <ct...@apache.org>
AuthorDate: Wed Aug 29 20:54:21 2018 -0400
Use streams to remove warnings
Small feedback for PR #623: can use streams to avoid warnings or
unnecessary warnings suppression, or excessive casts to String from
Object.
---
.../accumulo/core/conf/SiteConfiguration.java | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java b/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java
index 6e4842a..9512bd2 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java
@@ -23,10 +23,11 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
+import java.util.function.Function;
import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import org.apache.accumulo.core.util.CachedConfiguration;
import org.apache.commons.configuration.CompositeConfiguration;
@@ -93,10 +94,9 @@ public class SiteConfiguration extends AccumuloConfiguration {
}
internalConfig.addConfiguration(config);
- Map<String,String> temp = new HashMap<>();
-
- Iterator<String> iter = internalConfig.getKeys();
- iter.forEachRemaining(key -> temp.put(key, internalConfig.getString(key)));
+ Map<String,String> temp = StreamSupport
+ .stream(((Iterable<?>) internalConfig::getKeys).spliterator(), false).map(String::valueOf)
+ .collect(Collectors.toMap(Function.identity(), internalConfig::getString));
/*
* If any of the configs used in hot codepaths are unset here, set a null so that we'll default
@@ -227,12 +227,9 @@ public class SiteConfiguration extends AccumuloConfiguration {
parent.getProperties(props, filter);
}
- Iterator<String> iter = getConfiguration().getKeys();
- iter.forEachRemaining(key -> {
- if (filter.test(key)) {
- props.put(key, getConfiguration().getString(key));
- }
- });
+ StreamSupport.stream(((Iterable<?>) getConfiguration()::getKeys).spliterator(), false)
+ .map(String::valueOf).filter(filter)
+ .forEach(k -> props.put(k, getConfiguration().getString(k)));
// CredentialProvider should take precedence over site
org.apache.hadoop.conf.Configuration hadoopConf = getHadoopConfiguration();