Package org.springframework.classify
Class SubclassClassifier<T,C>
java.lang.Object
org.springframework.classify.SubclassClassifier<T,C>
- Type Parameters:
T- the type of the thing to classifyC- the output of the classifier
- All Implemented Interfaces:
Serializable,Classifier<T,C>
- Direct Known Subclasses:
BinaryExceptionClassifier
A
Classifier for a parameterised object type based on a map. Classifies objects
according to their inheritance relation with the supplied type map. If the object to be
classified is one of the keys of the provided map, or is a subclass of one of the keys,
then the map entry value for that key is returned. Otherwise, returns the default value
which is null by default.- Author:
- Dave Syer, Gary Russell, Artem Bilan
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate aSubclassClassifierwith null default value.SubclassClassifier(C defaultValue) Create aSubclassClassifierwith supplied default value.Create aSubclassClassifierwith supplied default value. -
Method Summary
Modifier and TypeMethodDescriptionvoidThe key is the type and this will be mapped along with all subclasses to the corresponding value.Return the value from the type map whose key is the class of the given Throwable, or its nearest ancestor if a subclass.final CReturn the default value supplied in the constructor (default false).voidsetDefaultValue(C defaultValue) Public setter for the default value for mapping keys that are not found in the map (or their subclasses).voidsetTypeMap(Map<Class<? extends T>, C> map) Set the classifications up as a map.
-
Constructor Details
-
SubclassClassifier
public SubclassClassifier()Create aSubclassClassifierwith null default value. -
SubclassClassifier
Create aSubclassClassifierwith supplied default value.- Parameters:
defaultValue- the default value
-
SubclassClassifier
Create aSubclassClassifierwith supplied default value.- Parameters:
defaultValue- the default valuetypeMap- the map of types
-
-
Method Details
-
setDefaultValue
Public setter for the default value for mapping keys that are not found in the map (or their subclasses). Defaults to false.- Parameters:
defaultValue- the default value to set
-
setTypeMap
Set the classifications up as a map. The keys are types and these will be mapped along with all their subclasses to the corresponding value. The most specific types will match first.- Parameters:
map- a map from type to class
-
add
The key is the type and this will be mapped along with all subclasses to the corresponding value. The most specific types will match first.- Parameters:
type- the type of the input objecttarget- the target value for all such types
-
classify
Return the value from the type map whose key is the class of the given Throwable, or its nearest ancestor if a subclass.- Specified by:
classifyin interfaceClassifier<T,C> - Parameters:
classifiable- the classifiable thing- Returns:
- C the classified value
-
getDefault
Return the default value supplied in the constructor (default false).- Returns:
- C the default value
-
getClassified
-