Class RangeSelection


  • public class RangeSelection
    extends java.lang.Object
    Class for managing a set of indexed range selections.

    Note: Since this class is used for 0-based indexes, there are checks to make sure no negative values are ever added.

    • Constructor Summary

      Constructors 
      Constructor Description
      RangeSelection()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Sequence<Span> addRange​(int start, int end)
      Adds a range to the selection, merging and removing intersecting ranges as needed.
      Sequence<Span> addRange​(Span range)
      Add a range to the selection, merging and removing intersecting ranges as needed.
      void clear()
      Clears the selection.
      boolean containsIndex​(int index)
      Tests for the presence of an index in the selection.
      Span get​(int index)  
      int getEnd()  
      int getLength()  
      ImmutableList<Span> getSelectedRanges()  
      int getStart()  
      int indexOf​(Span range)
      Determines the index of a range in the selection.
      int insertIndex​(int index)
      Inserts an index into the span sequence (e.g.
      int removeIndexes​(int index, int count)
      Removes a range of indexes from the span sequence (e.g.
      Sequence<Span> removeRange​(int start, int end)
      Removes a range from the selection, truncating and removing intersecting ranges as needed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RangeSelection

        public RangeSelection()
    • Method Detail

      • addRange

        public Sequence<Span> addRange​(Span range)
        Add a range to the selection, merging and removing intersecting ranges as needed.
        Parameters:
        range - The new range to add to the selection.
        Returns:
        A sequence containing the ranges that were added.
      • addRange

        public Sequence<Span> addRange​(int start,
                                       int end)
        Adds a range to the selection, merging and removing intersecting ranges as needed.
        Parameters:
        start - Where to start the new range.
        end - The end of the new range.
        Returns:
        A sequence containing the ranges that were added.
      • removeRange

        public Sequence<Span> removeRange​(int start,
                                          int end)
        Removes a range from the selection, truncating and removing intersecting ranges as needed.
        Parameters:
        start - Start of the range to remove.
        end - The end of the range to remove.
        Returns:
        A sequence containing the ranges that were removed.
      • clear

        public void clear()
        Clears the selection.
      • get

        public Span get​(int index)
        Parameters:
        index - The index in question.
        Returns:
        The range at a given index.
      • getLength

        public int getLength()
        Returns:
        The number of ranges in the selection.
      • getSelectedRanges

        public ImmutableList<Span> getSelectedRanges()
        Returns:
        An immutable wrapper around the selected ranges.
      • getStart

        public int getStart()
        Returns:
        The smallest start value of this selection, or -1 if it is empty.
      • getEnd

        public int getEnd()
        Returns:
        The largest end value of this selection, or -1 if the range is empty.
      • indexOf

        public int indexOf​(Span range)
        Determines the index of a range in the selection.
        Parameters:
        range - The range to look for.
        Returns:
        The index of the range, if it exists in the selection; -1, otherwise.
      • containsIndex

        public boolean containsIndex​(int index)
        Tests for the presence of an index in the selection.
        Parameters:
        index - The index to look for in the selection.
        Returns:
        true if the index is selected; false, otherwise.
      • insertIndex

        public int insertIndex​(int index)
        Inserts an index into the span sequence (e.g. when items are inserted into the model data).
        Parameters:
        index - The location to insert into the sequence.
        Returns:
        The number of ranges that were updated.
      • removeIndexes

        public int removeIndexes​(int index,
                                 int count)
        Removes a range of indexes from the span sequence (e.g. when items are removed from the model data).
        Parameters:
        index - Start index to remove.
        count - Number of indexes to remove.
        Returns:
        The number of ranges that were updated.