![JAR search and dependency download from the Maven repository](/logo.png)
net.sf.javagimmicks.collections.bidimap.DualSortedBidiMap Maven / Gradle / Ivy
package net.sf.javagimmicks.collections.bidimap;
import java.util.AbstractMap;
import java.util.Comparator;
import java.util.Set;
import java.util.SortedMap;
public class DualSortedBidiMap extends DualBidiMap implements SortedBidiMap
{
DualSortedBidiMap(SortedMap forwardMap, SortedMap reverseMap)
{
super(forwardMap, reverseMap);
}
public SortedBidiMap inverseBidiSortedMap()
{
return new InverseDualSortedBidiMap(getReverseMap(), getForwardMap());
}
public SortedMap headMap(K toKey)
{
return new SortedSubMapDecorator(getForwardMap().headMap(toKey));
}
public SortedMap subMap(K fromKey, K toKey)
{
return new SortedSubMapDecorator(getForwardMap().subMap(fromKey, toKey));
}
public SortedMap tailMap(K fromKey)
{
return new SortedSubMapDecorator(getForwardMap().tailMap(fromKey));
}
public Comparator super K> comparator()
{
return getForwardMap().comparator();
}
public K firstKey()
{
return getForwardMap().firstKey();
}
public K lastKey()
{
return getForwardMap().lastKey();
}
@Override
protected SortedMap getForwardMap()
{
return (SortedMap)super.getForwardMap();
}
@Override
protected SortedMap getReverseMap()
{
return (SortedMap)super.getReverseMap();
}
protected class InverseDualSortedBidiMap extends DualSortedBidiMap
{
protected InverseDualSortedBidiMap(SortedMap reverseMap, SortedMap forwardMap)
{
super(reverseMap, forwardMap);
}
@Override
public SortedBidiMap inverseBidiSortedMap()
{
return DualSortedBidiMap.this;
}
}
protected class SortedSubMapDecorator extends AbstractMap implements SortedMap
{
protected final SortedMap m_oSubMap;
protected SortedSubMapDecorator(SortedMap oSubMap)
{
m_oSubMap = oSubMap;
}
@Override
public Set> entrySet()
{
return new DualBidiEntrySet(m_oSubMap.entrySet());
}
public SortedMap headMap(K toKey)
{
return new SortedSubMapDecorator(m_oSubMap.headMap(toKey));
}
public SortedMap subMap(K fromKey, K toKey)
{
return new SortedSubMapDecorator(m_oSubMap.subMap(fromKey, toKey));
}
public SortedMap tailMap(K fromKey)
{
return new SortedSubMapDecorator(m_oSubMap.tailMap(fromKey));
}
@Override
public V put(K key, V value)
{
checkValue(value);
V oldValue = m_oSubMap.put(key, value);
K oldKey = getReverseMap().put(value, key);
getForwardMap().remove(oldKey);
getReverseMap().remove(oldValue);
return oldValue;
}
public void clear()
{
m_oSubMap.clear();
}
public Comparator super K> comparator()
{
return m_oSubMap.comparator();
}
public boolean containsKey(Object key)
{
return m_oSubMap.containsKey(key);
}
public boolean containsValue(Object value)
{
return m_oSubMap.containsValue(value);
}
public K firstKey()
{
return m_oSubMap.firstKey();
}
public V get(Object key)
{
return m_oSubMap.get(key);
}
public boolean isEmpty()
{
return m_oSubMap.isEmpty();
}
public K lastKey()
{
return m_oSubMap.lastKey();
}
public int size()
{
return m_oSubMap.size();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy