Class PrefixStringMatcher

java.lang.Object
org.apache.nutch.util.TrieStringMatcher
org.apache.nutch.util.PrefixStringMatcher

public class PrefixStringMatcher extends TrieStringMatcher
A class for efficiently matching Strings against a set of prefixes.
  • Constructor Details

    • PrefixStringMatcher

      public PrefixStringMatcher(String[] prefixes)
      Creates a new PrefixStringMatcher which will match Strings with any prefix in the supplied array. Zero-length Strings are ignored.
      Parameters:
      prefixes - A array containing string prefixes
    • PrefixStringMatcher

      public PrefixStringMatcher(Collection<String> prefixes)
      Creates a new PrefixStringMatcher which will match Strings with any prefix in the supplied Collection.
      Parameters:
      prefixes - A collection containing string prefixes
      Throws:
      ClassCastException - if any Objects in the collection are not Strings
  • Method Details

    • matches

      public boolean matches(String input)
      Returns true if the given String is matched by a prefix in the trie
      Specified by:
      matches in class TrieStringMatcher
      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 of input that is matched, or null if no match exists.
      Specified by:
      shortestMatch in class TrieStringMatcher
      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 of input that is matched, or null if no match exists.
      Specified by:
      longestMatch in class TrieStringMatcher
      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)