正規表示式特里樹
public class RegexTrie
extends Object
java.lang.Object | |
↳ | com.android.tradefed.util.RegexTrie<V> |
RegexTrie 是一個 trie,其中每個ERROR(/Pattern)
。因此,完整的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 [[], []]
概括
公共構造函數 | |
---|---|
RegexTrie () |
公共方法 | |
---|---|
void | clear () |
V | put (V value, Pattern... patterns) 在 trie 新增一個條目。 |
V | retrieve (String... strings) 透過將提供的 |
V | retrieve ( captures, String... strings) retrieve ( captures, String... strings) 透過將提供的 |
String | toString () |
公共構造函數
正規表示式特里樹
public RegexTrie ()
公共方法
清除
public void clear ()
放
public V put (V value, Pattern... patterns)
在 trie 新增一個條目。
參數 | |
---|---|
value | V :要設定的值 |
patterns | Pattern :必須依序比對才能檢索關聯value 的ERROR(/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 |