Class SearchResult

java.lang.Object
org.fife.ui.rtextarea.SearchResult
All Implemented Interfaces:
Comparable<SearchResult>

public class SearchResult extends Object implements Comparable<SearchResult>
The result of a find, replace, or "mark all" operation.
Version:
1.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    The number of matches found or replaced.
    private int
    The number of instances marked.
    If a find or replace operation is successful, this will be the range of text representing the found text (for "find" operations) or the replacement text inserted (for "replace" operations; for "replace all" operations this will be the last replacement region).
    private boolean
    Whether this result is from a "wrapping" search - that is, no results were found from caret -> end of document, but a result _was_ found in a subsequent search from document start -> caret.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor; indicates no match is found.
    SearchResult(DocumentRange range, int count, int markedCount)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares this search result to another.
    boolean
    equals(Object other)
    Returns whether this search result represents the same logical result as another.
    int
    Returns the number of matches found or replaced.
    int
    Returns the number of instances marked.
    If a find or replace operation is successful, this will be the range of text representing the found text (for "find" operations) or the replacement text inserted (for "replace" operations; for "replace all" operations this will be the last replacement region).
    int
    Overridden simply as a best practice, since equals(Object) is overridden.
    boolean
    Returns whether this is a 'wrapped' result, meaning it came from a second pass through the document, after an initial search forward or backward from the caret didn't return anything.
    void
    setCount(int count)
    Sets the number of matches found or replaced.
    void
    setMarkedCount(int markedCount)
    Sets the number of marked occurrences found.
    void
    Sets the selected range for this search operation.
    void
    setWrapped(boolean wrapped)
    Marks this search result as a 'wrapped' result; that is, it came from the second pass through a document, after an initial search forward or backward from the caret didn't return anything.
    Returns a string representation of this object.
    boolean
    Returns whether anything was found in this search operation.

    Methods inherited from class java.lang.Object

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

    • matchRange

      private DocumentRange matchRange
      If a find or replace operation is successful, this will be the range of text representing the found text (for "find" operations) or the replacement text inserted (for "replace" operations; for "replace all" operations this will be the last replacement region). If no match was found, or this was a "mark all" operation, this will be null.
    • count

      private int count
      The number of matches found or replaced. For regular "find" and "replace" operations, this will be zero or 1. For "replace all" operations, this will be the number of replacements. For "mark all" operations, this should be zero.
    • markedCount

      private int markedCount
      The number of instances marked.
    • wrapped

      private boolean wrapped
      Whether this result is from a "wrapping" search - that is, no results were found from caret -> end of document, but a result _was_ found in a subsequent search from document start -> caret.
  • Constructor Details

    • SearchResult

      public SearchResult()
      Constructor; indicates no match is found.
    • SearchResult

      public SearchResult(DocumentRange range, int count, int markedCount)
      Constructor.
      Parameters:
      range - The selected range of text after the find or replace operation. This can be null if the selection was not changed.
      count - The number of matches found or replaced. For regular "find" and "replace" operations, this will be zero or 1; for "replace all" operations, this will be the number of replacements.
      markedCount - The number of matches marked. If "mark all" is disabled, this should be zero.
  • Method Details

    • compareTo

      public int compareTo(SearchResult other)
      Compares this search result to another.
      Specified by:
      compareTo in interface Comparable<SearchResult>
      Parameters:
      other - Another search result to compare to.
      Returns:
      How this result object should be sorted compared to other.
    • equals

      public boolean equals(Object other)
      Returns whether this search result represents the same logical result as another.
      Overrides:
      equals in class Object
      Parameters:
      other - Another object (presumably another SearchResult).
    • getCount

      public int getCount()
      Returns the number of matches found or replaced. For regular "find" and "replace" operations, this will be zero or 1. For "replace all" operations, this will be the number of replacements. For "mark all" operations, this will be zero.
      Returns:
      The count.
      See Also:
    • getMarkedCount

      public int getMarkedCount()
      Returns the number of instances marked. If "mark all" was not enabled, this will be 0.
      Returns:
      The number of instances marked.
      See Also:
    • getMatchRange

      public DocumentRange getMatchRange()
      If a find or replace operation is successful, this will be the range of text representing the found text (for "find" operations) or the replacement text inserted (for "replace" operations; for "replace all" operations this will be the last replacement region). If no match was found, or this was a "mark all" operation, this will be null, since they do not update the editor's selection.
      Returns:
      The matched range of text.
      See Also:
    • hashCode

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

      public void setCount(int count)
      Sets the number of matches found or replaced. For regular "find" and "replace" operations, this should be zero or 1. For "replace all" operations, this should be the number of replacements. For "mark all" operations, this should be zero.
      Parameters:
      count - The count.
      See Also:
    • setMarkedCount

      public void setMarkedCount(int markedCount)
      Sets the number of marked occurrences found.
      Parameters:
      markedCount - The number of marked occurrences found.
      See Also:
    • setMatchRange

      public void setMatchRange(DocumentRange range)
      Sets the selected range for this search operation.
      Parameters:
      range - The new selected range.
      See Also:
    • setWrapped

      public void setWrapped(boolean wrapped)
      Marks this search result as a 'wrapped' result; that is, it came from the second pass through a document, after an initial search forward or backward from the caret didn't return anything.
      Parameters:
      wrapped - The new 'wrapped' state. Defaults to false.
      See Also:
    • isWrapped

      public boolean isWrapped()
      Returns whether this is a 'wrapped' result, meaning it came from a second pass through the document, after an initial search forward or backward from the caret didn't return anything.
      Returns:
      true if the result was from a 'wrapping' search; false otherwise.
      See Also:
    • toString

      public String toString()
      Returns a string representation of this object. Useful for debugging.
      Overrides:
      toString in class Object
      Returns:
      A string representation of this object.
    • wasFound

      public boolean wasFound()
      Returns whether anything was found in this search operation. This is shorthand for getCount()>0.
      Returns:
      Whether anything was found in this search operation.
      See Also: