Class SearchTerm<T>

java.lang.Object
org.apache.nifi.util.search.SearchTerm<T>

public class SearchTerm<T> extends Object
This is an immutable thread safe object representing a search term
  • Field Details

    • bytes

      private final byte[] bytes
    • hashCode

      private final int hashCode
    • reference

      private final T reference
  • Constructor Details

    • SearchTerm

      public SearchTerm(byte[] bytes)
      Constructs a SearchTerm. Defensively copies the given byte array
      Parameters:
      bytes - the bytes of the search term
      Throws:
      IllegalArgumentException - if given bytes are null or 0 length
    • SearchTerm

      public SearchTerm(byte[] bytes, boolean defensiveCopy, T reference)
      Constructs a search term. Optionally performs a defensive copy of the given byte array. If the caller indicates a defensive copy is not necessary then they must not change the given arrays state any longer
      Parameters:
      bytes - the bytes of the new search term
      defensiveCopy - if true will make a defensive copy; false otherwise
      reference - a holder for an object which can be retrieved when this search term hits
  • Method Details

    • get

      public int get(int index)
    • size

      public int size()
      Returns:
      size in of search term in bytes
    • getReference

      public T getReference()
      Returns:
      reference object for this given search term
    • startsWith

      public boolean startsWith(byte[] window, int windowLength)
      Determines if the given window starts with the same bytes as this term
      Parameters:
      window - bytes from the haystack being evaluated
      windowLength - The length of the window to consider
      Returns:
      true if this term starts with the same bytes of the given window
    • getBytes

      public byte[] getBytes()
      Returns:
      a defensive copy of the internal byte structure
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(Charset charset)