RegexTrie
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
,而非像標準三路檢索一樣檢查逐點相等性。因此,在處理大型資料集時,可能會出現效能不佳的情況。
您也可以在 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(
將提供的 |
String
|
toString()
|
公用建構函式
RegexTrie
public RegexTrie ()
公用方法
清除
public void clear ()
聯繫
public V put (V value, Pattern... patterns)
將項目新增至 trie。
參數 | |
---|---|
value |
V :要設定的值 |
patterns |
Pattern :必須依序比對的 ERROR(/Pattern) 序列,才能擷取相關聯的 value |
傳回 | |
---|---|
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)
。
外部清單中的每個項目都對應至 trie 中的一個 Pattern
層級。系統會為每個層級儲存擷取群組清單。如果特定層級沒有擷取畫面,系統會儲存空白清單。
請注意,在擷取作業開始前,captures
會先進行 ERROR(/List#clear())
作業。此外,如果在部分相符序列後擷取失敗,captures
仍會反映部分相符的擷取群組。
參數 | |
---|---|
captures |
:透過此 List<List<String>> 傳回擷取群組。 |
strings |
String :要比對的 String 序列 |
傳回 | |
---|---|
V |
相關聯的值,如果找不到值則傳回 null |
toString
public String toString ()
傳回 | |
---|---|
String |