IN - the input type of processorsOUT - the output type of processors@Immutable public final class ProcessorSelector<IN extends MessageProvider,OUT extends MessageProvider> extends Object
This class allows you pair processors with a set of Predicates.
Internally, it uses a LinkedHashMap where keys are predicates on
the input type IN, and values are processors to use if this
predicate returns true.
As it is a LinkedHashMap, order matters: the first added predicate
will be evaluated first, etc. If no predicate evaluates to true, the
default action takes place. Depending on whether you have set a default
processor, this processor will be selected, or a ProcessingException
will be thrown indicating that no appropriate selector could be found for the
input.
Sample usage:
final Processor<X, Y> processor
= new ProcessorSelector<X, Y>()
.when(predicate1).then(processor1)
.when(predicate2).then(processor2)
.otherwise(byDefault)
.getProcessor();
The returned processor is immutable.
ProcessorSelectorPredicate| Constructor and Description |
|---|
ProcessorSelector()
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
Processor<IN,OUT> |
getProcessor()
Build the processor from this selector
|
ProcessorSelector<IN,OUT> |
otherwise(Processor<IN,OUT> byDefault)
Set a default processor
|
ProcessorSelectorPredicate<IN,OUT> |
when(Predicate<IN> predicate)
Add a predicate
|
public ProcessorSelectorPredicate<IN,OUT> when(Predicate<IN> predicate)
predicate - the predicate to addProcessorSelectorPredicateProcessorBuildError - the predicate is nullpublic ProcessorSelector<IN,OUT> otherwise(Processor<IN,OUT> byDefault)
byDefault - the default processorProcessorBuildError - default processor is nullCopyright © 2013. All Rights Reserved.