|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jcmdline.StringFormatHelper
public class StringFormatHelper
A class used to facilitate common String formatting tasks.
Objects of this class contain no data. As such, this class is implemented as a Singleton.
Method Summary | |
---|---|
protected java.lang.String[] |
breakString(java.lang.String s,
int maxLen)
Breaks a String along word boundarys to the specified maximum length. |
java.lang.String |
formatBlockedText(java.lang.String s,
int indent,
int lineLen)
Splits the specified String into lines that are indented by the specified indent and are of length less than or equal to the specified line length. |
java.lang.String |
formatHangingIndent(java.lang.String s,
int indent,
int lineLen)
Formats a string with a hanging indent. |
java.lang.String |
formatLabeledList(java.lang.String[] labels,
java.lang.String[] texts,
java.lang.String divider,
int maxIndent,
int lineLen)
Formats a "labeled list" (like a bullet or numbered list, only with labels for each item). |
static StringFormatHelper |
getHelper()
Gets the one and only instance of the StringFormatHelper |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static StringFormatHelper getHelper()
public java.lang.String formatHangingIndent(java.lang.String s, int indent, int lineLen)
The returned String is formated such that:
lineLen
indent
spaces
indent
- the number of spaces to indent all but the
first line (may be 0)lineLen
- the maximum line lengths
- the string to be formatted
java.lang.IllegalArgumentException
- if lineLen
is less than
indent
or if lineLen
is less than 0.public java.lang.String formatBlockedText(java.lang.String s, int indent, int lineLen)
If s
is null or empty, an empty String is returned.
s
- the String to be formattedindent
- the length of the indent for the text blocklineLen
- the maximum line length for the text block,
including the indent
java.lang.IllegalArgumentException
- if lineLen
is less than
indent
or if lineLen
is less than 0.protected java.lang.String[] breakString(java.lang.String s, int maxLen)
This method returns an array of two strings:
The first String is a line, of length less than maxLen
.
If this String is not the entire passed String, it will
be terminated with a newline.
The second String is the remainder of the original String. If the original String had been broken on a space (as opposed to a newline that had been in the original String) all leading spaces will have been removed. If there is no remainder, null is returned as the second String and no newline will have been appended to the first String.
s
- The String to be broken. If null, will be
converted to an empty string.maxLen
- the maximum line length of the first returned
string
public java.lang.String formatLabeledList(java.lang.String[] labels, java.lang.String[] texts, java.lang.String divider, int maxIndent, int lineLen)
Example:
System.out.println(formatLabeledList( new String[] { "old_file", "new_file" }, new String[] { "the name of the file to copy - this file " + "must already exist, be readable, and " + "end with '.html'", "the name of the file to receive the copy" }, " = ", 20, 80));produces....
old_file = the name of the file to copy - this file must already exist, be readable, and end with '.html' new_file = the name of the file to copy to
labels
- An array of labels.texts
- An array of texts to go with the labels.divider
- The divider to go between the labels and texts. This
will be right-aligned against the texts.maxIndent
- Specifies the maximum indent for the text to be
written out. If the combination of a label and
divider is longer than maxIndent, the text will
be written out in a block starting on the line
following the label and divider, rather than on the
same line.lineLen
- The maximum length of returned lines.
java.lang.IllegalArgumentException
- if labels
and text
do not have the same number of elements.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |