Class AdjacentSortedRangeList

  • All Implemented Interfaces:
    java.lang.Iterable<Range>

    public class AdjacentSortedRangeList
    extends SortedRangeList
    Provides a list of integer ranges that are maintained in sorted order where adjacent ranges do not coalesce. When a range is added any ranges that overlap will coalesce into a single range. However, ranges which are adjacent to one another will not coalesce. This list maintains separate ranges which can have one range ending and the next range beginning at the next available integer value.
    • Constructor Detail

      • AdjacentSortedRangeList

        public AdjacentSortedRangeList()
        Creates a new empty sorted range list which allows adjacent ranges.
      • AdjacentSortedRangeList

        public AdjacentSortedRangeList​(AdjacentSortedRangeList list)
        Creates a new adjacent sorted range list with ranges equivalent to those in the specified list.
        Parameters:
        list - the adjacent sorted range list to make an equivalent copy of.
    • Method Detail

      • addRange

        public void addRange​(int min,
                             int max)
        Adds the range from min to max to this adjacent sorted range list. If the range overlaps any other existing ranges, then those ranges will coalesce. If the range is adjacent to other
        Overrides:
        addRange in class SortedRangeList
        Parameters:
        min - the range minimum
        max - the range maximum (inclusive)
      • intersect

        public AdjacentSortedRangeList intersect​(AdjacentSortedRangeList other)
        Creates a new AdjacentSortedRangeList that is the intersection of this range list and the other range list specified. The ranges in the new list will have breaks between adjacent ranges wherever either this range list or the other range list have breaks between adjacent ranges.
        Parameters:
        other - the other adjacent sorted range list
        Returns:
        the new AdjacentSortedRangeList representing the intersection.