de.unkrig.commons.lang.protocol
Class TransformerUtil

java.lang.Object
  extended by de.unkrig.commons.lang.protocol.TransformerUtil

public final class TransformerUtil
extends java.lang.Object

Various Transformer-related utility methods.


Method Summary
static
<I,O> Transformer<I,O>
addMappings(Transformer<I,O> transformer, java.lang.Object... keysAndValues)
           
static
<I,O,EX extends java.lang.RuntimeException>
Transformer<I,O>
asTransformer(TransformerWhichThrows<? super I,? extends O,EX> source)
          Converts a TransformerWhichThrows into a Transformer, which is possible iff: The target's input type is a subclass of the source's input type, and The source's output type is a subclass of the target's output type The source's exception is a subclass of RuntimeException.
static
<I,O,EX extends java.lang.Throwable>
TransformerWhichThrows<I,O,EX>
asTransformerWhichThrows(Transformer<? super I,? extends O> source)
          Converts a Transformer into a TransformerWhichThrows, which is possible iff: The target's input type is a subclass of the source's input type, and The source's output type is a subclass of the target's output type.
static
<I,O> Transformer<I,O>
combine(I extraInput, O extraOutput, Transformer<I,O> delegate)
           
static
<I,O,EX extends java.lang.Exception>
TransformerWhichThrows<I,O,EX>
combine(I extraInput, O extraOutput, TransformerWhichThrows<I,O,EX> delegate)
           
static
<I,O> Transformer<I,O>
fromMappings(java.lang.Object... keysAndValues)
           
static
<O,I extends O>
Transformer<I,O>
identity()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

identity

public static <O,I extends O> Transformer<I,O> identity()
Returns:
A Transformer that transforms any object reference to itself.

asTransformerWhichThrows

public static <I,O,EX extends java.lang.Throwable> TransformerWhichThrows<I,O,EX> asTransformerWhichThrows(Transformer<? super I,? extends O> source)
Converts a Transformer into a TransformerWhichThrows, which is possible iff:

Type Parameters:
I - The transformers' input type
O - The transformers' output type
EX - The target transformer's exception

asTransformer

public static <I,O,EX extends java.lang.RuntimeException> Transformer<I,O> asTransformer(TransformerWhichThrows<? super I,? extends O,EX> source)
Converts a TransformerWhichThrows into a Transformer, which is possible iff:

Type Parameters:
I - The transformers' input type
O - The transformers' output type
EX - The source transformer's exception

combine

public static <I,O> Transformer<I,O> combine(I extraInput,
                                             O extraOutput,
                                             Transformer<I,O> delegate)
Returns:
A Transformer which calls the delegate, except when the subject equals the extraInput, when it returns extraOutput

combine

public static <I,O,EX extends java.lang.Exception> TransformerWhichThrows<I,O,EX> combine(I extraInput,
                                                                                          O extraOutput,
                                                                                          TransformerWhichThrows<I,O,EX> delegate)
Returns:
A TransformerWhichThrows which calls the delegate, except when the subject equals the extraInput, when it returns extraOutput

addMappings

public static <I,O> Transformer<I,O> addMappings(Transformer<I,O> transformer,
                                                 java.lang.Object... keysAndValues)
Returns:
A Transformer in which the given keys and values override the mappings of the delegate.

fromMappings

public static <I,O> Transformer<I,O> fromMappings(java.lang.Object... keysAndValues)
Returns:
A Transformer in which the given keys and values override the mappings of the delegate.