net.sourceforge.sstringsearch.replace
Interface Replacer

All Superinterfaces:
Serializable

public interface Replacer
extends Serializable

Project: sstringsearch
File: Replacer.java
Class: Replacer
Created: 6. mai. 2008

Description:

For performing search and replace.

Version:
$Revision$
Author:
Kristian Andersen Email

Method Summary
 void addSearchTerm(String term, ReplacingHitListener listener)
          Adds a new searchterm with a ReplacingHitListener.
 long getNumberOfSearchTerms()
          Get the number of defined searchterms.
 void removeSearchTerm(String term)
          Removes a searchterm.
 void save(OutputStream outputStream)
          Serialize the finite state automata to an outputstream.
 void save(String filename)
          Convience-method to save a finite state automata to file.
 State searchAndReplace(Reader input, Writer result, Object... callbackArguments)
          Does a search and replace on all that provided by the Reader.
 State searchAndReplace(Reader input, Writer result, State state, Object... callbackArguments)
          Does a search and replace on all that provided by the Reader.
 

Method Detail

addSearchTerm

void addSearchTerm(String term,
                   ReplacingHitListener listener)
                   throws IllegalArgumentException
Adds a new searchterm with a ReplacingHitListener. Use this method when you are using StringSearch.searchAndReplace()

Parameters:
term - The searchterm to add.
listener - The ReplacingHitListener used to replace this term in the result.
Throws:
IllegalArgumentException
See Also:
ReplacingHitListener

searchAndReplace

State searchAndReplace(Reader input,
                       Writer result,
                       Object... callbackArguments)
                       throws IOException,
                              IllegalArgumentException,
                              IllegalStateException
Does a search and replace on all that provided by the Reader. The output is written to the specified Writer. Requires that all searchterms are registered with a ReplacingHitListener

Parameters:
input - A reader that provides the data to search through.
result - A Writer where the result is written to
callbackArguments - Arguments that may be included when calling the listener.
Returns:
The state of the finite state automata when finished. This can be used to continue searching from a previous state
Throws:
IOException - If there is a problem reading the data.
IllegalArgumentException - If any of the arguments are invalid.
IllegalStateException - If the FSA is not ready to perform search, e.g. if no searchterms are defined.

searchAndReplace

State searchAndReplace(Reader input,
                       Writer result,
                       State state,
                       Object... callbackArguments)
                       throws IOException,
                              IllegalArgumentException,
                              IllegalStateException
Does a search and replace on all that provided by the Reader. The output is written to the specified Writer. Requires that all searchterms are registered with a ReplacingHitListener

Parameters:
input - A reader that provides the data to search through.
result - A Writer where the result is written to
state - The state to start from.
callbackArguments - Arguments that may be included when calling the listener.
Returns:
The state of the finite state automata when finished. This can be used to continue searching from a previous state
Throws:
IOException - If there is a problem reading the data.
IllegalArgumentException - If any of the arguments are invalid.
IllegalStateException - If the FSA is not ready to perform search, e.g. if no searchterms are defined.

removeSearchTerm

void removeSearchTerm(String term)
Removes a searchterm.

Parameters:
term - The searchterm to remove.

save

void save(OutputStream outputStream)
          throws IOException
Serialize the finite state automata to an outputstream. Useful to avoid building a static finite state automata for each run.

Parameters:
outputStream - The outputstream to write finite state automata to.
Throws:
IOException - If something goes wrong while serializing the class.

save

void save(String filename)
          throws IOException
Convience-method to save a finite state automata to file.

Parameters:
filename - The file to write finite state automata to.
Throws:
IOException - If something goes wrong while serializing the class.

getNumberOfSearchTerms

long getNumberOfSearchTerms()
Get the number of defined searchterms.

Returns:
The number of defined searchterms.


Copyright 2005-2009 Kristian Andersen. All Rights Reserved.