1818package org .apache .commons .collections4 .properties ;
1919
2020import java .util .AbstractMap ;
21- import java .util .AbstractMap .SimpleEntry ;
2221import java .util .Collections ;
2322import java .util .Enumeration ;
2423import java .util .LinkedHashSet ;
3029import java .util .stream .Collectors ;
3130import 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