Skip to content

Commit 3ed2a3a

Browse files
committed
Simplify
1 parent 66d3544 commit 3ed2a3a

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/main/java/org/apache/commons/collections4/properties/SortedProperties.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.commons.collections4.properties;
1919

2020
import java.util.AbstractMap;
21-
import java.util.AbstractMap.SimpleEntry;
2221
import java.util.Collections;
2322
import java.util.Enumeration;
2423
import java.util.LinkedHashSet;
@@ -30,8 +29,6 @@
3029
import java.util.stream.Collectors;
3130
import java.util.stream.Stream;
3231

33-
import org.apache.commons.collections4.iterators.IteratorEnumeration;
34-
3532
/**
3633
* A drop-in replacement for {@link Properties} for sorting keys.
3734
* <p>
@@ -54,8 +51,7 @@ public SortedProperties() {
5451

5552
@Override
5653
public Set<Map.Entry<Object, Object>> entrySet() {
57-
final Stream<SimpleEntry<Object, Object>> stream = sortedKeys().map(k -> new AbstractMap.SimpleEntry<>(k, getProperty(k)));
58-
return stream.collect(Collectors.toCollection(LinkedHashSet::new));
54+
return keyStream().map(k -> new AbstractMap.SimpleEntry<>(k, get(k))).collect(Collectors.toCollection(LinkedHashSet::new));
5955
}
6056

6157
/**
@@ -79,27 +75,27 @@ private synchronized TreeSet<String> enumerateStringProperties(final TreeSet<Str
7975
}
8076

8177
@Override
82-
public synchronized void forEach(BiConsumer<? super Object, ? super Object> action) {
83-
keySet().stream().forEach(k -> action.accept(k, get(k)));
78+
public synchronized void forEach(final BiConsumer<? super Object, ? super Object> action) {
79+
keyStream().forEach(k -> action.accept(k, get(k)));
8480
}
8581

8682
@Override
8783
public synchronized Enumeration<Object> keys() {
88-
return new IteratorEnumeration<>(sortedKeys().collect(Collectors.toList()).iterator());
84+
return Collections.enumeration(keySet());
8985
}
9086

9187
@Override
9288
public Set<Object> keySet() {
9389
return new TreeSet<>(super.keySet());
9490
}
9591

96-
@Override
97-
public Enumeration<?> propertyNames() {
98-
return Collections.enumeration(keySet());
92+
private Stream<Object> keyStream() {
93+
return keySet().stream();
9994
}
10095

101-
private Stream<String> sortedKeys() {
102-
return keySet().stream().map(Object::toString);
96+
@Override
97+
public Enumeration<?> propertyNames() {
98+
return Collections.enumeration(stringPropertyNames());
10399
}
104100

105101
@Override

0 commit comments

Comments
 (0)