Class RangeCounter<C extends Comparable>

  • Type Parameters:
    C - Type of the range's end points.

    public final class RangeCounter<C extends Comparable>
    extends Object
    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 Detail

      • RangeCounter

        public RangeCounter()
        Creates a new range map for ranges of the given type.
    • Method Detail

      • add

        public void add​(com.google.common.collect.Range<C> range)
        Adds a range to this map and counts it.
        Parameters:
        range - A range to add and count.
      • getMaxCount

        public int getMaxCount​(com.google.common.collect.Range<C> range)
         // 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

        public Stream<Map.Entry<com.google.common.collect.Range<C>,​Integer>> stream()
        Returns:
        A stream with all ranges and the corresponding count. The (disjoint) ranges are ordered in ascending order.
      • create

        public static <C extends ComparableRangeCounter<C> create()
        Type Parameters:
        C - Type of the range's end points.
        Returns:
        A newly range map for ranges of the given type.