List of usage examples for com.google.common.base Strings padEnd
public static String padEnd(String string, int minLength, char padChar)
From source file:de.unioninvestment.eai.portal.portlet.crud.Settings.java
private void addSortedListOfConfigurationProperties(StringBuilder builder) { loadPropertiesAndDefaults();// w ww. j a va 2s . c om List<String> lines = new ArrayList<String>(props.size()); for (Entry<Object, Object> entry : props.entrySet()) { String key = entry.getKey().toString(); if (!key.contains("password")) { lines.add(Strings.padEnd(key + ":", 50, ' ') + entry.getValue()); } } sort(lines); for (String line : lines) { builder.append(line).append('\n'); } }
From source file:org.sosy_lab.cpachecker.util.resources.MemoryStatistics.java
/** * Print the gathered statistics./*w w w. ja v a2 s .co m*/ * This method may only be called when the thread running this instance * has finished! Check with {@link Thread#isAlive()} prior invocation! */ public void printStatistics(PrintStream out) { long heapPeak = 0; long nonHeapPeak = 0; for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { long peak = pool.getPeakUsage().getUsed(); if (pool.getType() == MemoryType.HEAP) { heapPeak += peak; } else { nonHeapPeak += peak; } } out.println("Used heap memory: " + formatMem(maxHeap) + " max; " + formatMem(sumHeap / count) + " avg; " + formatMem(heapPeak) + " peak"); out.println("Used non-heap memory: " + formatMem(maxNonHeap) + " max; " + formatMem(sumNonHeap / count) + " avg; " + formatMem(nonHeapPeak) + " peak"); for (int i = 0; i < pools.length; i++) { String name = Strings.padEnd("Used in " + pools[i].getName() + " pool:", 30, ' '); out.println(name + formatMem(maxHeapAllocatedPerPool[i]) + " max; " + formatMem(sumHeapAllocatedPerPool[i] / count) + " avg; " + formatMem(pools[i].getPeakUsage().getUsed()) + " peak"); } out.println("Allocated heap memory: " + formatMem(maxHeapAllocated) + " max; " + formatMem(sumHeapAllocated / count) + " avg"); out.println("Allocated non-heap memory: " + formatMem(maxNonHeapAllocated) + " max; " + formatMem(sumNonHeapAllocated / count) + " avg"); if (osMbean != null) { out.println("Total process virtual memory: " + formatMem(maxProcess) + " max; " + formatMem(sumProcess / count) + " avg"); } }
From source file:org.seedstack.seed.core.Seed.java
private String buildWelcomeMessage() { Ansi welcomeMessage = Ansi.ansi().reset().fgBrightGreen().a(WELCOME_MESSAGE).reset(); if (seedVersion != null) { welcomeMessage.a("\n").a("Core v").a(Strings.padEnd(seedVersion, 16, ' ')); }//from w ww . j a v a 2 s. co m if (businessVersion != null) { welcomeMessage.a(seedVersion != null ? "" : "\n").a("Business v").a(businessVersion); } welcomeMessage.a("\n"); return welcomeMessage.reset().toString(); }
From source file:org.eclipse.xtext.formatting2.debug.TextRegionAccessToString.java
protected String toString(IEObjectRegion region) { EObject obj = region.getSemanticElement(); StringBuilder builder = new StringBuilder(Strings.padEnd(toClassWithName(obj), textWidth, ' ') + " "); EObject element = region.getGrammarElement(); if (element instanceof AbstractElement) builder.append(grammarToString.apply((AbstractElement) element)); else if (element instanceof AbstractRule) builder.append(((AbstractRule) element).getName()); else/* w w w . j a va 2 s . co m*/ builder.append(": ERROR: No grammar element."); List<String> segments = Lists.newArrayList(); EObject current = obj; while (current.eContainer() != null) { EObject container = current.eContainer(); EStructuralFeature containingFeature = current.eContainingFeature(); StringBuilder segment = new StringBuilder(); segment.append(toClassWithName(container)); segment.append("/"); segment.append(containingFeature.getName()); if (containingFeature.isMany()) { int index = ((List<?>) container.eGet(containingFeature)).indexOf(current); segment.append("[" + index + "]"); } current = container; segments.add(segment.toString()); } if (!segments.isEmpty()) { builder.append(" path:"); builder.append(Joiner.on("=").join(segments)); } return builder.toString(); }
From source file:org.dice.solrenhancements.morelikethis.DiceMoreLikeThisHandler.java
private void addInterestingTerms(SolrQueryResponse rsp, MoreLikeThisParams.TermStyle termStyle, MLTResult mltResult) {/*from ww w . j a v a 2 s . c om*/ List<MLTTerm> mltTerms = mltResult.mltTerms; Collections.sort(mltTerms, MLTTerm.FLD_BOOST_X_SCORE_ORDER); if (termStyle == MoreLikeThisParams.TermStyle.DETAILS) { List<InterestingTerm> interesting = extractInterestingTerms(mltResult.rawMLTQuery); int longest = 0; for (InterestingTerm t : interesting) { longest = Math.max(t.term.toString().length(), longest); } NamedList<Float> it = new NamedList<Float>(); for (InterestingTerm t : interesting) { it.add(Strings.padEnd(t.term.toString(), longest, ' '), t.boost); } rsp.add("interestingTerms", it); } else { List<String> it = new ArrayList<String>(mltTerms.size()); for (MLTTerm mltTerm : mltTerms) { it.add(mltTerm.getWord()); } rsp.add("interestingTerms", it); } }
From source file:com.facebook.buck.android.resources.ResourcesXml.java
private static void dumpAttribute(PrintStream out, StringPool strings, Optional<RefMap> refMap, ByteBuffer buf, int indent, Map<String, String> nsMap) { int nsId = buf.getInt(0); String namespace = nsId == -1 ? "" : strings.getString(nsId); String shortNs = nsMap.get(namespace); int nameIndex = buf.getInt(4); String name = strings.getString(nameIndex); int resValue = refMap.map(ref -> ref.getRef(nameIndex)).orElse(-1); int rawValueIndex = buf.getInt(8); String rawValue = rawValueIndex < 0 ? null : strings.getOutputNormalizedString(rawValueIndex); int attrType = buf.get(15); int data = buf.getInt(16); String dumpValue = getValueForDump(strings, rawValue, attrType, data); out.format("%sA: %s%s%s=%s%s\n", Strings.padEnd("", indent * 2, ' '), shortNs == null ? "" : shortNs + ":", name, resValue == -1 ? "" : String.format("(0x%08x)", resValue), dumpValue, rawValue == null ? "" : String.format(" (Raw: \"%s\")", rawValue)); }
From source file:com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Data.Component.TypeInstanceTableDatamodel.java
@Override public FormattedCharacterBuffer getLineFormatted(int rowIndex, int columnIndex, int lineIndex) { Color backgroundColor = getBackgroundColor(rowIndex, columnIndex); switch (columnIndex) { case ADDRESS_INDEX: TypeInstance type = typesToDisplay.get(rowIndex); String addressString = ""; if (lineIndex == 0) { addressString = TypeInstanceAddressTableCellRenderer.getStringToDisplay(false, type.getAddress()); }/* ww w. j ava2 s . c o m*/ return stringToFormattedCharacterBuffer(addressString, rowIndex, columnIndex); case NAME_INDEX: String typeName = ""; if (lineIndex == 0) { typeName = typesToDisplay.get(rowIndex).getName(); } return new FormattedCharacterBuffer(Strings.padEnd(typeName, columns[columnIndex].getWidth(), ' '), STANDARD_FONT, columns[columnIndex].getDefaultFontColor(), backgroundColor); case TYPE_INDEX: FormattedCharacterBuffer typeDeclaration = typeDeclarations.get(rowIndex); if (typeDeclaration.getNumberOfLines() > lineIndex) { return typeDeclarations.get(rowIndex).getLine(lineIndex).setBackgroundColor(backgroundColor); } return stringToFormattedCharacterBuffer("", rowIndex, columnIndex); case XREFS_INDEX: TypeInstanceReference reference = getTypeInstanceReference(rowIndex, lineIndex); String xrefString = ""; if (reference != null) { xrefString = TypeInstanceCrossReferenceRenderer.renderText(reference); } return stringToFormattedCharacterBuffer(xrefString, rowIndex, columnIndex); case COMMENTS_INDEX: FormattedCharacterBuffer comment = generateFormattedComment( typeContainer.getComments(typesToDisplay.get(rowIndex))); if (lineIndex < comment.getNumberOfLines()) { // Now only return the line that was requested. TODO(thomasdullien): This is pretty // wasteful, clean it up eventually. return comment.getLine(lineIndex).setBackgroundColor(backgroundColor); } // Return empty buffers for empty lines. return stringToFormattedCharacterBuffer("", rowIndex, columnIndex); default: Logger.warning("Invalid column index, investigate."); break; } return null; }
From source file:ninja.RouterImpl.java
private void logRoutes() { // determine the width of the columns int maxMethodLen = 0; int maxPathLen = 0; int maxControllerLen = 0; for (Route route : getRoutes()) { maxMethodLen = Math.max(maxMethodLen, route.getHttpMethod().length()); maxPathLen = Math.max(maxPathLen, route.getUri().length()); if (route.getControllerClass() != null) { int controllerLen = route.getControllerClass().getName().length() + route.getControllerMethod().getName().length(); maxControllerLen = Math.max(maxControllerLen, controllerLen); }/*from w w w .ja va 2s . co m*/ } // log the routing table int borderLen = 10 + maxMethodLen + maxPathLen + maxControllerLen; String border = Strings.padEnd("", borderLen, '-'); logger.info(border); logger.info("Registered routes"); logger.info(border); for (Route route : getRoutes()) { if (route.getControllerClass() != null) { logger.info("{} {} => {}.{}()", Strings.padEnd(route.getHttpMethod(), maxMethodLen, ' '), Strings.padEnd(route.getUri(), maxPathLen, ' '), route.getControllerClass().getName(), route.getControllerMethod().getName()); } else { logger.info("{} {}", route.getHttpMethod(), route.getUri()); } } }
From source file:io.prestosql.orc.AbstractTestOrcReader.java
private String toCharValue(Object value) { return Strings.padEnd(value.toString(), CHAR_LENGTH, ' '); }
From source file:google.registry.tools.server.ListObjectsAction.java
/** * Returns for the given column widths map a row formatting function that converts a row map (of * column keys to cell values) into a single string with each column right-padded to that width. * * <p>The resulting strings separate padded fields with two spaces and each end in a newline. *//*from ww w . j av a 2s. c o m*/ private static Function<Map<String, String>, String> makeRowFormatter(final Map<String, Integer> columnWidths) { return new Function<Map<String, String>, String>() { @Override public String apply(Map<String, String> rowByColumns) { List<String> paddedFields = new ArrayList<>(); for (Map.Entry<String, String> cell : rowByColumns.entrySet()) { paddedFields.add(Strings.padEnd(cell.getValue(), columnWidths.get(cell.getKey()), ' ')); } return Joiner.on(" ").join(paddedFields); } }; }