java.lang.Object
org.jhotdraw8.icollection.impl.redblack.Node<K,V>
Type Parameters:
K - Component type
All Implemented Interfaces:
Iterable<Node<K,V>>, Map.Entry<K,V>, RedBlackTree<K,V>

public final class Node<K,V> extends Object implements RedBlackTree<K,V>, Map.Entry<K,V>
A non-empty tree node.

This class has been derived from 'vavr' RedBlackTree.java.

RedBlackTree.java. Copyright 2023 (c) vavr. MIT License.
github.com
  • Method Details

    • ceiling

      public @NonNull RedBlackTree<K,V> ceiling(K value, @NonNull Comparator<? super K> comparator)
      Description copied from interface: RedBlackTree
      Returns the least Node in this tree greater than or equal to the given element, or Empty if there is no such element.
      Specified by:
      ceiling in interface RedBlackTree<K,V>
    • color

      public boolean color()
      Description copied from interface: RedBlackTree
      Return the Color of this Red/Black Tree node.

      An empty node is BLACK by definition.

      Specified by:
      color in interface RedBlackTree<K,V>
      Returns:
      Either RED or BLACK.
    • contains

      public boolean contains(K key, Comparator<? super K> comparator)
      Description copied from interface: RedBlackTree
      Checks, if this RedBlackTree contains the given key.
      Specified by:
      contains in interface RedBlackTree<K,V>
      Parameters:
      key - A key.
      comparator -
      Returns:
      true, if this tree contains the value, false otherwise.
    • entryOrNull

      public @Nullable Map.Entry<K,V> entryOrNull()
      Description copied from interface: RedBlackTree
      Returns the map entry of this RedBlackTree or null if it is empty.
      Specified by:
      entryOrNull in interface RedBlackTree<K,V>
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map.Entry<K,V>
      Overrides:
      equals in class Object
    • find

      public RedBlackTree<K,V> find(K key, Comparator<? super K> comparator)
      Description copied from interface: RedBlackTree
      Finds the value stored in this tree, if exists, by applying the underlying comparator to the tree elements and the given element.

      Especially the value returned may differ from the given value, even if the underlying comparator states that both are equal.

      Specified by:
      find in interface RedBlackTree<K,V>
      Parameters:
      key - A value
      comparator -
      Returns:
      Some value, if this tree contains a value equal to the given value according to the underlying comparator. Otherwise None.
    • floor

      public @NonNull RedBlackTree<K,V> floor(K value, @NonNull Comparator<? super K> comparator)
      Description copied from interface: RedBlackTree
      Returns the greatest Node in this tree less than or equal to the given element, or Empty if there is no such element.
      Specified by:
      floor in interface RedBlackTree<K,V>
    • getKey

      public K getKey()
      Description copied from interface: RedBlackTree
      Returns the key of the current tree node or throws if this is empty.
      Specified by:
      getKey in interface Map.Entry<K,V>
      Specified by:
      getKey in interface RedBlackTree<K,V>
      Returns:
      The value.
    • getValue

      public V getValue()
      Description copied from interface: RedBlackTree
      Returns the value of the current tree node or throws if this is empty.
      Specified by:
      getValue in interface Map.Entry<K,V>
      Specified by:
      getValue in interface RedBlackTree<K,V>
      Returns:
      The value.
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map.Entry<K,V>
      Overrides:
      hashCode in class Object
    • higher

      public @NonNull RedBlackTree<K,V> higher(K value, @NonNull Comparator<? super K> comparator)
      Description copied from interface: RedBlackTree
      Returns the least Node in this tree strictly greater than the given element, or Empty if there is no such element.
      Specified by:
      higher in interface RedBlackTree<K,V>
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: RedBlackTree
      Checks if this RedBlackTree is empty, i.e. an instance of Leaf.
      Specified by:
      isEmpty in interface RedBlackTree<K,V>
      Returns:
      true, if it is empty, false otherwise.
    • isRed

      public boolean isRed()
      Specified by:
      isRed in interface RedBlackTree<K,V>
    • keyOrNull

      public @Nullable K keyOrNull()
      Description copied from interface: RedBlackTree
      Returns the key of this RedBlackTree or null if it is empty.
      Specified by:
      keyOrNull in interface RedBlackTree<K,V>
    • left

      public RedBlackTree<K,V> left()
      Description copied from interface: RedBlackTree
      Returns the left child if this is a non-empty node, otherwise throws.
      Specified by:
      left in interface RedBlackTree<K,V>
      Returns:
      The left child.
    • lower

      public @NonNull RedBlackTree<K,V> lower(K value, @NonNull Comparator<? super K> comparator)
      Description copied from interface: RedBlackTree
      Returns the greatest Node in this tree strictly less than the given element, or Empty if there is no such element.
      Specified by:
      lower in interface RedBlackTree<K,V>
    • mapOrNull

      public <E> @Nullable E mapOrNull(@NonNull BiFunction<K,V,E> f)
      Specified by:
      mapOrNull in interface RedBlackTree<K,V>
    • orElse

      public RedBlackTree<K,V> orElse(RedBlackTree<K,V> other)
      Description copied from interface: RedBlackTree
      Returns this RedBlackTree if it is nonempty, otherwise return the alternative.
      Specified by:
      orElse in interface RedBlackTree<K,V>
    • right

      public @NonNull RedBlackTree<K,V> right()
      Description copied from interface: RedBlackTree
      Returns the right child if this is a non-empty node, otherwise throws.
      Specified by:
      right in interface RedBlackTree<K,V>
      Returns:
      The right child.
    • setValue

      public V setValue(V value)
      Specified by:
      setValue in interface Map.Entry<K,V>
    • size

      public int size()
      Description copied from interface: RedBlackTree
      Returns the size of this tree.
      Specified by:
      size in interface RedBlackTree<K,V>
      Returns:
      the number of nodes of this tree and 0 if this is the empty tree
    • toLispString

      public String toLispString()
      Specified by:
      toLispString in interface RedBlackTree<K,V>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • valueOrNull

      public @Nullable V valueOrNull()
      Description copied from interface: RedBlackTree
      Returns the value of this RedBlackTree or null if it is empty.
      Specified by:
      valueOrNull in interface RedBlackTree<K,V>