org.qi4j.api.io
Class Transforms

java.lang.Object
  extended by org.qi4j.api.io.Transforms

public class Transforms
extends Object

Utility class for I/O transforms


Nested Class Summary
static class Transforms.Counter<T>
          Count the number of items in the transfer.
static class Transforms.Log<T>
          Log the toString() representation of transferred items to the given log.
static class Transforms.ObjectToString
          Convert objects to Strings using .toString()
static class Transforms.ProgressLog<T>
          Track progress of transfer by emitting a log message in given intervals
static class Transforms.String2Bytes
          Convert strings to bytes using the given CharSet
 
Constructor Summary
Transforms()
           
 
Method Summary
static
<T,ReceiverThrowableType extends Throwable>
Output<T,ReceiverThrowableType>
filter(Specification<? super T> specification, Output<T,ReceiverThrowableType> output)
          Filter items in a transfer by applying the given Specification to each item.
static
<T,ReceiverThrowableType extends Throwable>
Output<T,ReceiverThrowableType>
filteredMap(Specification<? super T> specification, Function<? super T,? extends T> function, Output<T,ReceiverThrowableType> output)
          Apply the given function to items in the transfer that match the given specification.
static
<T,SenderThrowableType extends Throwable>
Input<T,SenderThrowableType>
lock(Lock lock, Input<T,SenderThrowableType> input)
          Wrapper for Outputs that uses a lock whenever a transfer is instantiated.
static
<T,ReceiverThrowableType extends Throwable>
Output<T,ReceiverThrowableType>
lock(Lock lock, Output<T,ReceiverThrowableType> output)
          Wrapper for Outputs that uses a lock whenever a transfer is instantiated.
static
<From,To,ReceiverThrowableType extends Throwable>
Output<From,ReceiverThrowableType>
map(Function<? super From,? extends To> function, Output<To,ReceiverThrowableType> output)
          Map items in a transfer from one type to another by applying the given function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Transforms

public Transforms()
Method Detail

filter

public static <T,ReceiverThrowableType extends Throwable> Output<T,ReceiverThrowableType> filter(Specification<? super T> specification,
                                                                                                 Output<T,ReceiverThrowableType> output)
Filter items in a transfer by applying the given Specification to each item.

Type Parameters:
T -
ReceiverThrowableType -
Parameters:
specification -
output -
Returns:

map

public static <From,To,ReceiverThrowableType extends Throwable> Output<From,ReceiverThrowableType> map(Function<? super From,? extends To> function,
                                                                                                       Output<To,ReceiverThrowableType> output)
Map items in a transfer from one type to another by applying the given function.

Type Parameters:
From -
To -
ReceiverThrowableType -
Parameters:
function -
output -
Returns:

filteredMap

public static <T,ReceiverThrowableType extends Throwable> Output<T,ReceiverThrowableType> filteredMap(Specification<? super T> specification,
                                                                                                      Function<? super T,? extends T> function,
                                                                                                      Output<T,ReceiverThrowableType> output)
Apply the given function to items in the transfer that match the given specification. Other items will pass through directly.

Type Parameters:
T -
ReceiverThrowableType -
Parameters:
specification -
function -
output -
Returns:

lock

public static <T,ReceiverThrowableType extends Throwable> Output<T,ReceiverThrowableType> lock(Lock lock,
                                                                                               Output<T,ReceiverThrowableType> output)
Wrapper for Outputs that uses a lock whenever a transfer is instantiated. Typically a read-lock would be used on the sending side and a write-lock would be used on the receiving side. Inputs can use this as well to create a wrapper on the send side when transferTo is invoked.

Type Parameters:
T -
ReceiverThrowableType -
Parameters:
lock - the lock to be used for transfers
output - output to be wrapped
Returns:
Output wrapper that uses the given lock during transfers.

lock

public static <T,SenderThrowableType extends Throwable> Input<T,SenderThrowableType> lock(Lock lock,
                                                                                          Input<T,SenderThrowableType> input)
Wrapper for Outputs that uses a lock whenever a transfer is instantiated. Typically a read-lock would be used on the sending side and a write-lock would be used on the receiving side.

Type Parameters:
T -
SenderThrowableType -
Parameters:
lock - the lock to be used for transfers
input - input to be wrapped
Returns:
Input wrapper that uses the given lock during transfers.