Class SubclassClassifier<T,C>

java.lang.Object
org.springframework.classify.SubclassClassifier<T,C>
Type Parameters:
T - the type of the thing to classify
C - the output of the classifier
All Implemented Interfaces:
Serializable, Classifier<T,C>
Direct Known Subclasses:
BinaryExceptionClassifier

public class SubclassClassifier<T,C> extends Object implements Classifier<T,C>
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 Details

    • SubclassClassifier

      public SubclassClassifier()
      Create a SubclassClassifier with null default value.
    • SubclassClassifier

      public SubclassClassifier(C defaultValue)
      Create a SubclassClassifier with supplied default value.
      Parameters:
      defaultValue - the default value
    • SubclassClassifier

      public SubclassClassifier(Map<Class<? extends T>,C> typeMap, C defaultValue)
      Create a SubclassClassifier with supplied default value.
      Parameters:
      defaultValue - the default value
      typeMap - the map of types
  • Method Details

    • setDefaultValue

      public void setDefaultValue(C defaultValue)
      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

      public void setTypeMap(Map<Class<? extends T>,C> map)
      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

      public void add(Class<? extends T> type, C target)
      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 object
      target - the target value for all such types
    • classify

      public 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.
      Specified by:
      classify in interface Classifier<T,C>
      Parameters:
      classifiable - the classifiable thing
      Returns:
      C the classified value
    • getDefault

      public final C getDefault()
      Return the default value supplied in the constructor (default false).
      Returns:
      C the default value
    • getClassified

      protected Map<Class<? extends T>,C> getClassified()