View Javadoc

1   /*
2    * Copyright 2006-2012 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 de.smartics.maven.plugin.buildmetadata.common;
17  
18  import java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.Enumeration;
21  import java.util.List;
22  import java.util.Properties;
23  
24  /**
25   * Class for sorting properties.
26   *
27   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
28   * @version $Revision: 9143 $
29   */
30  public final class SortedProperties extends Properties
31  {
32    // ********************************* Fields *********************************
33  
34    // --- constants ------------------------------------------------------------
35  
36    /**
37     * The class version identifier.
38     * <p>
39     * The value of this constant is {@value}.
40     * </p>
41     */
42    private static final long serialVersionUID = 1L;
43  
44    // --- members --------------------------------------------------------------
45  
46    // ****************************** Initializer *******************************
47  
48    // ****************************** Constructors ******************************
49  
50    // ****************************** Inner Classes *****************************
51  
52    // ********************************* Methods ********************************
53  
54    // --- init -----------------------------------------------------------------
55  
56    /**
57     * {@inheritDoc}
58     *
59     * @see java.util.Hashtable#keys()
60     */
61    @SuppressWarnings("all")
62    public synchronized Enumeration<Object> keys()
63    {
64      final Enumeration<Object> keysEnum = super.keys();
65      final List keyList = new ArrayList<Object>();
66      while (keysEnum.hasMoreElements())
67      {
68        keyList.add(keysEnum.nextElement());
69      }
70      Collections.sort(keyList);
71      return Collections.enumeration(keyList);
72    }
73  
74    // --- get&set --------------------------------------------------------------
75  
76    // --- business -------------------------------------------------------------
77  
78    /**
79     * Factory method to create an instance of sorted properties.
80     *
81     * @param properties the properties to return a sorted instance for.
82     * @return sorted properties.
83     */
84    public static Properties createSorted(final Properties properties)
85    {
86      final SortedProperties sortedProperties = new SortedProperties();
87      sortedProperties.putAll(properties);
88      return sortedProperties;
89    }
90  
91    // --- object basics --------------------------------------------------------
92  
93  }