net.sf.japaki.text
Class MultiLineTransformer

java.lang.Object
  extended by net.sf.japaki.text.MultiLineTransformer
All Implemented Interfaces:
TwoWayTransformer<String,List<String>>

public class MultiLineTransformer
extends Object
implements TwoWayTransformer<String,List<String>>

Transforms a single line into multiple lines of a defined maximum size.


Constructor Summary
MultiLineTransformer(int linesize)
          Creates a new multiline transformer.
 
Method Summary
 boolean isRetrievable(List<String> input)
          Indicates if the origin of the specified object can be calculated.
static
<B> Parser<B>
newMultiLineParser(Format format, Property<B,String> property, String name, int linesize)
          Creates a parser for a multline string field.
 String retransform(List<String> input)
          Concatenates the strings from the list into a single string.
 List<String> transform(String input)
          Breaks a string into multiple lines, so that each line except the last has the predefined linesize.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiLineTransformer

public MultiLineTransformer(int linesize)
Creates a new multiline transformer.

Parameters:
linesize - the maximum size of an output line
Throws:
IllegalArgumentException - if linesize is smaller than one.
Method Detail

transform

public List<String> transform(String input)
Breaks a string into multiple lines, so that each line except the last has the predefined linesize.

Specified by:
transform in interface TwoWayTransformer<String,List<String>>
Parameters:
input - the text in a single string
Returns:
the text in multiple strings

retransform

public String retransform(List<String> input)
Concatenates the strings from the list into a single string.

Specified by:
retransform in interface TwoWayTransformer<String,List<String>>
Parameters:
input - the text in multiple strings
Returns:
the text in a single string

isRetrievable

public boolean isRetrievable(List<String> input)
Description copied from interface: TwoWayTransformer
Indicates if the origin of the specified object can be calculated. This requires that:
  1. retransform is implemented for this object and does not throw an exception.
  2. The object x returned by retransform is unique, or more formally: transform(o1).equals(transform(o2)) ⇒ o1.equals(o2)
This implies that
 retransform(transform(input)).equals(input)
 
for all objects where the retransformation is defined.

Specified by:
isRetrievable in interface TwoWayTransformer<String,List<String>>
Parameters:
input - the object for which the transformation origin is searched.
Returns:
true if the origin of the specified object can be calculated.

newMultiLineParser

public static <B> Parser<B> newMultiLineParser(Format format,
                                               Property<B,String> property,
                                               String name,
                                               int linesize)
Creates a parser for a multline string field.

Parameters:
format - base format (see LeafParser)
property - the rule how to retrieve and store the value for parsing and formatting, respectively.
name - name of the line parser for logging purposes
linesize - the maximum size of an output line