From 78bd34769f0607a11152897fe13621bf159b0814 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 2 May 2026 09:54:23 +0200 Subject: [PATCH] Simplify SortedProperties.entrySet() Use Comparator.comparing() and Collectors.toCollection() to make the method much more obvious. Signed-off-by: Robert Varga --- .../karaf/tools/utils/SortedProperties.java | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/tooling/utils/src/main/java/org/apache/karaf/tools/utils/SortedProperties.java b/tooling/utils/src/main/java/org/apache/karaf/tools/utils/SortedProperties.java index 6658dc2b032..ae5ecc37092 100644 --- a/tooling/utils/src/main/java/org/apache/karaf/tools/utils/SortedProperties.java +++ b/tooling/utils/src/main/java/org/apache/karaf/tools/utils/SortedProperties.java @@ -19,12 +19,12 @@ import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.TreeSet; +import java.util.stream.Collectors; /** * Sort properties for better readability. @@ -40,28 +40,13 @@ public Set keySet() { @Override public Set> entrySet() { - Set> origSet = super.entrySet(); - Set> sortedSet = new LinkedHashSet>(origSet.size()); - - Iterator> iterator = origSet.stream().sorted(new Comparator>() { - - @Override - public int compare(java.util.Map.Entry o1, java.util.Map.Entry o2) { - return o1.getKey().toString().compareTo(o2.getKey().toString()); - } - }).iterator(); - - while (iterator.hasNext()) - sortedSet.add(iterator.next()); - - return sortedSet; + return super.entrySet().stream() + .sorted(Comparator.comparing(entry -> entry.getKey().toString())) + .collect(Collectors.toCollection(LinkedHashSet::new)); } @Override public synchronized Enumeration keys() { return Collections.enumeration(new TreeSet<>(super.keySet())); } - - - }