1 /*
2 * #%L
3 * Nuiton Utils
4 * %%
5 * Copyright (C) 2004 - 2010 CodeLutin
6 * %%
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Lesser Public License for more details.
16 *
17 * You should have received a copy of the GNU General Lesser Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20 * #L%
21 */
22
23 package org.nuiton.util;
24
25 import java.util.Collections;
26 import java.util.Enumeration;
27 import java.util.List;
28 import java.util.Properties;
29 import java.util.Vector;
30
31 /**
32 * Permet d'avoir les propriétés triées.
33 *
34 * @author Julien Ruchaud - ruchaud@codelutin.com
35 *
36 */
37 public class SortedProperties extends Properties {
38
39 private static final long serialVersionUID = -1147150444452577558L;
40
41
42 public SortedProperties() {
43 }
44
45 public SortedProperties(Properties defaults) {
46 super(defaults);
47 }
48
49 @Override
50 public synchronized Enumeration<Object> keys() {
51 List<Object> objects = Collections.list(super.keys());
52 Vector<Object> result;
53 try {
54 // Attention, si les clef ne sont pas des string, ca ne marchera pas
55 List<String> list = CollectionUtil.toGenericList(objects,
56 String.class);
57 Collections.sort(list);
58 result = new Vector<Object>(list);
59 } catch (IllegalArgumentException e) {
60 // keys are not string !!!
61 // can not sort keys
62 result = new Vector<Object>(objects);
63 }
64 return result.elements();
65 }
66 }