Package com.overzealous.remark.util
Class StringUtils
- java.lang.Object
-
- com.overzealous.remark.util.StringUtils
-
public class StringUtils extends Object
A small collection of utilities for manipulating strings.- Author:
- Phil DeJarnett
-
-
Field Summary
Fields Modifier and Type Field Description static intALIGN_CENTERRepresents centered alignment.static intALIGN_LEFTRepresents left alignment.static intALIGN_RIGHTRepresents right alignment.
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidalign(PrintWriter output, String s, int width, char paddingChar, int alignment)Pads out a left-, right-, or center-aligned string using the specified character up to the specified width.static voidalign(PrintWriter output, String s, int width, int alignment)Pads out a left-, right-, or center-aligned string using spaces up to the specified width.static Stringalign(String s, int width, char paddingChar, int alignment)Pads out a left-, right-, or center-aligned string using the specified character up to the specified width.static Stringalign(String s, int width, int alignment)Pads out a left-, right-, or center-aligned string using spaces up to the specified width.static Stringmultiply(char c, int count)Duplicates the given charactercounttimes.static voidmultiply(PrintWriter output, char c, int count)Duplicates the given charactercounttimes to the Writer.static voidmultiply(PrintWriter output, String s, int count)Duplicates the given stringcounttimes to the Writer.static Stringmultiply(String s, int count)Duplicates the given stringcounttimes.static voidprependEachLine(PrintWriter output, String s, String prependWith)Prepends a specific string to the front of each line of an input string.static StringprependEachLine(String s, String prependWith)Prepends a specific string to the front of each line of an input string.
-
-
-
Field Detail
-
ALIGN_LEFT
public static final int ALIGN_LEFT
Represents left alignment.- See Also:
- Constant Field Values
-
ALIGN_CENTER
public static final int ALIGN_CENTER
Represents centered alignment.- See Also:
- Constant Field Values
-
ALIGN_RIGHT
public static final int ALIGN_RIGHT
Represents right alignment.- See Also:
- Constant Field Values
-
-
Method Detail
-
align
public static String align(String s, int width, int alignment)
Pads out a left-, right-, or center-aligned string using spaces up to the specified width.- Parameters:
s- String to padwidth- Minimum width of final stringalignment- How to align the string < 0 means left, 0 means center, and > 0 means right- Returns:
- Padded string
-
align
public static String align(String s, int width, char paddingChar, int alignment)
Pads out a left-, right-, or center-aligned string using the specified character up to the specified width.- Parameters:
s- String to padwidth- Minimum width of final stringpaddingChar- Character to pad withalignment- How to align the string < 0 means left, 0 means center, and > 0 means right- Returns:
- Padded string
-
align
public static void align(PrintWriter output, String s, int width, int alignment)
Pads out a left-, right-, or center-aligned string using spaces up to the specified width.- Parameters:
output- Writer to output the centered string tos- String to padwidth- Minimum width of final stringalignment- How to align the string < 0 means left, 0 means center, and > 0 means right
-
align
public static void align(PrintWriter output, String s, int width, char paddingChar, int alignment)
Pads out a left-, right-, or center-aligned string using the specified character up to the specified width.- Parameters:
output- Writer to output the centered string tos- String to padwidth- Minimum width of final stringpaddingChar- Character to pad withalignment- How to align the string < 0 means left, 0 means center, and > 0 means right
-
multiply
public static String multiply(char c, int count)
Duplicates the given charactercounttimes. Ifcountis less than or equal to 0, the empty string is returned.- Parameters:
c- Character to duplicatecount- Number of times to duplicate- Returns:
- Duplicated string.
-
multiply
public static String multiply(String s, int count)
Duplicates the given stringcounttimes. Ifcountis less than or equal to 0, the empty string is returned.- Parameters:
s- String to duplicatecount- Number of times to duplicate- Returns:
- Duplicated string.
-
multiply
public static void multiply(PrintWriter output, char c, int count)
Duplicates the given charactercounttimes to the Writer. Ifcountis less than or equal to 0, this is a no-op.- Parameters:
output- Writer to receive duplicated resultsc- Character to duplicatecount- Number of times to duplicate
-
multiply
public static void multiply(PrintWriter output, String s, int count)
Duplicates the given stringcounttimes to the Writer. Ifcountis less than or equal to 0, this is a no-op.- Parameters:
output- Writer to receive duplicated resultss- String to duplicatecount- Number of times to duplicate
-
prependEachLine
public static String prependEachLine(String s, String prependWith)
Prepends a specific string to the front of each line of an input string. Lines are marked by a trailing'\n','\r', or'\f'character.- Parameters:
s- The input string.prependWith- The string to prepend to each line.- Returns:
- The modified string.
-
prependEachLine
public static void prependEachLine(PrintWriter output, String s, String prependWith)
Prepends a specific string to the front of each line of an input string. Lines are marked by a trailing'\n','\r', or'\f'character.- Parameters:
output- The writer to recieve the modified string.s- The input string.prependWith- The string to prepend to each line.
-
-