|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.github.fge.jsonschema.core.processing.ProcessorSelector<IN,OUT>
IN - the input type of processorsOUT - the output type of processors@Immutable public final class ProcessorSelector<IN extends MessageProvider,OUT extends MessageProvider>
A processor selector using predicates
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 Summary | |
|---|---|
ProcessorSelector()
Constructor |
|
| Method Summary | |
|---|---|
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 |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ProcessorSelector()
| Method Detail |
|---|
public ProcessorSelectorPredicate<IN,OUT> when(Predicate<IN> predicate)
predicate - the predicate to add
ProcessorSelectorPredicate
NullPointerException - the predicate is nullpublic ProcessorSelector<IN,OUT> otherwise(Processor<IN,OUT> byDefault)
byDefault - the default processor
NullPointerException - default processor is nullpublic Processor<IN,OUT> getProcessor()
The returned processor is immutable: reusing this selector will not affect the result of this method in any way.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||