com.github.fge.jsonschema.core.processing
Class ProcessorMap<K,IN extends MessageProvider,OUT extends MessageProvider>

java.lang.Object
  extended by com.github.fge.jsonschema.core.processing.ProcessorMap<K,IN,OUT>
Type Parameters:
K - the type of keys in the map
IN - the input type of processors
OUT - the output type of processors

public final class ProcessorMap<K,IN extends MessageProvider,OUT extends MessageProvider>
extends Object

Map-based processor selector, with an optional default processor

The processor produced by this class works as follows:

The default action depends on whether a default processor has been supplied: if none exists, a ProcessingException is thrown.

The Function used to extract a key from an input is the only argument of the constructor. It cannot be null.

Note that null keys are not allowed.


Constructor Summary
ProcessorMap(Function<IN,K> keyFunction)
          Constructor
 
Method Summary
 ProcessorMap<K,IN,OUT> addEntry(K key, Processor<IN,OUT> processor)
          Add an entry to the processor map
 Processor<IN,OUT> getProcessor()
          Build the resulting processor from this map selector
 ProcessorMap<K,IN,OUT> setDefaultProcessor(Processor<IN,OUT> defaultProcessor)
          Set the default processor if no matching key is found
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessorMap

public ProcessorMap(Function<IN,K> keyFunction)
Constructor

Parameters:
keyFunction - function to extract a key from an input
Throws:
NullPointerException - key function is null
Method Detail

addEntry

public ProcessorMap<K,IN,OUT> addEntry(K key,
                                       Processor<IN,OUT> processor)
Add an entry to the processor map

Parameters:
key - the key to match against
processor - the processor for that key
Returns:
this
Throws:
NullPointerException - either the key or the processor are null

setDefaultProcessor

public ProcessorMap<K,IN,OUT> setDefaultProcessor(Processor<IN,OUT> defaultProcessor)
Set the default processor if no matching key is found

Parameters:
defaultProcessor - the default processor
Returns:
this
Throws:
NullPointerException - processor is null

getProcessor

public Processor<IN,OUT> getProcessor()
Build the resulting processor from this map selector

The resulting processor is immutable: reusing a map builder after getting the processor by calling this method will not alter the processor you grabbed.

Returns:
the processor for this map selector