Class IndexRange


  • public final class IndexRange
    extends java.lang.Object
    A simple immutable container for a range of indices into an underlying InputBuffer.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static IndexRange EMPTY  
      int end
      The index of the character following the last character of the range.
      int start
      The index of the first character in the range.
    • Constructor Summary

      Constructors 
      Constructor Description
      IndexRange​(int start, int end)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      boolean isEmpty()
      Determines whether this range contains no characters.
      boolean isFollowedBy​(IndexRange other)
      Determines whether this range is immediated followed by the given other one.
      boolean isPrecededBy​(IndexRange other)
      Determines whether this range immediated follows the given other one.
      int length()  
      IndexRange mergedWith​(IndexRange other)
      Created a new IndexRange that spans all characters between the smallest and the highest index of the two ranges.
      boolean overlapsWith​(IndexRange other)
      Determines whether this range overlaps with the given other one.
      java.lang.String toString()  
      boolean touches​(IndexRange other)
      Determines whether this range immediated follows or precedes the given other one.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • start

        public final int start
        The index of the first character in the range.
      • end

        public final int end
        The index of the character following the last character of the range.
    • Constructor Detail

      • IndexRange

        public IndexRange​(int start,
                          int end)
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Determines whether this range contains no characters.
        Returns:
        true if the end matches the start of the range.
      • length

        public int length()
        Returns:
        the number of characters covered by this range
      • overlapsWith

        public boolean overlapsWith​(IndexRange other)
        Determines whether this range overlaps with the given other one.
        Parameters:
        other - the other range
        Returns:
        true if there is at least one index that is contained in both ranges
      • isPrecededBy

        public boolean isPrecededBy​(IndexRange other)
        Determines whether this range immediated follows the given other one.
        Parameters:
        other - the other range
        Returns:
        true if this range immediated follows the given other one
      • isFollowedBy

        public boolean isFollowedBy​(IndexRange other)
        Determines whether this range is immediated followed by the given other one.
        Parameters:
        other - the other range
        Returns:
        true if this range is immediated followed by the given other one
      • touches

        public boolean touches​(IndexRange other)
        Determines whether this range immediated follows or precedes the given other one.
        Parameters:
        other - the other range
        Returns:
        true if this range immediated follows or precedes the given other one.
      • mergedWith

        public IndexRange mergedWith​(IndexRange other)
        Created a new IndexRange that spans all characters between the smallest and the highest index of the two ranges.
        Parameters:
        other - the other range
        Returns:
        a new IndexRange instance
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object