正则表达式
public class RegexTrie
extends Object
java.lang.Object |
↳ | com.android.tradefed.util.RegexTrie <V> |
RegexTrie是一个Trie,其中每个储存的键的段是regex 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 [[], []]
概要
公共建设者
正则表达式
public RegexTrie ()
公开方法
放
public V put (V value,
Pattern... patterns)
将条目添加到特里。
找回
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 序列 |
toString
public String toString ()