正则表达式特里树

public class RegexTrie
extends Object

java.lang.Object
com.android.tradefed.util.RegexTrie<V>


RegexTrie 是一个 trie,其中每个已存储键的部分是正则表达式ERROR(/Pattern) 。因此,完整的已存储key 是一个List&lt;Pattern&gt;而不是List&lt;String&gt;就像在标准特里树中一样。请注意, 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)

通过将提供的String序列与存储在 trie 中的ERROR(/Pattern)序列进行匹配,从 trie 中获取一个值。

V retrieve ( captures, String... strings) retrieve ( captures, String... strings)

通过将提供的String序列与存储在 trie 中的ERROR(/Pattern)序列进行匹配,从 trie 中获取一个值。

String toString ()

公共构造函数

正则表达式特里树

public RegexTrie ()

公共方法

清除

public void clear ()

public V put (V value, 
                Pattern... patterns)

向 trie 添加一个条目。

参数
value V :要设置的值

patterns Pattern :必须按顺序匹配才能检索关联valueERROR(/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