mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-09 11:35:28 +00:00
Reimplement SortedProperties#keys() a la Java 8.
Use final.
This commit is contained in:
parent
78c4b0f865
commit
a18086f23b
@ -26,6 +26,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.collections4.iterators.IteratorEnumeration;
|
import org.apache.commons.collections4.iterators.IteratorEnumeration;
|
||||||
|
|
||||||
@ -43,21 +44,15 @@ public class SortedProperties extends Properties {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Enumeration<Object> keys() {
|
public synchronized Enumeration<Object> keys() {
|
||||||
final Set<Object> keySet = keySet();
|
return new IteratorEnumeration<>(keySet().stream().map(Object::toString).sorted().collect(Collectors.toList()).iterator());
|
||||||
final List<String> keys = new ArrayList<>(keySet.size());
|
|
||||||
for (final Object key : keySet) {
|
|
||||||
keys.add(key.toString());
|
|
||||||
}
|
|
||||||
Collections.sort(keys);
|
|
||||||
return new IteratorEnumeration<>(keys.iterator());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Map.Entry<Object, Object>> entrySet() {
|
public Set<Map.Entry<Object, Object>> entrySet() {
|
||||||
Enumeration<Object> keys = keys();
|
final Enumeration<Object> keys = keys();
|
||||||
Set<Map.Entry<Object, Object>> entrySet = new LinkedHashSet<>();
|
final Set<Map.Entry<Object, Object>> entrySet = new LinkedHashSet<>();
|
||||||
while (keys.hasMoreElements()) {
|
while (keys.hasMoreElements()) {
|
||||||
Object key = keys.nextElement();
|
final Object key = keys.nextElement();
|
||||||
entrySet.add(new AbstractMap.SimpleEntry<>(key, getProperty((String) key)));
|
entrySet.add(new AbstractMap.SimpleEntry<>(key, getProperty((String) key)));
|
||||||
}
|
}
|
||||||
return entrySet;
|
return entrySet;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user