List of usage examples for org.apache.commons.lang3.text StrBuilder appendFixedWidthPadLeft
public StrBuilder appendFixedWidthPadLeft(final int value, final int width, final char padChar)
From source file:com.mgmtp.perfload.core.console.status.FileStatusTransformer.java
private void processStatusInfo(final Map<StatusInfoKey, StatusInfo> statusInfoMap, final Map<StatusInfoKey, Deque<ThreadActivity>> threadActivitiesMap) { PrintWriter pr = null;// ww w . jav a 2 s . c om try { pr = new PrintWriter(statusFile, encoding); pr.println(HR); pr.println(HEADER); pr.println(HR); Set<StatusInfoKey> sortedKeys = newTreeSet(statusInfoMap.keySet()); int threadsFinished = 0; for (StatusInfoKey key : sortedKeys) { StatusInfo statusInfo = statusInfoMap.get(key); if (statusInfo.getFinished() != null && statusInfo.getFinished()) { threadsFinished++; } StrBuilder sb = new StrBuilder(200); sb.append(LINE_START); 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.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); pr.println(sb); } pr.println(HR); StrBuilder sb = new StrBuilder(HR.length); sb.append(LINE_START); int activeThreads = 0; for (Deque<ThreadActivity> ta : threadActivitiesMap.values()) { 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 = new StrBuilder(HR.length); 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); pr.println(sb); sb = new StrBuilder(HR.length); sb.append(LINE_START); sb.appendFixedWidthPadRight("Total threads finished: " + threadsFinished + "/" + totalThreadCount, HR.length - LINE_START.length() - LINE_END.length(), ' '); sb.append(LINE_END); pr.println(sb); pr.println(HR); } catch (IOException ex) { log.error("Error writing load test status to file: {}", statusFile, ex); } finally { IOUtils.closeQuietly(pr); } }
From source file:de.vandermeer.skb.interfaces.transformers.textformat.String_To_RightPadded.java
@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;/* w w w . j ava 2 s .c o m*/ }
From source file:de.vandermeer.asciitable.v2.render.V2_AsciiTableRenderer.java
private void appendWithAlignment(char alignment, StrBuilder sb, String str, int width, char paddingChar, int padding, boolean isLastLine) { if (padding > 0) { width = width - padding * 2;/*from w w w . j ava2s . c o m*/ } for (int i = 0; i < padding; i++) { sb.append(paddingChar); } if ('l' == alignment) { sb.appendFixedWidthPadRight(str, width, paddingChar); } else if ('r' == alignment) { sb.appendFixedWidthPadLeft(str, width, paddingChar); } else if ('c' == alignment) { sb.append(StringUtils.center(str, width, paddingChar)); } else if ('j' == alignment || 't' == alignment) { if (isLastLine) { //nothing needed if this is the last line of a wrapped text if ('j' == alignment) { sb.appendFixedWidthPadRight(str, width, paddingChar); } else { //mist be 't' now sb.appendFixedWidthPadLeft(str, width, paddingChar); } } else { String[] ar = StringUtils.split(str); int length = 0; for (String s : ar) { length += s.length(); } //first spaces to distributed (even) int first = ((width - length) / (ar.length - 1)) * (ar.length - 1); for (int i = 0; i < ar.length - 1; i++) { if (first != 0) { ar[i] += " "; first--; } } //second space to distributed (leftovers, as many as there are) int second = (width - length) % (ar.length - 1); for (int i = 0; i < ar.length - 1; i++) { if (second != 0) { ar[i] += " "; second--; } } sb.append(StringUtils.join(ar)); } } else { System.err.println("ERROR RENDER ALIGNMENT");//TODO } for (int i = 0; i < padding; i++) { sb.append(paddingChar); } }