Javadoc
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1099416 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7699d19aaa
commit
154da561fd
|
@ -26,17 +26,24 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides utilities for working with {@link Formattable}s.
|
* <p>Provides utilities for working with the {@code Formattable} interface.</p>
|
||||||
|
*
|
||||||
|
* <p>The {@link Formattable} interface provides basic control over formatting
|
||||||
|
* when using a {@code Formatter}. It is primarily concerned with numeric precision
|
||||||
|
* and padding, and is not designed to allow generalised alternate formats.</p>
|
||||||
*
|
*
|
||||||
* @since Lang 3.0
|
* @since Lang 3.0
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class FormattableUtils {
|
public class FormattableUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A format that simply outputs the value as a string.
|
||||||
|
*/
|
||||||
private static final String SIMPLEST_FORMAT = "%s";
|
private static final String SIMPLEST_FORMAT = "%s";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>{@link FormattableUtils} instances should NOT be constructed in
|
* <p>{@code FormattableUtils} instances should NOT be constructed in
|
||||||
* standard programming. Instead, the methods of the class should be invoked
|
* standard programming. Instead, the methods of the class should be invoked
|
||||||
* statically.</p>
|
* statically.</p>
|
||||||
*
|
*
|
||||||
|
@ -47,28 +54,29 @@ public class FormattableUtils {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* Get the default formatted representation of the specified
|
* Get the default formatted representation of the specified
|
||||||
* {@link Formattable}.
|
* {@code Formattable}.
|
||||||
*
|
*
|
||||||
* @param formattable to convert to a String
|
* @param formattable the instance to convert to a string, not null
|
||||||
* @return String
|
* @return the resulting string, not null
|
||||||
*/
|
*/
|
||||||
public static String toString(Formattable formattable) {
|
public static String toString(Formattable formattable) {
|
||||||
return String.format(SIMPLEST_FORMAT, formattable);
|
return String.format(SIMPLEST_FORMAT, formattable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the common {@link Formattable} operations of truncate-pad-append,
|
* Handles the common {@code Formattable} operations of truncate-pad-append,
|
||||||
* with no ellipsis on precision overflow, and padding width underflow with
|
* with no ellipsis on precision overflow, and padding width underflow with
|
||||||
* spaces.
|
* spaces.
|
||||||
*
|
*
|
||||||
* @param seq to handle
|
* @param seq the string to handle, not null
|
||||||
* @param formatter destination
|
* @param formatter the destination formatter, not null
|
||||||
* @param flags for formatting
|
* @param flags the flags for formatting, see {@code Formattable}
|
||||||
* @param width of output
|
* @param width the width of the output, see {@code Formattable}
|
||||||
* @param precision of output
|
* @param precision the precision of the output, see {@code Formattable}
|
||||||
* @return {@code formatter}
|
* @return the {@code formatter} instance, not null
|
||||||
*/
|
*/
|
||||||
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width,
|
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width,
|
||||||
int precision) {
|
int precision) {
|
||||||
|
@ -79,13 +87,13 @@ public class FormattableUtils {
|
||||||
* Handles the common {@link Formattable} operations of truncate-pad-append,
|
* Handles the common {@link Formattable} operations of truncate-pad-append,
|
||||||
* with no ellipsis on precision overflow.
|
* with no ellipsis on precision overflow.
|
||||||
*
|
*
|
||||||
* @param seq to handle
|
* @param seq the string to handle, not null
|
||||||
* @param formatter destination
|
* @param formatter the destination formatter, not null
|
||||||
* @param flags for formatting
|
* @param flags the flags for formatting, see {@code Formattable}
|
||||||
* @param width of output
|
* @param width the width of the output, see {@code Formattable}
|
||||||
* @param precision of output
|
* @param precision the precision of the output, see {@code Formattable}
|
||||||
* @param padChar to use
|
* @param padChar the pad character to use
|
||||||
* @return {@code formatter}
|
* @return the {@code formatter} instance, not null
|
||||||
*/
|
*/
|
||||||
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width,
|
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width,
|
||||||
int precision, char padChar) {
|
int precision, char padChar) {
|
||||||
|
@ -96,14 +104,14 @@ public class FormattableUtils {
|
||||||
* Handles the common {@link Formattable} operations of truncate-pad-append,
|
* Handles the common {@link Formattable} operations of truncate-pad-append,
|
||||||
* padding width underflow with spaces.
|
* padding width underflow with spaces.
|
||||||
*
|
*
|
||||||
* @param seq to handle
|
* @param seq the string to handle, not null
|
||||||
* @param formatter destination
|
* @param formatter the destination formatter, not null
|
||||||
* @param flags for formatting
|
* @param flags the flags for formatting, see {@code Formattable}
|
||||||
* @param width of output
|
* @param width the width of the output, see {@code Formattable}
|
||||||
* @param precision of output
|
* @param precision the precision of the output, see {@code Formattable}
|
||||||
* @param ellipsis to use when precision dictates truncation; a {@code null}
|
* @param ellipsis the ellipsos to use when precision dictates truncation, null or
|
||||||
* or empty value causes a hard truncation
|
* empty causes a hard truncation
|
||||||
* @return {@code formatter}
|
* @return the {@code formatter} instance, not null
|
||||||
*/
|
*/
|
||||||
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width,
|
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width,
|
||||||
int precision, CharSequence ellipsis) {
|
int precision, CharSequence ellipsis) {
|
||||||
|
@ -113,15 +121,15 @@ public class FormattableUtils {
|
||||||
/**
|
/**
|
||||||
* Handles the common {@link Formattable} operations of truncate-pad-append.
|
* Handles the common {@link Formattable} operations of truncate-pad-append.
|
||||||
*
|
*
|
||||||
* @param seq to handle
|
* @param seq the string to handle, not null
|
||||||
* @param formatter destination
|
* @param formatter the destination formatter, not null
|
||||||
* @param flags for formatting
|
* @param flags the flags for formatting, see {@code Formattable}
|
||||||
* @param width of output
|
* @param width the width of the output, see {@code Formattable}
|
||||||
* @param precision of output
|
* @param precision the precision of the output, see {@code Formattable}
|
||||||
* @param padChar to use
|
* @param padChar the pad character to use
|
||||||
* @param ellipsis to use when precision dictates truncation; a {@code null}
|
* @param ellipsis the ellipsos to use when precision dictates truncation, null or
|
||||||
* or empty value causes a hard truncation
|
* empty causes a hard truncation
|
||||||
* @return {@code formatter}
|
* @return the {@code formatter} instance, not null
|
||||||
*/
|
*/
|
||||||
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width,
|
public static Formatter append(CharSequence seq, Formatter formatter, int flags, int width,
|
||||||
int precision, char padChar, CharSequence ellipsis) {
|
int precision, char padChar, CharSequence ellipsis) {
|
||||||
|
@ -139,4 +147,5 @@ public class FormattableUtils {
|
||||||
formatter.format(buf.toString());
|
formatter.format(buf.toString());
|
||||||
return formatter;
|
return formatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue