public class State extends Object
一个状态有如下几个功能
根节点稍有不同,根节点没有 failure 功能,它的“failure”指的是按照字符串路径转移到下一个状态。其他节点则都有failure状态。
| 限定符和类型 | 字段和说明 |
|---|---|
protected int |
depth
模式串的长度,也是这个状态的深度
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addEmit(Collection<String> emits)
添加一些匹配到的模式串
|
void |
addEmit(String keyword)
添加一个匹配到的模式串(这个状态对应着这个模式串)
|
State |
addState(Character character) |
Collection<String> |
emit()
获取这个节点代表的模式串(们)
|
State |
failure()
获取failure状态
|
int |
getDepth()
获取节点深度
|
Collection<State> |
getStates() |
Collection<Character> |
getTransitions() |
State |
nextState(Character character)
按照character转移,根节点转移失败会返回自己(永远不会返回null)
|
State |
nextStateIgnoreRootState(Character character)
按照character转移,任何节点转移失败会返回null
|
void |
setFailure(State failState)
设置failure状态
|
String |
toString() |
public int getDepth()
public void addEmit(String keyword)
keyword - public void addEmit(Collection<String> emits)
emits - public Collection<String> emit()
public State failure()
public void setFailure(State failState)
failState - public State nextState(Character character)
character - public State nextStateIgnoreRootState(Character character)
character - public Collection<State> getStates()
public Collection<Character> getTransitions()
Copyright © 2014–2018 码农场. All rights reserved.