001    //$$Header: $$
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    
037    package org.deegree.graphics.charts;
038    
039    import java.util.Collection;
040    import java.util.LinkedHashSet;
041    import java.util.Map;
042    import java.util.Set;
043    import java.util.TreeMap;
044    import java.util.TreeSet;
045    
046    /**
047     * A HashMp with keys and values. The difference here is that elements are inserted using a queue structure instead of a
048     * hash function, so that first come first served
049     *
050     * @author <a href="mailto:elmasry@lat-lon.de">Moataz Elmasry</a>
051     * @author last edited by: $Author: elmasri$
052     *
053     * @version $Revision: $, $Date: 28 Mar 2008 11:04:49$
054     * @param <K>
055     * @param <V>
056     */
057    public class QueuedMap<K, V> implements Map<K, V> {
058    
059        /**
060         *
061         */
062        private static final long serialVersionUID = 6497684950402691072L;
063    
064        private Map<K, V> map = null;
065    
066        private LinkedHashSet<K> list = new LinkedHashSet<K>();
067    
068        /**
069         *
070         */
071        public QueuedMap() {
072            map = new TreeMap<K, V>();
073        }
074    
075        /*
076         * (non-Javadoc)
077         *
078         * @see java.util.Map#clear()
079         */
080        public void clear() {
081            list.clear();
082            map.clear();
083    
084        }
085    
086        /*
087         * (non-Javadoc)
088         *
089         * @see java.util.Map#containsKey(java.lang.Object)
090         */
091        public boolean containsKey( Object key ) {
092            return map.containsKey( key );
093        }
094    
095        /*
096         * (non-Javadoc)
097         *
098         * @see java.util.Map#containsValue(java.lang.Object)
099         */
100        public boolean containsValue( Object value ) {
101            return map.containsValue( value );
102        }
103    
104        /*
105         * (non-Javadoc)
106         *
107         * @see java.util.Map#entrySet()
108         */
109        public Set<java.util.Map.Entry<K, V>> entrySet() {
110            return map.entrySet();
111        }
112    
113        /*
114         * (non-Javadoc)
115         *
116         * @see java.util.Map#get(java.lang.Object)
117         */
118        public V get( Object key ) {
119            return map.get( key );
120        }
121    
122        /*
123         * (non-Javadoc)
124         *
125         * @see java.util.Map#isEmpty()
126         */
127        public boolean isEmpty() {
128            return map.isEmpty();
129        }
130    
131        /*
132         * (non-Javadoc)
133         *
134         * @see java.util.Map#keySet()
135         */
136        public Set<K> keySet() {
137            Set<K> set = new TreeSet<K>();
138            set.addAll( list );
139            return set;
140        }
141    
142        /*
143         * (non-Javadoc)
144         *
145         * @see java.util.Map#put(java.lang.Object, java.lang.Object)
146         */
147        public V put( K key, V value ) {
148            list.remove( key );
149            list.add( key );
150            return map.put( key, value );
151        }
152    
153        /*
154         * (non-Javadoc)
155         *
156         * @see java.util.Map#putAll(java.util.Map)
157         */
158        public void putAll( Map<? extends K, ? extends V> t ) {
159            list.addAll( t.keySet() );
160            map.putAll( t );
161    
162        }
163    
164        /*
165         * (non-Javadoc)
166         *
167         * @see java.util.Map#remove(java.lang.Object)
168         */
169        public V remove( Object key ) {
170            list.remove( key );
171            return map.remove( key );
172        }
173    
174        /*
175         * (non-Javadoc)
176         *
177         * @see java.util.Map#size()
178         */
179        public int size() {
180            return map.size();
181        }
182    
183        /*
184         * (non-Javadoc)
185         *
186         * @see java.util.Map#values()
187         */
188        public Collection<V> values() {
189            return map.values();
190        }
191    }