All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nuiton.util.SortedProperties Maven / Gradle / Ivy

There is a newer version: 3.1
Show newest version
/*
 * #%L
 * Nuiton Utils
 * %%
 * Copyright (C) 2004 - 2010 CodeLutin
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * .
 * #L%
 */

package org.nuiton.util;

import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.Vector;

/**
 * Permet d'avoir les propriétés triées.
 *
 * @author Julien Ruchaud - [email protected]
 *
 */
public class SortedProperties extends Properties {

    private static final long serialVersionUID = -1147150444452577558L;


    public SortedProperties() {
    }

    public SortedProperties(Properties defaults) {
        super(defaults);
    }

    @Override
    public synchronized Enumeration keys() {
        List objects = Collections.list(super.keys());
        Vector result;
        try {
            // Attention, si les clef ne sont pas des string, ca ne marchera pas
            List list = CollectionUtil.toGenericList(objects,
                                                             String.class);
            Collections.sort(list);
            result = new Vector(list);
        } catch (IllegalArgumentException e) {
            // keys are not string !!!
            // can not sort keys
            result = new Vector(objects);
        }
        return result.elements();
    }
}