Code with Misuse: |
class Hex {
/**
* Pads <code>txt</code> with <code>padChar</code> characters so
* that its length becomes <code>width</code>. If the length
* of <code>txt</code> is already greater or equal to <code>width</code>,
* the result is just a copy of <code>txt</code>.
*
* @param txt the string to pad.
* @param width the length of the result (unless the length of
* <code>txt</code> was already greater or equal to <code>width</code>.
* @param padChar the padding character.
* @param left a boolean indicating whether to pad to the left
* (<code>true</code>) or to the right (<code>false</code>).
*
* @return the padded text.
*/
private static String pad(String txt, int width, char padChar, boolean left) {
String result = new String(txt);
String padString = Character.toString(padChar);
for (int i = txt.length(); i < width; i++) {
if (left) {
result = padString + result;
} else {
result = result + padString;
}
}
return result;
}
}
|