cc.kave.repackaged.jayes.internal.util.BidirectionalMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cc.kave.repackaged.jayes Show documentation
Show all versions of cc.kave.repackaged.jayes Show documentation
Repackaging of Jayes (Eclipse Code Recommenders) to make it available in Maven.
The newest version!
/**
* Copyright (c) 2011 Michael Kutschke.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Michael Kutschke - initial API and implementation.
*/
package cc.kave.repackaged.jayes.internal.util;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class BidirectionalMap implements Map {
private Map keyValue = new HashMap();
private Map valueKey = new HashMap();
public BidirectionalMap() {
}
@Override
public int size() {
return keyValue.size();
}
@Override
public boolean isEmpty() {
return keyValue.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return keyValue.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return valueKey.containsKey(value);
}
@Override
public V get(Object key) {
return keyValue.get(key);
}
public K getKey(V value) {
return valueKey.get(value);
}
@Override
public V put(K key, V value) {
if (containsValue(value) && valueKey.get(value) != key)
throw new IllegalArgumentException(value + " has already been assigned an other key, violating uniqueness");
V val = keyValue.put(key, value);
valueKey.remove(val);
valueKey.put(value, key);
return val;
}
@Override
public V remove(Object key) {
V v = keyValue.remove(key);
valueKey.remove(v);
return v;
}
@Override
public void putAll(Map extends K, ? extends V> m) {
for (Entry extends K, ? extends V> ent : m.entrySet()) {
put(ent.getKey(), ent.getValue());
}
}
@Override
public void clear() {
keyValue.clear();
valueKey.clear();
}
@Override
public Set keySet() {
return keyValue.keySet();
}
@Override
public Collection values() {
return valueKey.keySet();
}
@Override
public Set> entrySet() {
return keyValue.entrySet();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy