site.sorghum.anno._common.entity.BiHashMap Maven / Gradle / Ivy
The newest version!
package site.sorghum.anno._common.entity;
import java.util.*;
/**
* CopyFromRedisson
*
* @author Sorghum
* @since 2023/07/10
*/
public class BiHashMap implements Map {
private Map keyValueMap = new HashMap<>();
private Map valueKeyMap = new HashMap<>();
@Override
public int size() {
return keyValueMap.size();
}
@Override
public boolean isEmpty() {
return keyValueMap.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return keyValueMap.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return valueKeyMap.containsKey(value);
}
@Override
public V get(Object key) {
return keyValueMap.get(key);
}
public K reverseGet(Object key) {
return valueKeyMap.get(key);
}
@Override
public V put(K key, V value) {
if (keyValueMap.containsKey(key)) {
valueKeyMap.remove(keyValueMap.get(key));
}
valueKeyMap.put(value, key);
return keyValueMap.put(key, value);
}
@Override
public V remove(Object key) {
V removed = keyValueMap.remove(key);
if (removed != null) {
valueKeyMap.remove(removed);
}
return removed;
}
@Override
public void putAll(Map extends K, ? extends V> m) {
for (Entry extends K, ? extends V> entry : m.entrySet()) {
put(entry.getKey(), entry.getValue());
}
}
@Override
public void clear() {
keyValueMap.clear();
valueKeyMap.clear();
}
@Override
public Set keySet() {
return keyValueMap.keySet();
}
public Set valueSet() {
return valueKeyMap.keySet();
}
@Override
public Collection values() {
return keyValueMap.values();
}
public Collection keys() {
return valueKeyMap.values();
}
@Override
public Set> entrySet() {
return keyValueMap.entrySet();
}
public Set> reverseEntrySet() {
return valueKeyMap.entrySet();
}
public void makeImmutable() {
keyValueMap = Collections.unmodifiableMap(keyValueMap);
valueKeyMap = Collections.unmodifiableMap(valueKeyMap);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy