RegexTrie
public
class
RegexTrie
extends Object
| java.lang.Object | |
| ↳ | com.android.tradefed.util.RegexTrie<V> |
Pattern。List<Pattern>,而不是
List<String>,如标准 trie 中所示。请注意,
retrieve(String...) 方法将与 Pattern 进行逐点匹配,
而不是像标准 trie 中那样检查逐点相等性。因此,对于大型数据集,它的性能可能较差。
您还可以在 Pattern 序列中使用 null 条目作为通配符。 如果
遇到 null,系统将忽略序列中的所有后续条目。
当检索代码遇到 null Pattern 时,它会先等待,看看是否有
更具体的条目与该序列匹配。如果有,即使该条目随后无法匹配,也会继续执行。
如果没有更具体的条目匹配,通配符匹配会将所有剩余的 Strings
添加到捕获列表(如果已启用),并返回与通配符关联的值。
以下是通配符功能的一个简短示例:
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, String... regexen)
|
V
|
put(V value, Pattern... patterns)
向 trie 添加条目。 |
V
|
retrieve(String... strings)
|
V
|
retrieve(List<List<String>> captures, String... strings)
|
String
|
toString()
|
公共构造函数
RegexTrie
public RegexTrie ()
公共方法
清除
public void clear ()
put
public V put (V value,
String... regexen)此辅助方法会接受正则表达式列表作为 String,并在将后续 Pattern 添加到 trie 之前即时编译它们
| 参数 | |
|---|---|
value |
V:要设置的值 |
regexen |
String:必须按顺序匹配的正则表达式序列(作为 String),以检索关联的 value。每个 String 都将在调用 put(Object,Pattern...) 之前
编译为 Pattern。 |
| 返回 | |
|---|---|
V |
|
put
public V put (V value,
Pattern... patterns)向 trie 添加条目。
| 参数 | |
|---|---|
value |
V:要设置的值 |
patterns |
Pattern:必须按顺序匹配的 Pattern 序列,以检索关联的 value |
| 返回 | |
|---|---|
V |
|
检索
public V retrieve (String... strings)
通过将提供的 String 序列与存储在 trie 中的 Pattern 序列进行匹配,从 trie 中提取值。
| 参数 | |
|---|---|
strings |
String:要匹配的 String 序列 |
| 返回 | |
|---|---|
V |
关联的值;如果未找到任何值,则返回 null |
检索
public V retrieve (List<List<String>> captures,
String... strings)通过将提供的 String 序列与存储在 trie 中的 Pattern 序列进行匹配,从 trie 中提取值。此版本的方法还会返回
每个匹配的Pattern的捕获组的List。
外部列表中的每个条目都对应于 trie 中的一个 Pattern 级别。
对于每个级别,系统都会存储捕获组列表。 如果特定级别没有捕获
,系统将存储一个空列表。
请注意,在检索开始之前,captures 将被 List.clear()。
此外,如果检索在部分序列匹配后失败,captures 仍会
反映部分匹配中的捕获组。
| 参数 | |
|---|---|
captures |
List:捕获组将通过 List<List<String>> 返回。 |
strings |
String:要匹配的 String 序列 |
| 返回 | |
|---|---|
V |
关联的值;如果未找到任何值,则返回 null |
toString
public String toString ()
| 返回 | |
|---|---|
String |
|