This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git


The following commit(s) were added to refs/heads/master by this push:
     new c1f2623  Reimplement SortedProperties#keys() a la Java 8.
c1f2623 is described below

commit c1f262302cf6984865066f02d1e76e026ceb4190
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Sep 28 10:44:45 2021 -0400

    Reimplement SortedProperties#keys() a la Java 8.
---
 .../collections4/properties/SortedProperties.java  | 24 ++++++++++------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/collections4/properties/SortedProperties.java
 
b/src/main/java/org/apache/commons/collections4/properties/SortedProperties.java
index 3ccb2e1..5147c55 100644
--- 
a/src/main/java/org/apache/commons/collections4/properties/SortedProperties.java
+++ 
b/src/main/java/org/apache/commons/collections4/properties/SortedProperties.java
@@ -18,15 +18,14 @@
 package org.apache.commons.collections4.properties;
 
 import java.util.AbstractMap;
-import java.util.ArrayList;
-import java.util.Collections;
+import java.util.AbstractMap.SimpleEntry;
 import java.util.Enumeration;
 import java.util.LinkedHashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.apache.commons.collections4.iterators.IteratorEnumeration;
 
@@ -43,18 +42,17 @@ public class SortedProperties extends Properties {
     private static final long serialVersionUID = 1L;
 
     @Override
-    public synchronized Enumeration<Object> keys() {
-        return new 
IteratorEnumeration<>(keySet().stream().map(Object::toString).sorted().collect(Collectors.toList()).iterator());
+    public Set<Map.Entry<Object, Object>> entrySet() {
+        final Stream<SimpleEntry<Object, Object>> stream = sortedKeys().map(k 
-> new AbstractMap.SimpleEntry<>(k, getProperty(k)));
+        return stream.collect(Collectors.toCollection(LinkedHashSet::new));
     }
 
     @Override
-    public Set<Map.Entry<Object, Object>> entrySet() {
-        final Enumeration<Object> keys = keys();
-        final Set<Map.Entry<Object, Object>> entrySet = new LinkedHashSet<>();
-        while (keys.hasMoreElements()) {
-            final Object key = keys.nextElement();
-            entrySet.add(new AbstractMap.SimpleEntry<>(key, 
getProperty((String) key)));
-        }
-        return entrySet;
+    public synchronized Enumeration<Object> keys() {
+        return new 
IteratorEnumeration<>(sortedKeys().collect(Collectors.toList()).iterator());
+    }
+
+    private Stream<String> sortedKeys() {
+        return keySet().stream().map(Object::toString).sorted();
     }
 }

Reply via email to