Class AbstractIntervalTree<TKey extends Comparable<TKey>,TValue>

java.lang.Object
com.comphenix.protocol.concurrency.AbstractIntervalTree<TKey,TValue>
Type Parameters:
TKey - - type of the key. Must implement Comparable.
TValue - - type of the value to associate.

public abstract class AbstractIntervalTree<TKey extends Comparable<TKey>,TValue> extends Object
Represents a generic store of intervals and associated values. No two intervals can overlap in this representation.

Note that this implementation is not thread safe.

  • Field Details

  • Constructor Details

    • AbstractIntervalTree

      public AbstractIntervalTree()
  • Method Details

    • remove

      public Set<AbstractIntervalTree<TKey,TValue>.Entry> remove(TKey lowerBound, TKey upperBound)
      Removes every interval that intersects with the given range.
      Parameters:
      lowerBound - - lowest value to remove.
      upperBound - - highest value to remove.
      Returns:
      Intervals that were removed
    • remove

      public Set<AbstractIntervalTree<TKey,TValue>.Entry> remove(TKey lowerBound, TKey upperBound, boolean preserveDifference)
      Removes every interval that intersects with the given range.
      Parameters:
      lowerBound - - lowest value to remove.
      upperBound - - highest value to remove.
      preserveDifference - - whether or not to preserve the intervals that are partially outside.
      Returns:
      Intervals that were removed
    • getEntry

      Retrieve the entry from a given set of end points.
      Parameters:
      left - - leftmost end point.
      right - - rightmost end point.
      Returns:
      The associated entry.
    • addEndPoint

      protected AbstractIntervalTree<TKey,TValue>.EndPoint addEndPoint(TKey key, TValue value, AbstractIntervalTree.State state)
    • put

      public void put(TKey lowerBound, TKey upperBound, TValue value)
      Associates a given interval of keys with a certain value. Any previous association will be overwritten in the given interval.

      Overlapping intervals are not permitted. A key can only be associated with a single value.

      Parameters:
      lowerBound - - the minimum key (inclusive).
      upperBound - - the maximum key (inclusive).
      value - - the value, or NULL to reset this range.
    • containsKey

      public boolean containsKey(TKey key)
      Determines if the given key is within an interval.
      Parameters:
      key - - key to check.
      Returns:
      TRUE if the given key is within an interval in this tree, FALSE otherwise.
    • entrySet

      public Set<AbstractIntervalTree<TKey,TValue>.Entry> entrySet()
      Enumerates over every range in this interval tree.
      Returns:
      Number of ranges.
    • clear

      public void clear()
      Remove every interval.
    • putAll

      public void putAll(AbstractIntervalTree<TKey,TValue> other)
      Inserts every range from the given tree into the current tree.
      Parameters:
      other - - the other tree to read from.
    • get

      public TValue get(TKey key)
      Retrieves the value of the range that matches the given key, or NULL if nothing was found.
      Parameters:
      key - - the level to read for.
      Returns:
      The correct amount of experience, or NULL if nothing was recorded.
    • getEndPoint

      protected AbstractIntervalTree<TKey,TValue>.EndPoint getEndPoint(TKey key)
      Get the left-most end-point associated with this key.
      Parameters:
      key - - key to search for.
      Returns:
      The end point found, or NULL.
    • getPreviousEndPoint

      protected AbstractIntervalTree<TKey,TValue>.EndPoint getPreviousEndPoint(TKey point, boolean inclusive)
      Get the previous end point of a given key.
      Parameters:
      point - - the point to search with.
      inclusive - - whether or not to include the current point in the search.
      Returns:
      The previous end point of a given given key, or NULL if not found.
    • getNextEndPoint

      protected AbstractIntervalTree<TKey,TValue>.EndPoint getNextEndPoint(TKey point, boolean inclusive)
      Get the next end point of a given key.
      Parameters:
      point - - the point to search with.
      inclusive - - whether or not to include the current point in the search.
      Returns:
      The next end point of a given given key, or NULL if not found.
    • onEntryAdded

      protected void onEntryAdded(AbstractIntervalTree<TKey,TValue>.Entry added)
      Invoked when an entry is added.
      Parameters:
      added - - the entry that was added.
    • onEntryRemoved

      protected void onEntryRemoved(AbstractIntervalTree<TKey,TValue>.Entry removed)
      Invoked when an entry is removed.
      Parameters:
      removed - - the removed entry.
    • decrementKey

      protected abstract TKey decrementKey(TKey key)
      Decrement the given key by one unit.
      Parameters:
      key - - the key that should be decremented.
      Returns:
      The new decremented key.
    • incrementKey

      protected abstract TKey incrementKey(TKey key)
      Increment the given key by one unit.
      Parameters:
      key - - the key that should be incremented.
      Returns:
      The new incremented key.