001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import java.util.Collections;
018    import java.util.Dictionary;
019    import java.util.Enumeration;
020    import java.util.HashMap;
021    import java.util.Map;
022    
023    /**
024     * @author Shuyang Zhou
025     */
026    public class HashMapDictionary<K, V> extends Dictionary<K, V> {
027    
028            @Override
029            public Enumeration<V> elements() {
030                    return Collections.enumeration(_map.values());
031            }
032    
033            @Override
034            public V get(Object key) {
035                    return _map.get(key);
036            }
037    
038            @Override
039            public boolean isEmpty() {
040                    return _map.isEmpty();
041            }
042    
043            @Override
044            public Enumeration<K> keys() {
045                    return Collections.enumeration(_map.keySet());
046            }
047    
048            @Override
049            public V put(K key, V value) {
050                    return _map.put(key, value);
051            }
052    
053            public void putAll(Map<? extends K, ? extends V> map) {
054                    _map.putAll(map);
055            }
056    
057            @Override
058            public V remove(Object key) {
059                    return _map.remove(key);
060            }
061    
062            @Override
063            public int size() {
064                    return _map.size();
065            }
066    
067            private final Map<K, V> _map = new HashMap<>();
068    
069    }