Package com.yahoo.fsa
Class FSA
java.lang.Object
com.yahoo.fsa.FSA
- All Implemented Interfaces:
Closeable
,AutoCloseable
Finite-State Automaton.
- Author:
- Peter Boros
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Class used to iterate over all accepted strings in the fsa.static class
Thread local state object used to traverse a Finite-State Automaton. -
Constructor Summary
ConstructorDescriptionFSA
(FileInputStream file) Loads an FSA from a file input stream using utf-8 encodingFSA
(FileInputStream file, String charsetname) Loads an FSA from a file using utf-8 encodingLoads an FSA from a file using the specified character encoding. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected ByteBuffer
data
(int state) Retrieves data for the given state using the underlying fsa data buffer.protected String
dataString
(int state) Retrieves data for the given state using the underlying fsa data buffer.protected int
delta
(int state, byte symbol) getState()
protected int
hashDelta
(int state, byte symbol) boolean
protected boolean
isFinal
(int state) boolean
isOk()
iterator()
Returns a new iterator to the start state.Returns a new iterator to the given state.static FSA
loadFromResource
(String resourceFileName, Class<?> loadingClass) Loads an FSA from a resource file name, which is resolved from the class path of the class loader of the given class.Convenience method that returns the metadata string in the fsa for the input lookup String, or null if the input string does not exist in the fsa.static void
int
serial()
protected int
start()
int
version()
-
Constructor Details
-
FSA
Loads an FSA from a file using utf-8 encoding- Throws:
IllegalArgumentException
- if the file is not found
-
FSA
Loads an FSA from a file using the specified character encoding.- Throws:
IllegalArgumentException
- if the file is not found
-
FSA
Loads an FSA from a file input stream using utf-8 encoding -
FSA
-
-
Method Details
-
getState
-
iterator
Returns a new iterator to the start state. -
iterator
Returns a new iterator to the given state.- Parameters:
state
- the state to create the iterator from.
-
loadFromResource
Loads an FSA from a resource file name, which is resolved from the class path of the class loader of the given class.This is useful for loading fsa's deployed within OSGi bundles.
- Parameters:
resourceFileName
- the name of the file, relative to any element on the classpath. For example, if the classpath contains resources/ and the file is resources/myfsa.fsa this argument should be myfsa.fsaloadingClass
- a class which provides the class loader to use for loading. Any class which is loaded from the same class path as the resource will do (e.g with OSGi - any class in the same bundle jar)- Returns:
- the loaded FSA
- Throws:
RuntimeException
- if the class could not be loaded
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
isOk
public boolean isOk() -
hasPerfectHash
public boolean hasPerfectHash() -
version
public int version() -
serial
public int serial() -
start
protected int start() -
delta
protected int delta(int state, byte symbol) -
hashDelta
protected int hashDelta(int state, byte symbol) -
isFinal
protected boolean isFinal(int state) -
data
Retrieves data for the given state using the underlying fsa data buffer.- Parameters:
state
- The fsa state to retrieve data from.- Returns:
- A new buffer containing the data for the given state.
-
dataString
Retrieves data for the given state using the underlying fsa data buffer.- Parameters:
state
- The fsa state to retrieve data from.- Returns:
- A string representation of the data for the given state.
-
lookup
Convenience method that returns the metadata string in the fsa for the input lookup String, or null if the input string does not exist in the fsa.- Parameters:
str
- The string to look up.- Returns:
- Metadata string from the fsa.
-
main
-