Package de.xima.fc.utils.range
Class RangeCounter<C extends Comparable>
java.lang.Object
de.xima.fc.utils.range.RangeCounter<C>
- Type Parameters:
C
- Type of the range's end points.
A range map to which ranges can be added. Allows counting for how many ranges were added in a certain interval.
- Author:
- XIMA MEDIA GmbH
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a range to this map and counts it.static <C extends Comparable>
RangeCounter<C>create()
int
getMaxCount
(com.google.common.collect.Range<C> range) // Given these ranges: [----------] [---------] [--------] (-) 11111122223212111111111 // Then the above is the max count at each pointstream()
-
Constructor Details
-
RangeCounter
public RangeCounter()Creates a new range map for ranges of the given type.
-
-
Method Details
-
add
Adds a range to this map and counts it.- Parameters:
range
- A range to add and count.
-
getMaxCount
// Given these ranges: [----------] [---------] [--------] (-) 11111122223212111111111 // Then the above is the max count at each point
- Parameters:
range
- A range to check.- Returns:
- Checks each point in the given interval for how many ranges were added via
add(Range)
that include that point; and returns the maximum count. Ranges that partially overlap the given interval are included in the returned count.
-
stream
- Returns:
- A stream with all ranges and the corresponding count. The (disjoint) ranges are ordered in ascending order.
-
create
- Type Parameters:
C
- Type of the range's end points.- Returns:
- A newly range map for ranges of the given type.
-