Class DocumentRange

  • All Implemented Interfaces:
    java.lang.Comparable<DocumentRange>

    public class DocumentRange
    extends java.lang.Object
    implements java.lang.Comparable<DocumentRange>
    A range of text in a document.
    Version:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int endOffs  
      private int startOffs  
    • Constructor Summary

      Constructors 
      Constructor Description
      DocumentRange​(int startOffs, int endOffs)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(DocumentRange other)
      Compares this document range to another.
      boolean equals​(java.lang.Object other)
      Returns whether this document range is equal to another one.
      int getEndOffset()
      Gets the end offset of the range.
      int getStartOffset()
      Gets the starting offset of the range.
      int hashCode()
      Overridden simply as a best practice, since equals(Object) is overridden.
      boolean isZeroLength()
      Returns whether this document range has zero length.
      void set​(int start, int end)
      Sets the document range.
      java.lang.String toString()
      Returns a string representation of this object.
      DocumentRange translate​(int amount)
      Translates this document range by a given amount.
      • Methods inherited from class java.lang.Object

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

      • startOffs

        private int startOffs
      • endOffs

        private int endOffs
    • Constructor Detail

      • DocumentRange

        public DocumentRange​(int startOffs,
                             int endOffs)
        Constructor.
        Parameters:
        startOffs - The starting offset in the document, inclusive.
        endOffs - The ending offset in the document, exclusive.
        Throws:
        java.lang.IllegalArgumentException - If endOffs is less than startOffs, or either argument is less than zero.
    • Method Detail

      • compareTo

        public int compareTo​(DocumentRange other)
        Compares this document range to another.
        Specified by:
        compareTo in interface java.lang.Comparable<DocumentRange>
        Parameters:
        other - Another document range.
        Returns:
        How the two should be sorted relative to each other.
      • equals

        public boolean equals​(java.lang.Object other)
        Returns whether this document range is equal to another one.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - Another object, presumably a document range.
        Returns:
        Whether other is also a document range, and equal to this one.
      • getEndOffset

        public int getEndOffset()
        Gets the end offset of the range.
        Returns:
        The end offset.
        See Also:
        getStartOffset()
      • getStartOffset

        public int getStartOffset()
        Gets the starting offset of the range.
        Returns:
        The starting offset.
        See Also:
        getEndOffset()
      • hashCode

        public int hashCode()
        Overridden simply as a best practice, since equals(Object) is overridden.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code for this object.
      • isZeroLength

        public boolean isZeroLength()
        Returns whether this document range has zero length. This can happen, for example, with regex searches of forms like "foo|", where the right-hand sub-expression matches empty strings.
        Returns:
        Whether this document range has zero length.
      • set

        public void set​(int start,
                        int end)
        Sets the document range.
        Parameters:
        start - The new start value, inclusive.
        end - The new end value, exclusive.
        Throws:
        java.lang.IllegalArgumentException - If end is less than start, or either argument is less than zero.
      • toString

        public java.lang.String toString()
        Returns a string representation of this object.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this object.
      • translate

        public DocumentRange translate​(int amount)
        Translates this document range by a given amount.
        Parameters:
        amount - The amount to translate this range by.
        Returns:
        This (modified) range.