/** * Constructor. * @param bidi the parent bidi map * @param sm the subMap sorted map */ protected ViewMap(final DualTreeBidiMap<K, V> bidi, final SortedMap<K, V> sm) { // the implementation is not great here... // use the normalMap as the filtered map, but reverseMap as the full map // this forces containsValue and clear to be overridden super(new DualTreeBidiMap<>(sm, bidi.reverseMap, bidi.inverseBidiMap)); }
public OrderedBidiMap<V, K> inverseOrderedBidiMap() { return inverseBidiMap(); }
/** * Constructs a <code>DualTreeBidiMap</code> and copies the mappings from * specified <code>Map</code>. * * @param map the map whose mappings are to be placed in this map */ public DualTreeBidiMap(final Map<? extends K, ? extends V> map) { super(new TreeMap<K, V>(), new TreeMap<V, K>()); putAll(map); this.comparator = null; this.valueComparator = null; }
@Override public K previousKey(final K key) { if (isEmpty()) { return null; } if (normalMap instanceof OrderedMap) { return ((OrderedMap<K, V>) normalMap).previousKey(key); } final SortedMap<K, V> sm = (SortedMap<K, V>) normalMap; final SortedMap<K, V> hm = sm.headMap(key); if (hm.isEmpty()) { return null; } return hm.lastKey(); }
@Override public K nextKey(final K key) { return decorated().nextKey(key); } }
@Override public K previousKey(final K key) { return decorated().previousKey(key); }
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); normalMap = new TreeMap<>(comparator); reverseMap = new TreeMap<>(valueComparator); @SuppressWarnings("unchecked") // will fail at runtime if the stream is incorrect final Map<K, V> map = (Map<K, V>) in.readObject(); putAll(map); }
@Override public K nextKey(final K key) { if (isEmpty()) { return null; } if (normalMap instanceof OrderedMap) { return ((OrderedMap<K, ?>) normalMap).nextKey(key); } final SortedMap<K, V> sm = (SortedMap<K, V>) normalMap; final Iterator<K> it = sm.tailMap(key).keySet().iterator(); it.next(); if (it.hasNext()) { return it.next(); } return null; }
/** * Creates a new instance of this object. * * @param normalMap the normal direction map * @param reverseMap the reverse direction map * @param inverseMap the inverse BidiMap * @return new bidi map */ @Override protected DualTreeBidiMap<V, K> createBidiMap(final Map<V, K> normalMap, final Map<K, V> reverseMap, final BidiMap<K, V> inverseMap) { return new DualTreeBidiMap<>(normalMap, reverseMap, inverseMap); }
public SortedBidiMap<V, K> inverseSortedBidiMap() { return inverseBidiMap(); }