View Javadoc

1   /**
2    * Copyright 2009-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.mojo.properties;
17  
18  import java.util.Collections;
19  import java.util.Enumeration;
20  import java.util.Properties;
21  import java.util.Vector;
22  
23  /**
24   * Override the keys() method so it returns keys in sorted order. One effect of this is the store() method will write properties to the file
25   * system in sorted order.
26   */
27  public class SortedProperties extends Properties {
28  
29  	/**
30  	 * 
31  	 */
32  	private static final long serialVersionUID = 1330825236411537386L;
33  
34  	@SuppressWarnings({ "rawtypes", "unchecked" })
35  	@Override
36  	public synchronized Enumeration<Object> keys() {
37  		Enumeration keysEnum = super.keys();
38  		Vector keyList = new Vector();
39  		while (keysEnum.hasMoreElements()) {
40  			keyList.add(keysEnum.nextElement());
41  		}
42  		Collections.sort(keyList);
43  		return keyList.elements();
44  	}
45  
46  }