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.concurrent;
016    
017    import java.util.Map;
018    import java.util.concurrent.ConcurrentHashMap;
019    import java.util.concurrent.ConcurrentMap;
020    
021    /**
022     * @author Shuyang Zhou
023     */
024    public class ConcurrentIdentityHashMap<K, V>
025            extends ConcurrentMapperHashMap<K, IdentityKey<K>, V, V> {
026    
027            public ConcurrentIdentityHashMap() {
028                    this(new ConcurrentHashMap<IdentityKey<K>, V>());
029            }
030    
031            public ConcurrentIdentityHashMap(
032                    ConcurrentMap<IdentityKey<K>, V> innerConcurrentMap) {
033    
034                    super(innerConcurrentMap);
035            }
036    
037            public ConcurrentIdentityHashMap(int initialCapacity) {
038                    this(new ConcurrentHashMap<IdentityKey<K>, V>(initialCapacity));
039            }
040    
041            public ConcurrentIdentityHashMap(
042                    int initialCapacity, float loadFactor, int concurrencyLevel) {
043    
044                    this(
045                            new ConcurrentHashMap<IdentityKey<K>, V>(
046                                    initialCapacity, loadFactor, concurrencyLevel));
047            }
048    
049            public ConcurrentIdentityHashMap(Map<? extends K, ? extends V> map) {
050                    this(new ConcurrentHashMap<IdentityKey<K>, V>());
051    
052                    putAll(map);
053            }
054    
055            @Override
056            protected IdentityKey<K> mapKey(K key) {
057                    return new IdentityKey<>(key);
058            }
059    
060            @Override
061            protected IdentityKey<K> mapKeyForQuery(K key) {
062                    return new IdentityKey<>(key);
063            }
064    
065            @Override
066            protected V mapValue(K key, V value) {
067                    return value;
068            }
069    
070            @Override
071            protected V mapValueForQuery(V value) {
072                    return value;
073            }
074    
075            @Override
076            protected K unmapKey(IdentityKey<K> identityKey) {
077                    return identityKey.getKey();
078            }
079    
080            @Override
081            protected K unmapKeyForQuery(IdentityKey<K> identityKey) {
082                    return identityKey.getKey();
083            }
084    
085            @Override
086            protected V unmapValue(V value) {
087                    return value;
088            }
089    
090            @Override
091            protected V unmapValueForQuery(V value) {
092                    return value;
093            }
094    
095    }