Klasse StringSearch

java.lang.Object
libsidutils.stringsearch.StringSearch
Bekannte direkte Unterklassen:
BNDM, MismatchSearch

abstract class StringSearch extends Object
The base class for String searching implementations. String searching implementations do not maintain state and are thread safe - one instance can be used by as many threads as required.

Most pattern-matching algorithms pre-process the pattern to search for in some way. Subclasses of StringSearch allow retrieving the pre-processed pattern to save the time required to build up character tables.

Some of the Objects returned from processBytes(byte[]), processChars(char[]), might implement the Serializable interface and enable you to serialize pre-processed Objects to disk, see concrete implementations for details.

Version:
1.2
Autor:
Johann Burkard
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
     
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    protected CharIntMap
    createCharIntMap(char[] pattern)
    Returns a CharIntMap of the extent of the given pattern, using no default value.
    protected CharIntMap
    createCharIntMap(char[] pattern, int defaultValue)
    Returns a CharIntMap of the extent of the given pattern, using the specified default value.
    final boolean
    Returns if the Object's class name matches this Object's class name.
    final int
    Returns the hashCode of the Object's Class because all instances of this Class are equal.
    protected final int
    index(byte idx)
    Converts the given byte to an int.
    abstract Object
    processBytes(byte[] pattern)
    Pre-processes a byte array.
    abstract Object
    processChars(char[] pattern)
    Pre-processes a char array
    final int
    searchBytes(byte[] text, byte[] pattern)
    Returns the position in the text at which the pattern was found.
    final int
    searchBytes(byte[] text, byte[] pattern, Object processed)
    Returns the position in the text at which the pattern was found.
    final int
    searchBytes(byte[] text, int textStart, byte[] pattern)
    Returns the position in the text at which the pattern was found.
    final int
    searchBytes(byte[] text, int textStart, byte[] pattern, Object processed)
    Returns the position in the text at which the pattern was found.
    final int
    searchBytes(byte[] text, int textStart, int textEnd, byte[] pattern)
    Returns the position in the text at which the pattern was found.
    abstract int
    searchBytes(byte[] text, int textStart, int textEnd, byte[] pattern, Object processed)
    Returns the position in the text at which the pattern was found.
    final int
    searchChars(char[] text, char[] pattern)
    Returns the position in the text at which the pattern was found.
    final int
    searchChars(char[] text, char[] pattern, Object processed)
    Returns the index of the pattern in the text using the pre-processed Object.
    final int
    searchChars(char[] text, int textStart, char[] pattern)
    Returns the position in the text at which the pattern was found.
    final int
    searchChars(char[] text, int textStart, char[] pattern, Object processed)
    Returns the index of the pattern in the text using the pre-processed Object.
    final int
    searchChars(char[] text, int textStart, int textEnd, char[] pattern)
    Returns the position in the text at which the pattern was found.
    abstract int
    searchChars(char[] text, int textStart, int textEnd, char[] pattern, Object processed)
    Returns the index of the pattern in the text using the pre-processed Object.
    final String
    Returns a String representation of this.
    Appends a String representation of this to the given StringBuffer or creates a new one if none is given.

    Von Klasse geerbte Methoden java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Konstruktordetails

    • StringSearch

      StringSearch()
  • Methodendetails

    • processBytes

      public abstract Object processBytes(byte[] pattern)
      Pre-processes a byte array.
      Parameter:
      pattern - the byte array containing the pattern, may not be null
      Gibt zurück:
      an Object
    • processChars

      public abstract Object processChars(char[] pattern)
      Pre-processes a char array
      Parameter:
      pattern - a char array containing the pattern, may not be null
      Gibt zurück:
      an Object
    • searchBytes

      public final int searchBytes(byte[] text, byte[] pattern)
      Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.
      Parameter:
      text - the byte array containing the text, may not be null
      pattern - the byte array containing the pattern, may not be null
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchBytes

      public final int searchBytes(byte[] text, byte[] pattern, Object processed)
      Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.
      Parameter:
      text - the byte array containing the text, may not be null
      pattern - the pattern to search for, may not be null
      processed - an Object as returned from processBytes(byte[]), may not be null
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchBytes

      public final int searchBytes(byte[] text, int textStart, byte[] pattern)
      Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.
      Parameter:
      text - the byte array containing the text, may not be null
      textStart - at which position in the text the comparing should start
      pattern - the byte array containing the pattern, may not be null
      Gibt zurück:
      int the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchBytes

      public final int searchBytes(byte[] text, int textStart, byte[] pattern, Object processed)
      Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.
      Parameter:
      text - the byte array containing the text, may not be null
      textStart - at which position in the text the comparing should start
      pattern - the pattern to search for, may not be null
      processed -
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchBytes

      public final int searchBytes(byte[] text, int textStart, int textEnd, byte[] pattern)
      Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.
      Parameter:
      text - text the byte array containing the text, may not be null
      textStart - at which position in the text the comparing should start
      textEnd - at which position in the text comparing should stop
      pattern - the byte array containing the pattern, may not be null
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchBytes

      public abstract int searchBytes(byte[] text, int textStart, int textEnd, byte[] pattern, Object processed)
      Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.
      Parameter:
      text - text the byte array containing the text, may not be null
      textStart - at which position in the text the comparing should start
      textEnd - at which position in the text comparing should stop
      pattern - the pattern to search for, may not be null
      processed - an Object as returned from processBytes(byte[]), may not be null
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchChars

      public final int searchChars(char[] text, char[] pattern)
      Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.
      Parameter:
      text - the character array containing the text, may not be null
      pattern - the char array containing the pattern, may not be null
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchChars

      public final int searchChars(char[] text, char[] pattern, Object processed)
      Returns the index of the pattern in the text using the pre-processed Object. Returns -1 if the pattern was not found.
      Parameter:
      text - the character array containing the text, may not be null
      pattern - the char array containing the pattern, may not be null
      processed - an Object as returned from processChars(char[]), may not be null
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchChars

      public final int searchChars(char[] text, int textStart, char[] pattern)
      Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.
      Parameter:
      text - the character array containing the text, may not be null
      textStart - at which position in the text the comparing should start
      pattern - the char array containing the pattern, may not be null
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchChars

      public final int searchChars(char[] text, int textStart, char[] pattern, Object processed)
      Returns the index of the pattern in the text using the pre-processed Object. Returns -1 if the pattern was not found.
      Parameter:
      text - the String containing the text, may not be null
      textStart - at which position in the text the comparing should start
      pattern - the char array containing the pattern, may not be null
      processed - an Object as returned from processChars(char[]), may not be null
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchChars

      public final int searchChars(char[] text, int textStart, int textEnd, char[] pattern)
      Returns the position in the text at which the pattern was found. Returns -1 if the pattern was not found.
      Parameter:
      text - the character array containing the text, may not be null
      textStart - at which position in the text the comparing should start
      textEnd - at which position in the text comparing should stop
      pattern - the char array containing the pattern, may not be null
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
      Siehe auch:
    • searchChars

      public abstract int searchChars(char[] text, int textStart, int textEnd, char[] pattern, Object processed)
      Returns the index of the pattern in the text using the pre-processed Object. Returns -1 if the pattern was not found.
      Parameter:
      text - the String containing the text, may not be null
      textStart - at which position in the text the comparing should start
      textEnd - at which position in the text comparing should stop
      pattern - the pattern to search for, may not be null
      processed - an Object as returned from processChars(char[]), may not be null
      Gibt zurück:
      the position in the text or -1 if the pattern was not found
    • equals

      public final boolean equals(Object obj)
      Returns if the Object's class name matches this Object's class name.
      Setzt außer Kraft:
      equals in Klasse Object
      Parameter:
      obj - the other Object
      Gibt zurück:
      if the Object is equal to this Object
      Siehe auch:
    • hashCode

      public final int hashCode()
      Returns the hashCode of the Object's Class because all instances of this Class are equal.
      Setzt außer Kraft:
      hashCode in Klasse Object
      Gibt zurück:
      an int
      Siehe auch:
    • toString

      public final String toString()
      Returns a String representation of this. Simply returns the name of the Class.
      Setzt außer Kraft:
      toString in Klasse Object
      Gibt zurück:
      a String
      Siehe auch:
    • toStringBuffer

      public StringBuffer toStringBuffer(StringBuffer in)
      Appends a String representation of this to the given StringBuffer or creates a new one if none is given. This method is not final because subclasses might want a different String format.
      Parameter:
      in - the StringBuffer to append to, may be null
      Gibt zurück:
      a StringBuffer
    • createCharIntMap

      protected CharIntMap createCharIntMap(char[] pattern)
      Returns a CharIntMap of the extent of the given pattern, using no default value.
      Parameter:
      pattern - the pattern
      Gibt zurück:
      a CharIntMap
      Siehe auch:
    • createCharIntMap

      protected CharIntMap createCharIntMap(char[] pattern, int defaultValue)
      Returns a CharIntMap of the extent of the given pattern, using the specified default value.
      Parameter:
      pattern - the pattern
      defaultValue - the default value
      Gibt zurück:
      a CharIntMap
      Siehe auch:
    • index

      protected final int index(byte idx)
      Converts the given byte to an int.
      Parameter:
      idx - the byte
      Gibt zurück:
      an int