正则表达式特里树
public class RegexTrie
extends Object
java.lang.Object | |
↳ | com.android.tradefed.util.RegexTrie<V> |
RegexTrie 是一个 trie,其中每个ERROR(/Pattern)
。因此,完整的List<Pattern>
而不是List<String>
就像在标准特里树中一样。请注意, retrieve(String)
方法将针对Pattern
进行逐点匹配,而不是像标准 trie 中那样检查逐点相等性。因此,它对于大型数据集可能表现不佳。
Pattern
序列中的null
条目作为通配符。如果遇到null
,则序列中的所有后续条目将被忽略。当检索代码遇到null
Pattern
时,它将首先等待查看是否有更具体的条目与该序列匹配。如果这样做,则该更具体的条目将继续进行,即使它随后无法匹配。如果没有更具体的条目匹配,则通配符匹配会将所有剩余的String
添加到捕获列表(如果启用)并返回与通配符关联的值。通配符功能的简短示例: List<List<String>> captures = new LinkedList<List<String>>(); RegexTrie<Integer> trie = new RegexTrie<Integer>(); trie.put(2, "a", null); trie.put(4, "a", "b"); trie.retrieve(captures, "a", "c", "e"); // returns 2. captures is now [[], ["c"], ["e"]] trie.retrieve(captures, "a", "b"); // returns 4. captures is now [[], []] trie.retrieve(captures, "a", "b", "c"); // returns null. captures is now [[], []]
概括
公共构造函数 | |
---|---|
RegexTrie () |
公共方法 | |
---|---|
void | clear () |
V | put (V value, Pattern... patterns) 向 trie 添加一个条目。 |
V | retrieve (String... strings) 通过将提供的 |
V | retrieve ( captures, String... strings) retrieve ( captures, String... strings) 通过将提供的 |
String | toString () |
公共构造函数
正则表达式特里树
public RegexTrie ()
公共方法
清除
public void clear ()
放
public V put (V value, Pattern... patterns)
向 trie 添加一个条目。
参数 | |
---|---|
value | V :要设置的值 |
patterns | Pattern :必须按顺序匹配才能检索关联value 的ERROR(/Pattern) 序列 |
退货 | |
---|---|
V |
取回
public V retrieve (String... strings)
通过将提供的String
序列与存储在 trie 中的ERROR(/Pattern)
序列进行匹配,从 trie 中获取一个值。
参数 | |
---|---|
strings | String :要匹配的String 序列 |
退货 | |
---|---|
V | 关联值,如果未找到值则为null |
取回
public V retrieve (captures, String... strings)
通过将提供的String
序列与存储在 trie 中的ERROR(/Pattern)
序列进行匹配,从 trie 中获取一个值。此版本的方法还为每个匹配的ERROR(/Pattern)
) 返回捕获组的ERROR(/List)
。
Pattern
。对于每个级别,将存储捕获组的列表。如果特定级别没有捕获,则将存储一个空列表。请注意,在检索开始之前, captures
将被ERROR(/List#clear())
编辑。此外,如果在部分匹配序列后检索失败, captures
仍将反映部分匹配中的捕获组。参数 | |
---|---|
captures | List<List<String>> 。 |
strings | String :要匹配的String 序列 |
退货 | |
---|---|
V | 关联值,如果未找到值则为null |
到字符串
public String toString ()
退货 | |
---|---|
String |