AI
- abstract input symbol type.AO
- abstract output symbol type.CI
- concrete input symbol type.CO
- concrete output symbol type.public interface Mapper<AI,AO,CI,CO>
SUL
from an "abstract" to a "concrete" level.
The notion of "abstract" and "concrete" is not universally defined, and mostly depends
on the chosen perspective. Generally speaking, the point of a Mapper<AI,AO,CI,CO>
is to translate a SUL<CI,CO>
into a SUL<AI,AO>
, and additionally provide
facilities to map exceptions occurring at the concrete level to symbols at the abstract level.
The class Mappers
provides static utility functions for manipulating mappers.
Mappers, like SUL
s, may be forkable
. The requirements and semantics
of fork()
are basically the same as set forth for SUL.fork()
. Stateless
mappers (e.g., with empty pre()
and post()
implementations), should always
be forkable, and fork()
may just return this
. Stateful mappers may require
more sophisticated fork logic, but in general it should be possible to fork them as well.
Note: despite the above recommendation that mappers should almost always be forkable,
the default implementations of canFork()
and fork()
indicate
non-forkability for backwards compatibility reasons.
Modifier and Type | Interface and Description |
---|---|
static class |
Mapper.MappedException<AO> |
Modifier and Type | Method and Description |
---|---|
default boolean |
canFork()
Checks whether it is possible to
fork this mapper. |
default Mapper<AI,AO,CI,CO> |
fork()
Forks this mapper, i.e., returns a mapper that behaves in exactly the same way
as this mapper, but allows for being used independently of this mapper.
|
CI |
mapInput(AI abstractInput)
Method that maps an abstract input to a corresponding concrete input.
|
AO |
mapOutput(CO concreteOutput)
Method that maps a concrete output to a corresponding abstract output.
|
Mapper.MappedException<? extends AO> |
mapUnwrappedException(RuntimeException exception)
Maps an unwrapped
RuntimeException to an abstract output symbol, or rethrows
it if it is unmappable. |
Mapper.MappedException<? extends AO> |
mapWrappedException(SULException exception)
Maps a wrapped
SULException to an abstract output symbol, or rethrows it
if it is unmappable. |
void |
post()
Method that is invoked after all translation steps on a word are performed.
|
void |
pre()
Method that is invoked before any translation steps on a word are performed.
|
void pre()
void post()
CI mapInput(AI abstractInput)
abstractInput
- the abstract inputAO mapOutput(CO concreteOutput)
concreteOutput
- the concrete outputMapper.MappedException<? extends AO> mapWrappedException(SULException exception) throws SULException
SULException
to an abstract output symbol, or rethrows it
if it is unmappable.exception
- the wrapped exception that was thrownSULException
- if the exception cannot be mapped, or if a new exception
occurs while trying to map the given exceptionMapper.MappedException<? extends AO> mapUnwrappedException(RuntimeException exception) throws SULException, RuntimeException
RuntimeException
to an abstract output symbol, or rethrows
it if it is unmappable.exception
- the runtime exception that was thrownSULException
- if a new exception occurs while trying to map the given exceptionRuntimeException
- if the given exception cannot be mapped, or if a new
exception occurs while trying to map the given exceptiondefault boolean canFork()
fork
this mapper.true
if this mapper can be forked, false
otherwise.@Nonnull default Mapper<AI,AO,CI,CO> fork() throws UnsupportedOperationException
If canFork()
returned false
, this method must throw an
UnsupportedOperationException
. Otherwise, it must return a
non-null
object representing the fork of this mapper.
this
should
be returned)UnsupportedOperationException
- if this mapper is not forkableCopyright © 2015. All rights reserved.