正則表達式特里樹

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