< prev index next >

src/com/sun/javatest/util/SortedProperties.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


  24  * or visit www.oracle.com if you need additional information or have any
  25  * questions.
  26  */
  27 package com.sun.javatest.util;
  28 
  29 import java.util.Enumeration;
  30 import java.util.Iterator;
  31 import java.util.Properties;
  32 import java.util.Set;
  33 import java.util.TreeSet;
  34 
  35 /**
  36  * A subtype of Properties for which the keys method will return a sorted enumeration.
  37  * This means that the store method will write the various properties in sorted order.
  38  */
  39 public class SortedProperties extends Properties
  40 {
  41     // override Keys() to return a sorted set
  42     public Enumeration<Object> keys() {
  43         Set<Object> s = new TreeSet<>(); // ordered
  44         for (Enumeration e = super.keys(); e.hasMoreElements(); ) {
  45             s.add(e.nextElement());
  46         }
  47 
  48         final Iterator iter = s.iterator();
  49         return new Enumeration<Object>() {
  50                 public boolean hasMoreElements() {
  51                     return iter.hasNext();
  52                 }
  53                 public Object nextElement() {
  54                     return iter.next();
  55                 }
  56             };
  57     }
  58 }


  24  * or visit www.oracle.com if you need additional information or have any
  25  * questions.
  26  */
  27 package com.sun.javatest.util;
  28 
  29 import java.util.Enumeration;
  30 import java.util.Iterator;
  31 import java.util.Properties;
  32 import java.util.Set;
  33 import java.util.TreeSet;
  34 
  35 /**
  36  * A subtype of Properties for which the keys method will return a sorted enumeration.
  37  * This means that the store method will write the various properties in sorted order.
  38  */
  39 public class SortedProperties extends Properties
  40 {
  41     // override Keys() to return a sorted set
  42     public Enumeration<Object> keys() {
  43         Set<Object> s = new TreeSet<>(); // ordered
  44         for (Enumeration<?> e = super.keys(); e.hasMoreElements(); ) {
  45             s.add(e.nextElement());
  46         }
  47 
  48         final Iterator<?> iter = s.iterator();
  49         return new Enumeration<Object>() {
  50                 public boolean hasMoreElements() {
  51                     return iter.hasNext();
  52                 }
  53                 public Object nextElement() {
  54                     return iter.next();
  55                 }
  56             };
  57     }
  58 }
< prev index next >