@Override public void clear() { TreeBidiMap.this.clear(); } }
private V doRemoveKey(final Object key) { final Node<K, V> node = lookupKey(key); if (node == null) { return null; } doRedBlackDelete(node); return node.getValue(); }
private K doRemoveValue(final Object value) { final Node<K, V> node = lookupValue(value); if (node == null) { return null; } doRedBlackDelete(node); return node.getKey(); }
/** * Gets the next key after the one specified. * <p> * The key must implement <code>Comparable</code>. * * @param key the key to search for next from * @return the next key, null if no match or at end */ @Override public K nextKey(final K key) { checkKey(key); final Node<K, V> node = nextGreater(lookupKey(key), KEY); return node == null ? null : node.getKey(); }
@Override public OrderedMapIterator<K, V> mapIterator() { if (isEmpty()) { return EmptyOrderedMapIterator.<K, V>emptyOrderedMapIterator(); } return new ViewMapIterator(KEY); }
/** * Gets the first (lowest) key currently in this map. * * @return the first (lowest) key currently in this sorted map * @throws NoSuchElementException if this map is empty */ @Override public K firstKey() { if (nodeCount == 0) { throw new NoSuchElementException("Map is empty"); } return leastNode(rootNode[KEY.ordinal()], KEY).getKey(); }
@Override public Iterator<K> iterator() { return parent.createKeySetIterator(super.iterator()); }
@Override public Iterator<V> iterator() { return parent.createValuesIterator(super.iterator()); }
@Override public Iterator<Map.Entry<K, V>> iterator() { return parent.createEntrySetIterator(super.iterator()); }
@Override public K previousKey(final K key) { return decorated().previousKey(key); }
/** * Make this node black. * * @param dataElement either {@link DataElement#KEY} key} * or the {@link DataElement#VALUE value}. */ private void setBlack(final DataElement dataElement) { blackColor[dataElement.ordinal()] = true; }
/** * bump up the size and note that the map has changed */ private void grow() { modify(); nodeCount++; }
/** * Creates an entry set iterator. * Subclasses can override this to return iterators with different properties. * * @param iterator the iterator to decorate * @return the entrySet iterator */ protected Iterator<Map.Entry<K, V>> createEntrySetIterator(final Iterator<Map.Entry<K, V>> iterator) { return new EntrySetIterator<>(iterator, this); }
/** * 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)); }
/** * check a value for validity (non-null and implements Comparable) * * @param value the value to be checked * * @throws NullPointerException if value is null * @throws ClassCastException if value is not Comparable */ private static void checkValue(final Object value) { checkNonNullComparable(value, VALUE); }
/** * Make this node red. * * @param dataElement either {@link DataElement#KEY} key} * or the {@link DataElement#VALUE value}. */ private void setRed(final DataElement dataElement) { blackColor[dataElement.ordinal()] = false; }
/** * decrement the size and note that the map has changed */ private void shrink() { modify(); nodeCount--; }
/** * Is this node red? * * @param dataElement either {@link DataElement#KEY} key} * or the {@link DataElement#VALUE value}. * @return true if non-black */ private boolean isRed(final DataElement dataElement) { return !blackColor[dataElement.ordinal()]; }