正则表达式特里树
public class RegexTrie
extends Object
java.lang.Object |
↳ | com.android.tradefed.util.RegexTrie<V> |
RegexTrie 是一个 trie,其中每个已存储键的部分是正则表达式ERROR(/Pattern)
。因此,完整的已存储key 是一个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 [[], []]
概括
公共构造函数
正则表达式特里树
public RegexTrie ()
公共方法
放
public V put (V value,
Pattern... patterns)
向 trie 添加一个条目。
取回
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 序列 |
到字符串
public String toString ()