/** * Appends an object to the builder padding on the right to a fixed length. * The <code>String.valueOf</code> of the <code>int</code> value is used. * If the object is larger than the length, the right 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 appendFixedWidthPadRight(final int value, final int width, final char padChar) { return appendFixedWidthPadRight(String.valueOf(value), width, padChar); }
@Test public void testLang299() { final StrBuilder sb = new StrBuilder(1); sb.appendFixedWidthPadRight("foo", 1, '-'); assertEquals("f", sb.toString()); }
@Test public void testLang412Right() { final StrBuilder sb = new StrBuilder(); sb.appendFixedWidthPadRight(null, 10, '*'); assertEquals( "Failed to invoke appendFixedWidthPadRight correctly", "**********", sb.toString()); }
@Test public void testAppendFixedWidthPadRight_int() { final StrBuilder sb = new StrBuilder(); sb.appendFixedWidthPadRight(123, -1, '-'); assertEquals("", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight(123, 0, '-'); assertEquals("", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight(123, 1, '-'); assertEquals("1", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight(123, 2, '-'); assertEquals("12", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight(123, 3, '-'); assertEquals("123", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight(123, 4, '-'); assertEquals("123-", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight(123, 10, '-'); assertEquals(10, sb.length()); // 1234567890 assertEquals("123-------", sb.toString()); }
@Test public void testAppendFixedWidthPadRight() { final StrBuilder sb = new StrBuilder(); sb.appendFixedWidthPadRight("foo", -1, '-'); assertEquals("", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight("foo", 0, '-'); assertEquals("", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight("foo", 1, '-'); assertEquals("f", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight("foo", 2, '-'); assertEquals("fo", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight("foo", 3, '-'); assertEquals("foo", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight("foo", 4, '-'); assertEquals("foo-", sb.toString()); sb.clear(); sb.appendFixedWidthPadRight("foo", 10, '-'); assertEquals(10, sb.length()); // 1234567890 assertEquals("foo-------", sb.toString()); sb.clear(); sb.setNullText("null"); sb.appendFixedWidthPadRight(null, 5, '-'); assertEquals("null-", sb.toString()); }
/** * List available algorithms. This is displayed to the user when no valid * algorithm is given in the program parameterization. * * @return usage string listing available algorithms */ private static String getAlgorithmsListing() { StrBuilder strBuilder = new StrBuilder(); strBuilder .appendNewLine() .appendln("Select an algorithm to view usage: flink run examples/flink-gelly-examples_<version>.jar --algorithm <algorithm>") .appendNewLine() .appendln("Available algorithms:"); for (Driver algorithm : driverFactory) { strBuilder.append(" ") .appendFixedWidthPadRight(algorithm.getName(), 30, ' ') .append(algorithm.getShortDescription()).appendNewLine(); } return strBuilder.toString(); }
/** * Appends an object to the builder padding on the right to a fixed length. * The <code>String.valueOf</code> of the <code>int</code> value is used. * If the object is larger than the length, the right 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 appendFixedWidthPadRight(final int value, final int width, final char padChar) { return appendFixedWidthPadRight(String.valueOf(value), width, padChar); }
/** * Appends an object to the builder padding on the right to a fixed length. * The <code>String.valueOf</code> of the <code>int</code> value is used. * If the object is larger than the length, the right 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 appendFixedWidthPadRight(final int value, final int width, final char padChar) { return appendFixedWidthPadRight(String.valueOf(value), width, padChar); }
/** * Appends an object to the builder padding on the right to a fixed length. * The <code>String.valueOf</code> of the <code>int</code> value is used. * If the object is larger than the length, the right 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 appendFixedWidthPadRight(final int value, final int width, final char padChar) { return appendFixedWidthPadRight(String.valueOf(value), width, padChar); }
sb.appendFixedWidthPadLeft(statusInfo.getThreadId(), THREAD_ID.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getOperation(), OPERATION.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getTarget(), TARGET.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getFinished(), FINISHED.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getStackTrace() != null, ERROR.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getError() != null ? statusInfo.getError() ? "ERROR" : "SUCCESS" : "", RESULT.length(), ' '); sb.append(LINE_END); activeThreads += ta.peekLast().getActiveThreads(); sb.appendFixedWidthPadRight("Currently active client threads: " + activeThreads, HR.length - LINE_START.length() - LINE_END.length(), ' '); sb.append(LINE_END); pr.println(sb); sb.append(LINE_START); maxConcurrentThreads = max(maxConcurrentThreads, activeThreads); sb.appendFixedWidthPadRight("Maximum concurrent client threads: " + maxConcurrentThreads, HR.length - LINE_START.length() - LINE_END.length(), ' '); sb.append(LINE_END); sb.appendFixedWidthPadRight("Total threads finished: " + threadsFinished + "/" + totalThreadCount, HR.length - LINE_START.length() - LINE_END.length(), ' '); sb.append(LINE_END);
sb.appendFixedWidthPadLeft(statusInfo.getThreadId(), THREAD_ID.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getOperation(), OPERATION.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getTarget(), TARGET.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getFinished(), FINISHED.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getStackTrace() != null, ERROR.length(), ' '); sb.append(DELIMITER); sb.appendFixedWidthPadRight(statusInfo.getError() != null ? statusInfo.getError() ? "ERROR" : "SUCCESS" : "", RESULT.length(), ' '); sb.append(LINE_END); activeThreads += ta.peekLast().getActiveThreads(); sb.appendFixedWidthPadRight("Currently active client threads: " + activeThreads, HR.length - LINE_START.length() - LINE_END.length(), ' '); sb.append(LINE_END); pr.println(sb); sb.append(LINE_START); maxConcurrentThreads = max(maxConcurrentThreads, activeThreads); sb.appendFixedWidthPadRight("Maximum concurrent client threads: " + maxConcurrentThreads, HR.length - LINE_START.length() - LINE_END.length(), ' '); sb.append(LINE_END); sb.appendFixedWidthPadRight("Total threads finished: " + threadsFinished + "/" + totalThreadCount, HR.length - LINE_START.length() - LINE_END.length(), ' '); sb.append(LINE_END);
@Override default StrBuilder transform(String s) { IsTransformer.super.transform(s); StrBuilder ret = (this.getBuilderForAppend()==null)?new StrBuilder(this.getLength()):this.getBuilderForAppend(); String left = (s==null)?"":s; left = left.replace(' ', this.getInnerWsChar()); ret.appendFixedWidthPadRight(left, this.getLength(), this.getPaddingChar()); return ret; }