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.
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.
- Author:
- Kristian
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classRepresents a single end point (open, close or both) of a range.classRepresents a range and a value in this interval tree.protected static class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected AbstractIntervalTree.EndPointaddEndPoint(TKey key, TValue value, AbstractIntervalTree.State state)voidclear()Remove every interval.booleancontainsKey(TKey key)Determines if the given key is within an interval.protected abstract TKeydecrementKey(TKey key)Decrement the given key by one unit.entrySet()Enumerates over every range in this interval tree.Retrieves the value of the range that matches the given key, or NULL if nothing was found.protected AbstractIntervalTree.EndPointgetEndPoint(TKey key)Get the left-most end-point associated with this key.protected AbstractIntervalTree.EntryRetrieve the entry from a given set of end points.protected AbstractIntervalTree.EndPointgetNextEndPoint(TKey point, boolean inclusive)Get the next end point of a given key.protected AbstractIntervalTree.EndPointgetPreviousEndPoint(TKey point, boolean inclusive)Get the previous end point of a given key.protected abstract TKeyincrementKey(TKey key)Increment the given key by one unit.protected voidInvoked when an entry is added.protected voidonEntryRemoved(AbstractIntervalTree.Entry removed)Invoked when an entry is removed.voidAssociates a given interval of keys with a certain value.voidputAll(AbstractIntervalTree<TKey,TValue> other)Inserts every range from the given tree into the current tree.Removes every interval that intersects with the given range.Removes every interval that intersects with the given range.
-
Field Details
-
bounds
-
-
Constructor Details
-
AbstractIntervalTree
public AbstractIntervalTree()
-
-
Method Details
-
remove
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.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
protected AbstractIntervalTree.Entry getEntry(AbstractIntervalTree.EndPoint left, AbstractIntervalTree.EndPoint right)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.EndPoint addEndPoint(TKey key, TValue value, AbstractIntervalTree.State state) -
put
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
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
Enumerates over every range in this interval tree.- Returns:
- Number of ranges.
-
clear
public void clear()Remove every interval. -
putAll
Inserts every range from the given tree into the current tree.- Parameters:
other- - the other tree to read from.
-
get
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
Get the left-most end-point associated with this key.- Parameters:
key- - key to search for.- Returns:
- The end point found, or NULL.
-
getPreviousEndPoint
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
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
Invoked when an entry is added.- Parameters:
added- - the entry that was added.
-
onEntryRemoved
Invoked when an entry is removed.- Parameters:
removed- - the removed entry.
-
decrementKey
Decrement the given key by one unit.- Parameters:
key- - the key that should be decremented.- Returns:
- The new decremented key.
-
incrementKey
Increment the given key by one unit.- Parameters:
key- - the key that should be incremented.- Returns:
- The new incremented key.
-