org.springframework.classify
Class PatternMatchingClassifier<T>

java.lang.Object
  extended by org.springframework.classify.PatternMatchingClassifier<T>
All Implemented Interfaces:
Classifier<java.lang.String,T>

public class PatternMatchingClassifier<T>
extends java.lang.Object
implements Classifier<java.lang.String,T>

A Classifier that maps from String patterns with wildcards to a set of values of a given type. An input String is matched with the most specific pattern possible to the corresponding value in an input map. A default value should be specified with a pattern key of "*".

Author:
Dave Syer

Constructor Summary
PatternMatchingClassifier()
          Default constructor.
PatternMatchingClassifier(java.util.Map<java.lang.String,T> values)
          Create a classifier from the provided map.
 
Method Summary
 T classify(java.lang.String classifiable)
          Classify the input by matching it against the patterns provided in setPatternMap(Map).
 void setPatternMap(java.util.Map<java.lang.String,T> values)
          A map from pattern to value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PatternMatchingClassifier

public PatternMatchingClassifier()
Default constructor. Use the setter or the other constructor to create a sensible classifier, otherwise all inputs will cause an exception.


PatternMatchingClassifier

public PatternMatchingClassifier(java.util.Map<java.lang.String,T> values)
Create a classifier from the provided map. The keys are patterns, using '?' as a single character and '*' as multi-character wildcard.

Parameters:
values -
Method Detail

setPatternMap

public void setPatternMap(java.util.Map<java.lang.String,T> values)
A map from pattern to value

Parameters:
values - the pattern map to set

classify

public T classify(java.lang.String classifiable)
Classify the input by matching it against the patterns provided in setPatternMap(Map). The most specific pattern that matches will be used to locate a value.

Specified by:
classify in interface Classifier<java.lang.String,T>
Parameters:
classifiable - the input object. Can be null.
Returns:
the value matching the most specific pattern possible
Throws:
java.lang.IllegalStateException - if no matching value is found.


Copyright © 2011 SpringSource. All Rights Reserved.