List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:org.eclipse.elk.layered.JsonDebugUtil.java
/** * Writes a debug graph for the given linear segments and their dependencies. * /*from ww w.jav a 2s .c o m*/ * @param layeredGraph * the layered graph. * @param segmentList * the list of linear segments. * @param outgoingList * the list of successors for each linear segment. */ public static void writeDebugGraph(final LGraph layeredGraph, final List<LinearSegment> segmentList, final List<List<LinearSegment>> outgoingList) { try { Writer writer = createWriter(layeredGraph); beginGraph(writer, layeredGraph); beginChildNodeList(writer, 1); String indent1 = Strings.repeat(INDENT, 2); String indent2 = Strings.repeat(INDENT, 3); // SUPPRESS CHECKSTYLE MagicNumber int edgeId = 0; Iterator<LinearSegment> segmentIterator = segmentList.iterator(); Iterator<List<LinearSegment>> successorsIterator = outgoingList.iterator(); StringBuffer edges = new StringBuffer(); while (segmentIterator.hasNext()) { LinearSegment segment = segmentIterator.next(); writer.write("\n" + indent1 + "{\n" + indent2 + "\"id\": \"n" + segment.hashCode() + "\",\n" + indent2 + "\"labels\": [ { \"text\": \"" + segment + "\" } ],\n" + indent2 + "\"width\": 50,\n" + indent2 + "\"height\": 25\n" + indent1 + "}"); if (segmentIterator.hasNext()) { writer.write(","); } Iterator<LinearSegment> succIterator = successorsIterator.next().iterator(); while (succIterator.hasNext()) { LinearSegment successor = succIterator.next(); edges.append("\n" + indent1 + "{\n" + indent2 + "\"id\": \"e" + edgeId++ + "\",\n" + indent2 + "\"source\": \"n" + segment.hashCode() + "\",\n" + indent2 + "\"target\": \"n" + successor.hashCode() + "\",\n" + indent1 + "},"); } } endChildNodeList(writer, 1); if (edges.length() > 0) { edges.deleteCharAt(edges.length() - 1); } writer.write(INDENT + "\"edges\": [" + edges + "\n" + indent1 + "]"); endGraph(writer); writer.close(); } catch (Exception exception) { exception.printStackTrace(); } }
From source file:org.spongepowered.asm.util.PrettyPrinter.java
private void printHr(PrintStream stream) { stream.printf("/*%s*/\n", Strings.repeat("*", this.width + 2)); }
From source file:parquet.tools.util.MetadataUtils.java
private static void showColumnChunkDetails(PrettyPrintWriter out, Map<String, Object> current, int depth) { for (Map.Entry<String, Object> entry : current.entrySet()) { String name = Strings.repeat(".", depth) + entry.getKey(); Object value = entry.getValue(); if (value instanceof Map) { out.println(name + ": "); showColumnChunkDetails(out, (Map<String, Object>) value, depth + 1); } else {/*from w ww .java 2 s . c o m*/ out.print(name + ": "); showDetails(out, (ColumnChunkMetaData) value, false); } } }
From source file:com.rhythm.louie.services.status.StatusDAO.java
@Override public List<ErrorPB> streamTest(final Integer numResults, final Integer resultSize, final Integer sleep) throws Exception { List<String> values = new ArrayList<>(numResults); for (int i = 0; i < numResults; i++) { values.add(""); }//from w w w. ja v a 2 s .c o m CalcList<String, ErrorPB> list = new CalcList<>(new Function<String, ErrorPB>() { @Override public ErrorPB apply(String input) { if (sleep > 0) { try { Thread.sleep(sleep); } catch (Exception e) { LoggerFactory.getLogger(StatusDAO.class).error("Error sleeping in streamTest", e); } } return ErrorPB.newBuilder().setDescription(Strings.repeat("a", resultSize)).build(); } }, values); return list; }
From source file:com.google.template.soy.error.ErrorPrettyPrinter.java
/** * Displays {@code e} on the given {@link java.io.PrintStream} in a useful way, with a snippet * of Soy source code containing the error and a caret pointing at the exact place where the error * was found./*from ww w.j ava2 s . c o m*/ */ public void print(SoySyntaxException e, PrintStream err) { // Start by printing the actual text of the exception. err.println(e.getMessage()); // Try to find a snippet of source code associated with the exception and print it. SourceLocation sourceLocation = e.getSourceLocation(); SoyFileSupplier supplier = filePathsToSuppliers.get(sourceLocation.getFilePath()); if (supplier == null) { // TODO(user): this is a result of calling SoySyntaxException#createWithoutMetaInfo, // which occurs almost 100 times. Clean them up. return; } String snippet; try { snippet = getSnippet(supplier, sourceLocation); } catch (IOException ioe) { return; } err.println(snippet); // Print a caret below the error. // TODO(brndn): SourceLocation.beginColumn is occasionally -1. Review all SoySyntaxException // instantiations and ensure the SourceLocation is well-formed. int beginColumn = Math.max(e.getSourceLocation().getBeginColumn(), 1); String caretLine = Strings.repeat(" ", beginColumn - 1) + "^"; err.println(caretLine); }
From source file:com.chiorichan.util.ObjectUtil.java
public static String hexDump(ByteBuf buf, int highlightIndex) { if (buf == null) return "Buffer: null!"; if (buf.capacity() < 1) { return "Buffer: 0B!"; }/*www .j a va 2 s . c om*/ StringBuilder dump = new StringBuilder(); final int startIndex = 0; final int endIndex = buf.capacity(); final int length = endIndex - startIndex; final int fullRows = length >>> 4; final int remainder = length & 0xF; int highlightRow = -1; dump.append(NEWLINE + " +-------------------------------------------------+" + NEWLINE + " | 0 1 2 3 4 5 6 7 8 9 a b c d e f |" + NEWLINE + "+--------+-------------------------------------------------+----------------+"); if (highlightIndex > 0) { highlightRow = highlightIndex >>> 4; highlightIndex = highlightIndex - (16 * highlightRow) - 1; dump.append(NEWLINE + "| |" + Strings.repeat(" ", highlightIndex) + " $$" + Strings.repeat(" ", 15 - highlightIndex)); dump.append(" |" + Strings.repeat(" ", highlightIndex) + "$" + Strings.repeat(" ", 15 - highlightIndex) + "|"); } // Dump the rows which have 16 bytes. for (int row = 0; row < fullRows; row++) { int rowStartIndex = row << 4; // Per-row prefix. appendHexDumpRowPrefix(dump, row, rowStartIndex); // Hex dump int rowEndIndex = rowStartIndex + 16; for (int j = rowStartIndex; j < rowEndIndex; j++) { dump.append(BYTE2HEX[buf.getUnsignedByte(j)]); } dump.append(" |"); // ASCII dump for (int j = rowStartIndex; j < rowEndIndex; j++) { dump.append(BYTE2CHAR[buf.getUnsignedByte(j)]); } dump.append('|'); if (highlightIndex > 0 && highlightRow == row + 1) dump.append(" <--"); } // Dump the last row which has less than 16 bytes. if (remainder != 0) { int rowStartIndex = fullRows << 4; appendHexDumpRowPrefix(dump, fullRows, rowStartIndex); // Hex dump int rowEndIndex = rowStartIndex + remainder; for (int j = rowStartIndex; j < rowEndIndex; j++) { dump.append(BYTE2HEX[buf.getUnsignedByte(j)]); } dump.append(HEXPADDING[remainder]); dump.append(" |"); // Ascii dump for (int j = rowStartIndex; j < rowEndIndex; j++) { dump.append(BYTE2CHAR[buf.getUnsignedByte(j)]); } dump.append(BYTEPADDING[remainder]); dump.append('|'); if (highlightIndex > 0 && highlightRow > fullRows + 1) dump.append(" <--"); } dump.append(NEWLINE + "+--------+-------------------------------------------------+----------------+"); return dump.toString(); }
From source file:org.bonitasoft.web.designer.SpringWebApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { for (String line : BANNER) { logger.info(line);// ww w . j ava 2 s.com } logger.info(Strings.repeat("=", 100)); logger.info(String.format("UI-DESIGNER : %s edition v.%s", prop.getProperty("designer.edition"), prop.getProperty("designer.version"))); logger.info(Strings.repeat("=", 100)); // Create the root context Spring AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(new Class<?>[] { ApplicationConfig.class }); // Manage the lifecycle of the root application context servletContext.addListener(new ContextLoaderListener(rootContext)); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.setMultipartConfig(new MultipartConfigElement(System.getProperty("java.io.tmpdir"))); dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); }
From source file:com.google.googlejavaformat.java.JavaCommentsHelper.java
private String preserveIndentation(List<String> lines, int column0) { StringBuilder builder = new StringBuilder(); // find the leftmost non-whitespace character in all trailing lines int startCol = -1; for (int i = 1; i < lines.size(); i++) { int lineIdx = CharMatcher.whitespace().negate().indexIn(lines.get(i)); if (lineIdx >= 0 && (startCol == -1 || lineIdx < startCol)) { startCol = lineIdx;// ww w . j ava2 s . co m } } // output the first line at the current column builder.append(lines.get(0)); // output all trailing lines with plausible indentation for (int i = 1; i < lines.size(); ++i) { builder.append(lineSeparator).append(Strings.repeat(" ", column0)); // check that startCol is valid index, e.g. for blank lines if (lines.get(i).length() >= startCol) { builder.append(lines.get(i).substring(startCol)); } else { builder.append(lines.get(i)); } } return builder.toString(); }
From source file:com.google.android.marvin.utils.TraceAspect.java
private void log(ProceedingJoinPoint joinPoint, long elapsedMillis) { if (elapsedMillis >= LATENCY_THRESHOLD_MS) { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); String className = methodSignature.getMethod().getDeclaringClass().getCanonicalName(); String methodName = methodSignature.getName(); LogUtils.log(className, Log.DEBUG, "%s %s.%s -->%dms", Strings.repeat(" ", callLevel > 0 ? callLevel : 0), className, methodName, elapsedMillis); }//from w ww .j a v a2s. c o m }
From source file:jetbrains.jetpad.cell.toDom.IndentRootCellMapper.java
IndentRootCellMapper(IndentCell source, CellToDomContext ctx) { super(source, ctx, DOM.createDiv()); myCellMappers = createChildSet();/*from w w w . j a va 2 s. com*/ myIndentUpdater = new IndentUpdater<Node>(getSource(), getTarget(), new IndentUpdaterTarget<Node>() { @Override public Element newLine() { Element result = DOM.createDiv(); result.addClassName(CellContainerToDomMapper.CSS.horizontal()); return result; } @Override public Element newIndent(int size) { Element result = DOM.createDiv(); DomTextEditor editor = new DomTextEditor(result); editor.setText(Strings.repeat(" ", size)); return result; } @Override public CellWrapper<Node> wrap(final Cell cell) { final BaseCellMapper<?> mapper = createMapper(cell); CounterUtil.updateOnAdd(getSource(), cell, mapper); mapper.setAncestorBackground(AncestorUtil.getAncestorBackground(getSource(), cell)); myCellMappers.add(mapper); final Registration visibilityReg = cell.visible() .addHandler(new EventHandler<PropertyChangeEvent<Boolean>>() { @Override public void onEvent(PropertyChangeEvent<Boolean> event) { myIndentUpdater.visibilityChanged(cell, event); } }); return new CellWrapper<Node>() { @Override public Node item() { return mapper.getTarget(); } @Override public void remove() { CounterUtil.updateOnRemove(getSource(), cell, mapper); myCellMappers.remove(mapper); visibilityReg.remove(); } }; } @Override public List<Node> children(Node item) { if (item instanceof Element) { return divWrappedElementChildren((Element) item); } else { throw new IllegalStateException(); } } @Override public Element parent(Node item) { if (item instanceof Element) { return item.getParentElement().getParentElement(); } else { throw new IllegalStateException(); } } }) { @Override protected void onVisibilityChanged(Cell cell, PropertyChangeEvent<Boolean> event) { myIndentUpdater.visibilityChanged(cell, event); } }; }