public class StartWithMatcher extends Object implements Serializable
If one of the regular expression can be matched from
the first character of the string, they are considered to be matched.
For example:
匹配从字符串的第一个字符开始,只要开头一段完整匹配某个正则表达式,就算是匹配成功。
比如:
I like eating Chinese food --- matched by ---> I .*
I like eating Chinese food --- matched by ---> I like eating.*
I like eating Chinese food --- matched by ---> I
I like eating Chinese food --- matched by ---> I li
I like eating Chinese food --- matched by ---> I like
I like eating Chinese food --- matched by ---> I like eating
I like eating Chinese food --- matched by ---> .* like
I like eating Chinese food --- matched by ---> .* food
I like eating Chinese food --- matched by ---> I .* eating
Normally you don't need to use this class directly, using of its subclasses like
StringStartWithMatcher
or UrlStartWithMatcher
is preferred.
一般来说不需要直接用这个类,应该使用它的子类,比如StringStartWithMatcher
或
UrlStartWithMatcher
。
It's underlying implementation is based on dk.brics.automaton.RunAutomaton.
底层实现基于 dk.brics.automaton.RunAutomaton。
Modifier and Type | Field and Description |
---|---|
protected Object[] |
attachments
runAutomation的每一个state对应一个attachment对象。
|
protected dk.brics.automaton.RunAutomaton |
runAutomaton
实现匹配状态机的引擎
|
Constructor and Description |
---|
StartWithMatcher(Collection<MatchingDefinition> definitionList)
Create an instance according to matching definitions, when creating internal
data structure, choose to consume more memory for better matching speed.
根据匹配方式定义创建一个新的对象实例; 在创建内部数据结构的时候,选择占用更多内存,而换取速度上的提升。 |
StartWithMatcher(Collection<MatchingDefinition> definitionList,
boolean moreSpaceForSpeed)
Create an instance according to matching definitions.
根据匹配方式定义创建一个新的对象实例。 |
StartWithMatcher(StartWithMatcher toBeCopied)
Create a copy, the copy will have exactly the same matching
definitions as the original copy.
创建一个副本,这个副本与原先的对象具有完全相同匹配方式。 |
Modifier and Type | Method and Description |
---|---|
protected dk.brics.automaton.RunAutomaton |
copyRunAutomaton()
Make a copy of the internal state machine (dk.brics.automaton.RunAutomaton) of this instance.
把自己内部的状态机(dk.brics.automaton.RunAutomaton)对象复制一份。 |
protected static String |
escapeForRegExp(String s)
Escape special characters according to syntax of regular expression.
按正则表达式语法,对字符串进行escape。 |
protected List<Integer> |
getAllAcceptedStates(CharSequence text,
int startIndex)
By utilizing the state machine (dk.brics.automaton.RunAutomaton), get all the accepted matching state.
|
protected int |
getLastAcceptedState(CharSequence text)
By utilizing the state machine (dk.brics.automaton.RunAutomaton), get the last accepted matching state.
利用状态机(dk.brics.automaton.RunAutomaton),取得最后一个匹配到的状态。 |
protected int |
getLastAcceptedState(CharSequence text,
int startIndex)
By utilizing the state machine (dk.brics.automaton.RunAutomaton), get the last accepted matching state.
|
protected void |
initialize(Collection<MatchingDefinition> definitionList,
boolean moreSpaceForSpeed)
Initialize the state machine (dk.brics.automaton.RunAutomaton).
初始化状态机(dk.brics.automaton.RunAutomaton)。 |
Object |
match(CharSequence text)
Test if the text string can be matched by any of the regular expression.
|
Object |
match(CharSequence text,
int startIndex)
Begin from the specified position, test if the text string can be matched
by any of the regular expression,
return the attachment of the longest matching one.
从指定位置开始判断文本字符串是否可以被任意一个正则表达式所匹配, 返回所能匹配到的那个最长正则表达式的附件对象。 |
List<Object> |
matchAll(CharSequence text)
Test if the text string can be matched by any of the regular expression,
return list of the attachments of all the matching regular expressions.
判断文本字符串是否可以被任意一个正则表达式所匹配, 返回所有能匹配到的正则表达式的附件对象的列表。 |
List<Object> |
matchAll(CharSequence text,
int startIndex)
Begin from the specified position, test if the text string can be matched
by any of the regular expression,
return list of the attachments of all the matching regular expressions.
从指定位置开始判断文本字符串是否可以被任意一个正则表达式所匹配, 返回所有能匹配到的正则表达式的附件对象的列表。 |
protected void |
setAttachmentByExample(String example,
Object att,
String exp)
Set attachment object for each state, by testing which state the example string can run into.
根据示范字符串,设置各状态所对应的附件对象。 |
protected dk.brics.automaton.RunAutomaton runAutomaton
protected Object[] attachments
public StartWithMatcher(StartWithMatcher toBeCopied)
toBeCopied
- The original copy.public StartWithMatcher(Collection<MatchingDefinition> definitionList)
definitionList
- Matching definitionspublic StartWithMatcher(Collection<MatchingDefinition> definitionList, boolean moreSpaceForSpeed)
definitionList
- Matching definitionsmoreSpaceForSpeed
- Whether or not to consume more memory for better matching speed.protected void initialize(Collection<MatchingDefinition> definitionList, boolean moreSpaceForSpeed)
definitionList
- Matching definitionsmoreSpaceForSpeed
- Whether or not to consume more memory for better matching speed.protected void setAttachmentByExample(String example, Object att, String exp)
example
- Example string.att
- Attachment object.exp
- Regular expression which will only be used within the exception message.protected int getLastAcceptedState(CharSequence text)
text
- The text to be tested.protected int getLastAcceptedState(CharSequence text, int startIndex)
text
- The text to be tested.startIndex
- The position to start matching test.protected List<Integer> getAllAcceptedStates(CharSequence text, int startIndex)
text
- The text to be tested.startIndex
- The position to start matching test.public Object match(CharSequence text, int startIndex)
The test starts from the specified position. Caution: if the beginning part matches, the whole text is considered to match.
匹配从指定的位置开始。 注意:只要开头匹配了就算匹配。
text
- Text string to be tested for matching.startIndex
- The starting position of the testing.public List<Object> matchAll(CharSequence text, int startIndex)
The test starts from the specified position. Caution: if the beginning part matches, the whole text is considered to match.
匹配从指定的位置开始。 注意:只要开头匹配了就算匹配。
text
- Text string to be tested for matching.startIndex
- The starting position of the testing.public Object match(CharSequence text)
The test starts from the beginning. Caution: if the beginning part matches, the whole text is considered to match.
匹配从头开始。 注意:只要开头匹配了就算匹配。
text
- Text string to be tested for matching.public List<Object> matchAll(CharSequence text)
The test starts from the beginning. Caution: if the beginning part matches, the whole text is considered to match.
匹配从头开始。 注意:只要开头匹配了就算匹配。
text
- Text string to be tested for matching.protected static String escapeForRegExp(String s)
s
- The string to be escapedprotected dk.brics.automaton.RunAutomaton copyRunAutomaton() throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
Copyright © 2014. All Rights Reserved.