com.wizzardo.tools.misc
Class BoyerMoore

java.lang.Object
  extended by com.wizzardo.tools.misc.BoyerMoore

public class BoyerMoore
extends Object


Constructor Summary
BoyerMoore(byte[] pattern)
          Creates a precomputed Boyer-Moore byte string search object from the given pattern.
BoyerMoore(byte[] pattern, int offset, int length)
          Creates a precomputed Boyer-Moore byte string search object from a portion of the given pattern array.
BoyerMoore(String pattern)
          Creates a precomputed Boyer-Moore byte string search object from the given pattern.
 
Method Summary
 int getPatternLength()
          Returns the length of the pattern for this searcher.
 int search(byte[] byteString)
          Search for the previously pre-compiled pattern string in an array of bytes.
 int search(byte[] byteString, int offset, int length)
          Search for the previously pre-compiled pattern string in an array of bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoyerMoore

public BoyerMoore(String pattern)
Creates a precomputed Boyer-Moore byte string search object from the given pattern. The unicode characters in pattern are truncated if greater than 255, and converted in twos-complement fashion, to appropriate negative byte values, if necessary. This method is provided as a convenience for searching for patterns within 8 bit byte strings composed of character data.

Parameters:
pattern - The pattern create this object for.

BoyerMoore

public BoyerMoore(byte[] pattern)
Creates a precomputed Boyer-Moore byte string search object from the given pattern.

Parameters:
pattern - Binary pattern to search for.

BoyerMoore

public BoyerMoore(byte[] pattern,
                  int offset,
                  int length)
Creates a precomputed Boyer-Moore byte string search object from a portion of the given pattern array.

Parameters:
pattern - Byte array containing a pattern to search for.
offset - Offset to beginning of search pattern.
length - Length of the search pattern.
Method Detail

getPatternLength

public int getPatternLength()
Returns the length of the pattern for this searcher.

Returns:
The search pattern length.

search

public int search(byte[] byteString)
Search for the previously pre-compiled pattern string in an array of bytes. This method uses the Boyer-Moore pattern search algorithm.

Parameters:
byteString - Array of bytes in which to search for the pattern.
Returns:
The array index where the pattern begins in the string, or -1 if the pattern was not found.

search

public int search(byte[] byteString,
                  int offset,
                  int length)
Search for the previously pre-compiled pattern string in an array of bytes. This method uses the Boyer-Moore pattern search algorithm.

Parameters:
byteString - Array of bytes in which to search for the pattern.
offset - The the index in byteString where the search is to begin.
length - The number of bytes to search in byteString.
Returns:
The array index where the pattern begins in the string, or -1 if the pattern was not found.


Copyright © 2015. All Rights Reserved.