com.codemesh.terp.api
Class Formatter.Pad
java.lang.Object
com.codemesh.terp.api.Transformer.AbstractTransformer<java.lang.CharSequence>
com.codemesh.terp.api.Formatter.AbstractFormatter
com.codemesh.terp.api.Formatter.Pad
- All Implemented Interfaces:
- Formatter, Transformer<java.lang.CharSequence>
- Enclosing interface:
- Formatter
public static class Formatter.Pad
- extends Formatter.AbstractFormatter
A formatter that pads an item with a configurable string to a
configurable width, before or after the item.
The Pad formatter's most common use is to insert a variable
number of spaces in front of a string to create a fixed width,
right-aligned string.
Pad has been generalized from that starting point to be able
to handle arbitrary padding elements, not just spaces and to pad
on the right as well as on the left.
A Pad transform() operations expects at least one argument
which has to be convertible to an integer. This is interpreted
as the width to which the given item is being padded. A second,
optional, argument can be provided to specify the padding text
(a single space by default).
| Nested classes/interfaces inherited from interface com.codemesh.terp.api.Formatter |
Formatter.AbstractFormatter, Formatter.Base64, Formatter.Capitalize, Formatter.Namefy, Formatter.Pad, Formatter.Remove, Formatter.Replace, Formatter.TextFormatter, Formatter.ToAscii, Formatter.ToLowercase, Formatter.ToSlug, Formatter.ToUppercase, Formatter.ToXml, Formatter.Trim |
|
Method Summary |
java.lang.CharSequence |
transform(java.lang.Object item,
java.util.List<java.lang.Object> args,
TerpContext ctx)
Transforms an item into another item, taking optional arguments into account. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Formatter.Pad
public Formatter.Pad(boolean bBefore)
transform
public java.lang.CharSequence transform(java.lang.Object item,
java.util.List<java.lang.Object> args,
TerpContext ctx)
- Transforms an item into another item, taking optional arguments into account.
args is expected to contain at least one element
that will be interpreted as the desired width. An optional second
argument can be provided to specify the padding text.
- Parameters:
item - the item to transform.args - the optional arguments.ctx - the context in which the transformation occurs.
- Returns:
- the transformed item.
Copyright © 2008-2012 by Codemesh, Inc. All Rights Reserved.