Package org.apache.nutch.util
Class PrefixStringMatcher
- java.lang.Object
-
- org.apache.nutch.util.TrieStringMatcher
-
- org.apache.nutch.util.PrefixStringMatcher
-
public class PrefixStringMatcher extends TrieStringMatcher
A class for efficiently matchingString
s against a set of prefixes.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.nutch.util.TrieStringMatcher
TrieStringMatcher.TrieNode
-
-
Field Summary
-
Fields inherited from class org.apache.nutch.util.TrieStringMatcher
root
-
-
Constructor Summary
Constructors Constructor Description PrefixStringMatcher(String[] prefixes)
Creates a newPrefixStringMatcher
which will matchString
s with any prefix in the supplied array.PrefixStringMatcher(Collection<String> prefixes)
Creates a newPrefixStringMatcher
which will matchString
s with any prefix in the suppliedCollection
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
longestMatch(String input)
Returns the longest prefix ofinput
that is matched, ornull
if no match exists.static void
main(String[] argv)
boolean
matches(String input)
Returns true if the givenString
is matched by a prefix in the trieString
shortestMatch(String input)
Returns the shortest prefix ofinput
that is matched, ornull
if no match exists.-
Methods inherited from class org.apache.nutch.util.TrieStringMatcher
addPatternBackward, addPatternForward, matchChar
-
-
-
-
Constructor Detail
-
PrefixStringMatcher
public PrefixStringMatcher(String[] prefixes)
Creates a newPrefixStringMatcher
which will matchString
s with any prefix in the supplied array. Zero-lengthStrings
are ignored.- Parameters:
prefixes
- A array containing string prefixes
-
PrefixStringMatcher
public PrefixStringMatcher(Collection<String> prefixes)
Creates a newPrefixStringMatcher
which will matchString
s with any prefix in the suppliedCollection
.- Parameters:
prefixes
- A collection containing string prefixes- Throws:
ClassCastException
- if anyObject
s in the collection are notString
s
-
-
Method Detail
-
matches
public boolean matches(String input)
Returns true if the givenString
is matched by a prefix in the trie- Specified by:
matches
in classTrieStringMatcher
- Parameters:
input
- A String to be matched by a pattern- Returns:
- true if there is a match, flase otherwise
-
shortestMatch
public String shortestMatch(String input)
Returns the shortest prefix ofinput
that is matched, ornull
if no match exists.- Specified by:
shortestMatch
in classTrieStringMatcher
- Parameters:
input
- A String to be matched by a pattern- Returns:
- shortest string match or null if no match is made
-
longestMatch
public String longestMatch(String input)
Returns the longest prefix ofinput
that is matched, ornull
if no match exists.- Specified by:
longestMatch
in classTrieStringMatcher
- Parameters:
input
- A String to be matched by a pattern- Returns:
- longest string match or null if no match is made
-
main
public static final void main(String[] argv)
-
-