org.springframework.batch.classify
Class SubclassClassifier<T,C>

java.lang.Object
  extended by org.springframework.batch.classify.SubclassClassifier<T,C>
All Implemented Interfaces:
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

Constructor Summary
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.
 
Method Summary
 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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubclassClassifier

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


SubclassClassifier

public SubclassClassifier(C defaultValue)
Create a SubclassClassifier with supplied default value.

Parameters:
defaultValue -

SubclassClassifier

public SubclassClassifier(Map<Class<? extends T>,C> typeMap,
                          C defaultValue)
Create a SubclassClassifier with supplied default value.

Parameters:
defaultValue -
Method Detail

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

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 input object. Can be null.
Returns:
an object. Can be null, but implementations should declare if this is the case.

getDefault

public final C getDefault()
Return the default value supplied in the constructor (default false).



Copyright © 2013 SpringSource. All Rights Reserved.