Skip to content
Snippets Groups Projects
Commit bd537bed authored by srosse's avatar srosse
Browse files
parents 43bacc24 87528999
No related branches found
No related tags found
No related merge requests found
...@@ -28,8 +28,10 @@ import java.util.ArrayList; ...@@ -28,8 +28,10 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.TreeMap;
/** /**
* Description:<br> * Description:<br>
...@@ -51,8 +53,12 @@ import java.util.Set; ...@@ -51,8 +53,12 @@ import java.util.Set;
* @author gnaegi * @author gnaegi
*/ */
public class SortedProperties extends Properties { public class SortedProperties extends Properties {
private static final long serialVersionUID = -5930211273975255180L;
/** /**
* Overriden to be able to write properties sorted by keys to the disk * Override to be able to write properties sorted by keys
* to the disk (only Java 8)
* *
* @see java.util.Hashtable#keys() * @see java.util.Hashtable#keys()
*/ */
...@@ -61,7 +67,20 @@ public class SortedProperties extends Properties { ...@@ -61,7 +67,20 @@ public class SortedProperties extends Properties {
public synchronized Enumeration<Object> keys() { public synchronized Enumeration<Object> keys() {
// sort elements based on detector (prop key) names // sort elements based on detector (prop key) names
Set set = keySet(); Set set = keySet();
return (Enumeration<Object>)sortKeys(set); return sortKeys(set);
}
/**
* Override to be able to write properties sorted by keys
* to the disk (Java 11)
*/
@Override
public Set<Entry<Object, Object>> entrySet() {
TreeMap<Object,Object> map = new TreeMap<>();
for(Object propertyName:keySet()) {
map.put(propertyName, get(propertyName));
}
return map.entrySet();
} }
/** /**
...@@ -74,7 +93,7 @@ public class SortedProperties extends Properties { ...@@ -74,7 +93,7 @@ public class SortedProperties extends Properties {
* @return non null list wich contains all given keys, sorted * @return non null list wich contains all given keys, sorted
* lexicographically. The list may be empty if given set was empty * lexicographically. The list may be empty if given set was empty
*/ */
static public Enumeration<?> sortKeys(Set<String> keySet) { public static Enumeration<?> sortKeys(Set<String> keySet) {
List<String> sortedList = new ArrayList<>(); List<String> sortedList = new ArrayList<>();
sortedList.addAll(keySet); sortedList.addAll(keySet);
Collections.sort(sortedList); Collections.sort(sortedList);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment