正則表達式特里樹
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 ()