org.cojen.util
Class PatternMatcher<V>

java.lang.Object
  extended by org.cojen.util.PatternMatcher<V>

public abstract class PatternMatcher<V>
extends Object

Provides fast matching of strings against patterns containing wildcards. An ordinary map must be supplied in order to create a PatternMatcher. The map keys must be strings. Asterisks (*) are treated as wildcard characters.

Author:
Brian S O'Neill

Nested Class Summary
static class PatternMatcher.Result<V>
           
 
Field Summary
protected  V[] mValues
           
 
Constructor Summary
protected PatternMatcher(V[] values)
           
 
Method Summary
protected static boolean addMatchResult(int limit, List results, String pattern, Object value, int[] positions, int len)
           
protected abstract  void fillMatchResults(char[] lookup, int limit, List results)
           
static
<V> PatternMatcher<V>
forPatterns(Map<String,V> patternMap)
           
 PatternMatcher.Result<V> getMatch(String lookup)
          Returns null if no match.
 PatternMatcher.Result<V>[] getMatches(String lookup, int limit)
          Returns an empty array if no matches.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mValues

protected final V[] mValues
Constructor Detail

PatternMatcher

protected PatternMatcher(V[] values)
Method Detail

forPatterns

public static <V> PatternMatcher<V> forPatterns(Map<String,V> patternMap)

getMatch

public PatternMatcher.Result<V> getMatch(String lookup)
Returns null if no match.


getMatches

public PatternMatcher.Result<V>[] getMatches(String lookup,
                                             int limit)
Returns an empty array if no matches.

Parameters:
limit - maximum number of results to return

fillMatchResults

protected abstract void fillMatchResults(char[] lookup,
                                         int limit,
                                         List results)

addMatchResult

protected static boolean addMatchResult(int limit,
                                        List results,
                                        String pattern,
                                        Object value,
                                        int[] positions,
                                        int len)


Copyright © 2004-2011 Brian S O'Neill. All Rights Reserved.