Show TOC

Background documentationUtility Class OrderedProperties Locate this document in the navigation structure

 

Syntax Syntax

  1. import java.util.*;
  2. import java.io.*;
  3. public class OrderedProperties extends java.util.Properties {
  4.    ArrayList orderedKeys = new ArrayList();
  5.   public OrderedProperties() {
  6.     super();
  7.   }
  8.   public OrderedProperties(java.util.Properties defaults) {
  9.     super(defaults);
  10.   }
  11.   public synchronized Iterator getKeysIterator() {
  12.     return orderedKeys.iterator();
  13.   }
  14.   public static OrderedProperties load(String name)
  15.                                   throws IOException {
  16.     OrderedProperties props = null;
  17.     java.io.InputStream is =
  18.       OrderedProperties.class.getResourceAsStream(name);
  19.     if ( is != null ) {
  20.       props = new OrderedProperties();
  21.       props.load(is);
  22.       return props;
  23.     } else {
  24.       if ( ! name.startsWith("/") ) {
  25.         return load("/" + name);
  26.       } else {
  27.         throw new IOException("Properties could not be loaded.");
  28.       }
  29.     }
  30.  }
  31.  public synchronized Object put(Object key, Object value) {
  32.    Object obj = super.put(key, value);
  33.    orderedKeys.add(key);
  34.    return obj;
  35.  }
  36.  public synchronized Object remove(Object key) {
  37.    Object obj = super.remove(key);
  38.    orderedKeys.remove(key);
  39.    return obj;
  40.  }
  41. }
End of the code.