Package org.springframework.classify
Class PatternMatchingClassifier<T>
java.lang.Object
org.springframework.classify.PatternMatchingClassifier<T>
- Type Parameters:
T
- the output of the classifier
- All Implemented Interfaces:
Serializable
,Classifier<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
- See Also:
-
Constructor Summary
ConstructorDescriptionDefault constructor.PatternMatchingClassifier
(Map<String, T> values) Create a classifier from the provided map. -
Method Summary
Modifier and TypeMethodDescriptionClassify the input by matching it against the patterns provided insetPatternMap(Map)
.void
setPatternMap
(Map<String, T> values) A map from pattern to value
-
Constructor Details
-
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
Create a classifier from the provided map. The keys are patterns, using '?' as a single character and '*' as multi-character wildcard.- Parameters:
values
- the values to use in thePatternMatcher
-
-
Method Details
-
setPatternMap
A map from pattern to value- Parameters:
values
- the pattern map to set
-
classify
Classify the input by matching it against the patterns provided insetPatternMap(Map)
. The most specific pattern that matches will be used to locate a value.- Specified by:
classify
in interfaceClassifier<String,
T> - Parameters:
classifiable
- the input object. Can be null.- Returns:
- the value matching the most specific pattern possible
- Throws:
IllegalStateException
- if no matching value is found.
-