summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/main
diff options
context:
space:
mode:
authorThomas <>2021-03-12 15:43:57 +0100
committerThomas <>2021-03-12 15:43:57 +0100
commit7864448fd040b26b5921cfc63afa68ef2cb90c03 (patch)
treec2fdb77b4d3cbf02af1da0892ad1143983f3c3fa /eaaf_core_utils/src/main
parent391bc8546bf5bc9a6396378ebec50a7e35031adc (diff)
downloadEAAF-Components-7864448fd040b26b5921cfc63afa68ef2cb90c03.tar.gz
EAAF-Components-7864448fd040b26b5921cfc63afa68ef2cb90c03.tar.bz2
EAAF-Components-7864448fd040b26b5921cfc63afa68ef2cb90c03.zip
refactor some code to Java Stream API
Diffstat (limited to 'eaaf_core_utils/src/main')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java39
1 files changed, 15 insertions, 24 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java
index 0c5eeb40..49ef80e9 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/KeyValueUtils.java
@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -154,18 +155,14 @@ public class KeyValueUtils {
* null
*/
public static Map<String, String> removePrefixFromKeys(final Map<String, String> keys,
- final String prefix) {
- final Map<String, String> result = new HashMap<>();
- final Iterator<Entry<String, String>> interator = keys.entrySet().iterator();
- while (interator.hasNext()) {
- final Entry<String, String> el = interator.next();
- final String newKey = removePrefixFromKey(el.getKey(), prefix);
- if (StringUtils.isNotEmpty(newKey)) {
- result.put(newKey, el.getValue());
- }
- }
-
- return result;
+ final String prefix) {
+ return keys.entrySet().stream()
+ .filter(el -> StringUtils.isNotEmpty(removePrefixFromKey(el.getKey(), prefix)))
+ .collect(Collectors.toMap(
+ el -> removePrefixFromKey(el.getKey(), prefix),
+ el -> el.getValue()));
+
+
}
/**
@@ -351,19 +348,13 @@ public class KeyValueUtils {
* @return Map of Key / Value pairs, but never null
*/
public static Map<String, String> convertListToMap(final List<String> elements) {
- final Map<String, String> map = new HashMap<>();
- for (final String el : elements) {
- if (el.contains(KEYVVALUEDELIMITER)) {
- final String[] split = el.split(KEYVVALUEDELIMITER);
- map.put(split[0], split[1]);
-
- } else {
- log.debug("Key/Value Mapper: '" + el + "' contains NO '='. Ignore it.");
- }
-
- }
+ return elements.stream()
+ .filter(el -> el.contains(KEYVVALUEDELIMITER))
+ .map(el -> el.split(KEYVVALUEDELIMITER))
+ .collect(Collectors.toMap(
+ el -> el[0],
+ el -> el[1]));
- return map;
}
/**