|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.text.Format
org.jcoderz.commons.logging.FixLengthFormat
public class FixLengthFormat
This is used to format a String to a fixed length String. Strings, which are are longer than the configured length, are split after the appropriate number of chars; Strings which are shorter, are left padded with the configured padding char. When parsing a String, the configured number of chars is read from the source String and the padding char is left trimmed from the resulting String.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.text.Format |
|---|
Format.Field |
| Field Summary | |
|---|---|
static org.jcoderz.commons.logging.FixLengthFormat.Padding |
LEFT_CUT_RIGHT_PADDING
The string is right padded with the padding char to get the full sized string or cut on the left side if it dues not fit the length. |
static org.jcoderz.commons.logging.FixLengthFormat.Padding |
LEFT_PADDING
The string is left padded with the padding char to get the full sized string. |
static org.jcoderz.commons.logging.FixLengthFormat.Padding |
RIGHT_PADDING
The string is right padded with the padding char to get the full sized string. |
| Constructor Summary | |
|---|---|
FixLengthFormat(int fixedLength,
org.jcoderz.commons.logging.FixLengthFormat.Padding type)
Generates an instance of this with the default padding character, which is a space. |
|
FixLengthFormat(int fixedLength,
org.jcoderz.commons.logging.FixLengthFormat.Padding type,
char paddingChar)
Generates an instance of this with paddingChar as padding
character. |
|
| Method Summary | |
|---|---|
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos)
Formats a string to be of a certain length. |
Object |
parseObject(String source,
ParsePosition pos)
Parses the source string for a padded string from the position given by pos. |
| Methods inherited from class java.text.Format |
|---|
clone, format, formatToCharacterIterator, parseObject |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final org.jcoderz.commons.logging.FixLengthFormat.Padding LEFT_PADDING
public static final org.jcoderz.commons.logging.FixLengthFormat.Padding RIGHT_PADDING
public static final org.jcoderz.commons.logging.FixLengthFormat.Padding LEFT_CUT_RIGHT_PADDING
| Constructor Detail |
|---|
public FixLengthFormat(int fixedLength,
org.jcoderz.commons.logging.FixLengthFormat.Padding type)
fixedLength - all formatted strings will have this length, either
they are cut or padded with spaces.type - the type of padding, either LEFT_PADDING or
RIGHT_PADDING
IllegalArgumentException - if fixedLength <= 0
public FixLengthFormat(int fixedLength,
org.jcoderz.commons.logging.FixLengthFormat.Padding type,
char paddingChar)
paddingChar as padding
character.
fixedLength - all formatted strings will have this length, either
they are cut or padded with paddingChartype - the type of padding, either LEFT_PADDING or
RIGHT_PADDINGpaddingChar - the character to use for padding.
IllegalArgumentException - if fixedLength <= 0| Method Detail |
|---|
public Object parseObject(String source,
ParsePosition pos)
pos. It reads the configured number of chars and trims
all chars equal to the padding character, either from left or from right,
according to the configured type of this.
If the given source string is not long enough, the index of
pos is not modified, but the error index is set to its
current index and null is returned.
parseObject in class Formatsource - the string to parsepos - the parse position where to start parsing within
source. This will be updated after parsing.
source;
else parsed String, one-side trimmed from padding char.Format.parseObject(java.lang.String, java.text.ParsePosition)
public StringBuffer format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos)
format in class Formatobj - the String to be formatted, must not be null.toAppendTo - the StringBuffer to which to append the formatted Stringpos - field position
Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||