/** * Appends an object to the builder padding on the left to a fixed width. * The <code>String.valueOf</code> of the <code>int</code> value is used. * If the formatted value is larger than the length, the left hand side is lost. * * @param value the value to append * @param width the fixed field width, zero or negative has no effect * @param padChar the pad character to use * @return this, to enable chaining */ public StrBuilder appendFixedWidthPadLeft(final int value, final int width, final char padChar) { return appendFixedWidthPadLeft(String.valueOf(value), width, padChar); }
@Test public void testLang412Left() { final StrBuilder sb = new StrBuilder(); sb.appendFixedWidthPadLeft(null, 10, '*'); assertEquals( "Failed to invoke appendFixedWidthPadLeft correctly", "**********", sb.toString()); }
@Test public void testAppendFixedWidthPadLeft_int() { final StrBuilder sb = new StrBuilder(); sb.appendFixedWidthPadLeft(123, -1, '-'); assertEquals("", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft(123, 0, '-'); assertEquals("", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft(123, 1, '-'); assertEquals("3", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft(123, 2, '-'); assertEquals("23", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft(123, 3, '-'); assertEquals("123", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft(123, 4, '-'); assertEquals("-123", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft(123, 10, '-'); assertEquals(10, sb.length()); // 1234567890 assertEquals("-------123", sb.toString()); }
@Test public void testAppendFixedWidthPadLeft() { final StrBuilder sb = new StrBuilder(); sb.appendFixedWidthPadLeft("foo", -1, '-'); assertEquals("", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft("foo", 0, '-'); assertEquals("", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft("foo", 1, '-'); assertEquals("o", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft("foo", 2, '-'); assertEquals("oo", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft("foo", 3, '-'); assertEquals("foo", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft("foo", 4, '-'); assertEquals("-foo", sb.toString()); sb.clear(); sb.appendFixedWidthPadLeft("foo", 10, '-'); assertEquals(10, sb.length()); // 1234567890 assertEquals("-------foo", sb.toString()); sb.clear(); sb.setNullText("null"); sb.appendFixedWidthPadLeft(null, 5, '-'); assertEquals("-null", sb.toString()); }
/** * Appends an object to the builder padding on the left to a fixed width. * The <code>String.valueOf</code> of the <code>int</code> value is used. * If the formatted value is larger than the length, the left hand side is lost. * * @param value the value to append * @param width the fixed field width, zero or negative has no effect * @param padChar the pad character to use * @return this, to enable chaining */ public StrBuilder appendFixedWidthPadLeft(final int value, final int width, final char padChar) { return appendFixedWidthPadLeft(String.valueOf(value), width, padChar); }
/** * Appends an object to the builder padding on the left to a fixed width. * The <code>String.valueOf</code> of the <code>int</code> value is used. * If the formatted value is larger than the length, the left hand side is lost. * * @param value the value to append * @param width the fixed field width, zero or negative has no effect * @param padChar the pad character to use * @return this, to enable chaining */ public StrBuilder appendFixedWidthPadLeft(final int value, final int width, final char padChar) { return appendFixedWidthPadLeft(String.valueOf(value), width, padChar); }
/** * Appends an object to the builder padding on the left to a fixed width. * The <code>String.valueOf</code> of the <code>int</code> value is used. * If the formatted value is larger than the length, the left hand side is lost. * * @param value the value to append * @param width the fixed field width, zero or negative has no effect * @param padChar the pad character to use * @return this, to enable chaining */ public StrBuilder appendFixedWidthPadLeft(final int value, final int width, final char padChar) { return appendFixedWidthPadLeft(String.valueOf(value), width, padChar); }
@Override default StrBuilder transform(String s) { IsTransformer.super.transform(s); StrBuilder ret = (this.getBuilderForAppend()==null)?new StrBuilder(this.getLength()):this.getBuilderForAppend(); String right = (s==null)?"":s; right = right.replace(' ', this.getInnerWsChar()); ret.appendFixedWidthPadLeft(right, this.getLength(), this.getPaddingChar()); return ret; }
sb.appendFixedWidthPadLeft(statusInfo.getDaemonId(), DAEMON_ID.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadLeft(statusInfo.getProcessId(), PROCESS_ID.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadLeft(statusInfo.getThreadId(), THREAD_ID.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getOperation(), OPERATION.length(), ' ');
sb.appendFixedWidthPadLeft(statusInfo.getDaemonId(), DAEMON_ID.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadLeft(statusInfo.getProcessId(), PROCESS_ID.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadLeft(statusInfo.getThreadId(), THREAD_ID.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getOperation(), OPERATION.length(), ' ');