staticfinalclassEntry<K,V> implementsMap.Entry<K,V> { K key; V value; Entry<K,V> left; Entry<K,V> right; Entry<K,V> parent; boolean color = BLACK;
/** * Make a new cell with given key, value, and parent, and with * {@code null} child links, and BLACK color. */ Entry(K key, V value, Entry<K,V> parent) { this.key = key; this.value = value; this.parent = parent; }
/** * Returns the key. * * @return the key */ public K getKey(){ return key; }
/** * Returns the value associated with the key. * * @return the value associated with the key */ public V getValue(){ return value; }
/** * Replaces the value currently associated with the key with the given * value. * * @return the value associated with the key before this method was * called */ public V setValue(V value){ V oldValue = this.value; this.value = value; return oldValue; }
publicbooleanequals(Object o){ if (!(o instanceof Map.Entry)) returnfalse; Map.Entry<?,?> e = (Map.Entry<?,?>)o;
public V get(Object key){ Entry<K,V> p = getEntry(key); return (p==null ? null : p.value); }
final Entry<K,V> getEntry(Object key){ // Offload comparator-based version for sake of performance if (comparator != null) return getEntryUsingComparator(key); if (key == null) thrownew NullPointerException(); @SuppressWarnings("unchecked") Comparable<? super K> k = (Comparable<? super K>) key; Entry<K,V> p = root; while (p != null) { int cmp = k.compareTo(p.key); if (cmp < 0) p = p.left; elseif (cmp > 0) p = p.right; else return p; } returnnull; }