public class SubclassClassifier<T,C> extends Object implements Classifier<T,C>
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.Constructor and Description |
---|
SubclassClassifier()
Create a
SubclassClassifier with null default value. |
SubclassClassifier(C defaultValue)
Create a
SubclassClassifier with supplied default value. |
SubclassClassifier(Map<Class<? extends T>,C> typeMap,
C defaultValue)
Create a
SubclassClassifier with supplied default value. |
Modifier and Type | Method and Description |
---|---|
C |
classify(T classifiable)
Return the value from the type map whose key is the class of the given
Throwable, or its nearest ancestor if a subclass.
|
protected Map<Class<? extends T>,C> |
getClassified() |
C |
getDefault()
Return the default value supplied in the constructor (default false).
|
void |
setDefaultValue(C defaultValue)
Public setter for the default value for mapping keys that are not found
in the map (or their subclasses).
|
void |
setTypeMap(Map<Class<? extends T>,C> map)
Set the classifications up as a map.
|
public SubclassClassifier()
SubclassClassifier
with null default value.public SubclassClassifier(C defaultValue)
SubclassClassifier
with supplied default value.defaultValue
- the default valuepublic void setDefaultValue(C defaultValue)
defaultValue
- the default value to setpublic void setTypeMap(Map<Class<? extends T>,C> map)
map
- a map from type to classpublic C classify(T classifiable)
classify
in interface Classifier<T,C>
classifiable
- the classifiable thingpublic final C getDefault()
Copyright © 2018 SpringSource. All rights reserved.