001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.theme.properties; 021 022import java.util.ArrayList; 023import java.util.Collections; 024import java.util.Enumeration; 025import java.util.List; 026import java.util.Properties; 027 028public class OrderedProperties extends Properties { 029 030 private static final long serialVersionUID = 1L; 031 032 private final List<Object> order; 033 034 public OrderedProperties() { 035 order = new ArrayList<Object>(); 036 } 037 038 @Override 039 public Enumeration<Object> propertyNames() { 040 return Collections.enumeration(order); 041 } 042 043 @Override 044 public Object put(Object key, Object value) { 045 if (order.contains(key)) { 046 order.remove(key); 047 } 048 order.add(key); 049 return super.put(key, value); 050 } 051 052 @Override 053 public Object remove(Object key) { 054 order.remove(key); 055 return super.remove(key); 056 } 057 058}