001package jmri.util;
002
003import java.util.Collections;
004import java.util.Enumeration;
005import java.util.Properties;
006import java.util.Set;
007import java.util.TreeSet;
008
009/**
010 * {@link java.util.Properties} implementation that enumerates properties sorted
011 * by key.
012 *
013 * See
014 * <a href="http://stackoverflow.com/a/3253071/176160">http://stackoverflow.com/a/3253071/176160</a>
015 *
016 * @author Randall Wood
017 */
018public class OrderedProperties extends Properties {
019
020    @Override
021    public Set<Object> keySet() {
022        return Collections.unmodifiableSet(new TreeSet<Object>(super.keySet()));
023    }
024
025    @Override
026    public synchronized Enumeration<Object> keys() {
027        return Collections.enumeration(new TreeSet<Object>(super.keySet()));
028    }
029}