RegexTrie
public
class
RegexTrie
extends Object
| java.lang.Object | |
| ↳ | com.android.tradefed.util.RegexTrie<V> |
RegexTrie 是 Trie,其中每個Pattern。因此,完整的「儲存」List<Pattern>,而不是標準 Trie 中的 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, String... regexen)
這個輔助方法會將規則運算式清單做為 |
V
|
put(V value, Pattern... patterns)
在 Trie 中新增項目。 |
V
|
retrieve(String... strings)
|
V
|
retrieve(List<List<String>> captures, String... strings)
|
String
|
toString()
|
公用建構函式
RegexTrie
public RegexTrie ()
公用方法
清除
public void clear ()
put
public V put (V value,
String... regexen)這個輔助方法會將規則運算式清單做為 String,並在新增後續 Pattern 至特里樹之前,即時編譯這些規則運算式
| 參數 | |
|---|---|
value |
V:要設定的值 |
regexen |
String:必須依序比對的規則運算式序列 (如 String),才能擷取相關聯的 value。每個字串都會在叫用 put(Object,Pattern...) 前編譯為 Pattern。 |
| 傳回 | |
|---|---|
V |
|
put
public V put (V value,
Pattern... patterns)在 Trie 中新增項目。
| 參數 | |
|---|---|
value |
V:要設定的值 |
patterns |
Pattern:必須依序比對的 Pattern 序列,才能擷取相關聯的 value |
| 傳回 | |
|---|---|
V |
|
擷取
public V retrieve (String... strings)
方法是將提供的 String 序列與儲存在前置樹中的 Pattern 序列比對,從前置樹擷取值。
| 參數 | |
|---|---|
strings |
String:要比對的 String 序列 |
| 傳回 | |
|---|---|
V |
相關聯的值,或 null (如果找不到值) |
擷取
public V retrieve (List<List<String>> captures,
String... strings)從前置樹狀結構擷取值,方法是將提供的 String 序列與儲存在前置樹狀結構中的 Pattern 序列比對。這個方法版本也會針對每個相符的 Pattern 傳回擷取群組的 List。
外部 List 中的每個項目都對應於 trie 中的一個 Pattern 層級。系統會儲存每個層級的擷取群組清單。如果特定層級沒有任何擷取內容,系統會儲存空白清單。
請注意,系統會在開始擷取前capturesList.clear()captures。此外,如果擷取作業在部分序列相符後失敗,captures 仍會反映部分相符的擷取群組。
| 參數 | |
|---|---|
captures |
List:系統會透過這個 List<List<String>> 傳回擷取群組。 |
strings |
String:要比對的 String 序列 |
| 傳回 | |
|---|---|
V |
相關聯的值,或 null (如果找不到值) |
toString
public String toString ()
| 傳回 | |
|---|---|
String |
|