正規表示式特里樹

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