A representation of a single node in the IntervalTree. Since the Interval Tree is practically a binary search tree, every node is identified by a unique key - the center (called middlepoint) of the first interval that triggers the creation of this node. The key is immutable and can't be
| 70 | * @param <T> The type for the start and end point of the interval |
| 71 | */ |
| 72 | public class TreeNode<T extends Comparable<? super T>> implements Iterable<Interval<T>> { |
| 73 | /** |
| 74 | * A set containing all {@link Interval}s stored in this node, ordered by their |
| 75 | * starting points. |
| 76 | * @see Interval#sweepLeftToRight |
| 77 | */ |
| 78 | protected NavigableSet<Interval<T>> increasing; |
| 79 | |
| 80 | /** |
| 81 | * A set containing all {@link Interval}s stored in this node, ordered by their |
| 82 | * end points. |
| 83 | * @see Interval#sweepRightToLeft |
| 84 | */ |
| 85 | protected NavigableSet<Interval<T>> decreasing; |
| 86 | |
| 87 | /** |
| 88 | * A pointer to the left child of the current node. The left child must either be |
| 89 | * {@code null} or have a midpoint, smaller than the midpoint of the current node. More |
| 90 | * formally, {@code left.midpoint.compareTo(this.midpoint) < 0} must evaluate to {@code true}. |
| 91 | */ |
| 92 | protected TreeNode<T> left; |
| 93 | |
| 94 | /** |
| 95 | * A pointer to the right child of the current node. The right child must either be |
| 96 | * {@code null} or have a midpoint, larger than the midpoint of the current node. More |
| 97 | * formally, {@code right.midpoint.compareTo(this.midpoint) > 0} must evaluate to {@code true}. |
| 98 | */ |
| 99 | protected TreeNode<T> right; |
| 100 | |
| 101 | /** |
| 102 | * The midpoint of the initial interval added to the node. It is an immutable value |
| 103 | * and can not be changed, even if the initial interval has been removed from the |
| 104 | * node. |
| 105 | */ |
| 106 | protected final T midpoint; |
| 107 | |
| 108 | /** |
| 109 | * The height of the node. |
| 110 | */ |
| 111 | protected int height; |
| 112 | |
| 113 | /** |
| 114 | * Instantiates a new node in an {@link IntervalTree}. |
| 115 | * |
| 116 | * @param interval The initial interval stored in the node. The middlepoint of |
| 117 | * the node will be set based on this interval. |
| 118 | */ |
| 119 | public TreeNode(Interval<T> interval){ |
| 120 | decreasing = new TreeSet<>(Interval.sweepRightToLeft); |
| 121 | increasing = new TreeSet<>(Interval.sweepLeftToRight); |
| 122 | |
| 123 | decreasing.add(interval); |
| 124 | increasing.add(interval); |
| 125 | midpoint = interval.getMidpoint(); |
| 126 | height = 1; |
| 127 | } |
| 128 | |
| 129 | /** |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…