List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:com.bacoder.parser.core.DumpVisitor.java
@Override public void visitAfter(Node node) { level--;/*from www .j a va 2 s.co m*/ String s = String.format("%s</%s>\n", Strings.repeat(indent, level), node.getClass().getSimpleName()); try { outputStream.write(s.getBytes()); } catch (IOException e) { throw new RuntimeException("Unable to write \"" + s + "\"", e); } }
From source file:net.kaczmarzyk.kata.RomanSymbol.java
public RomanSymbol repeatUntilGreaterOrEqualTo(int val) { int numTimes = val / value; return new RomanSymbol(numTimes * value, Strings.repeat(symbol, numTimes)); }
From source file:com.technophobia.substeps.runner.ExecutionLogger.java
private String format(final IExecutionNode node) { // TODO - no way of knowing of this is an impl or not..? return Strings.repeat(this.indentString, node.getDepth()) + node.getDescription() + " from " + node.getFilename();//from w ww .ja v a 2 s . co m }
From source file:com.facebook.buck.util.Paths.java
/** * @param from must always refer to a directory (it should either be the empty string or end with * a slash).//w w w .j a va2s .co m * @param to may refer to either a file or a directory */ public static String computeRelativePath(String from, String to) { Preconditions.checkNotNull(from); Preconditions.checkArgument(from.isEmpty() || from.endsWith("/"), "Directory path must either be the empty string or end with a slash"); Preconditions.checkNotNull(to); if (from.isEmpty()) { return to; } // Both from and to have the same string prefix through this character index. int samePrefixIndex = 0; while (true) { int slashIndex = from.indexOf('/', samePrefixIndex); if (slashIndex < 0) { break; } int indexIncludingSlash = slashIndex + 1; if (indexIncludingSlash > to.length()) { break; } String fromPathElement = from.substring(samePrefixIndex, indexIncludingSlash); String toPathElement = to.substring(samePrefixIndex, indexIncludingSlash); if (fromPathElement.equals(toPathElement)) { samePrefixIndex = indexIncludingSlash; } else { break; } } int directoryDepth = 0; for (int charIndex = samePrefixIndex + 1; charIndex < from.length(); charIndex++) { if (from.charAt(charIndex) == '/') { directoryDepth++; } } return Strings.repeat("../", directoryDepth) + to.substring(samePrefixIndex); }
From source file:org.opendaylight.yangtools.yang.data.api.schema.stream.LoggingNormalizedNodeStreamWriter.java
public LoggingNormalizedNodeStreamWriter(final int indentSize) { this.indentStr = Strings.repeat(" ", indentSize); indent.push(""); }
From source file:com.twitter.graphjet.bipartite.segment.HigherBitsEdgeTypeMask.java
@Override public int restore(int node) { String bitMaskString = Strings.repeat("0", BITS_IN_BYTE) + Strings.repeat("1", ALLOWED_NODE_BITS); int bitMask = Integer.parseInt(bitMaskString, 2); return node & bitMask; }
From source file:parquet.tools.read.SimpleRecord.java
public void prettyPrint(PrintWriter out, int depth) { for (NameValue value : values) { out.print(Strings.repeat(".", depth)); out.print(value.getName());//from w ww.java2s. c om Object val = value.getValue(); if (val == null) { out.print(" = "); out.print("<null>"); } else if (byte[].class == val.getClass()) { out.print(" = "); out.print(Arrays.toString((byte[]) val)); } else if (short[].class == val.getClass()) { out.print(" = "); out.print(Arrays.toString((short[]) val)); } else if (int[].class == val.getClass()) { out.print(" = "); out.print(Arrays.toString((int[]) val)); } else if (long[].class == val.getClass()) { out.print(" = "); out.print(Arrays.toString((long[]) val)); } else if (float[].class == val.getClass()) { out.print(" = "); out.print(Arrays.toString((float[]) val)); } else if (double[].class == val.getClass()) { out.print(" = "); out.print(Arrays.toString((double[]) val)); } else if (boolean[].class == val.getClass()) { out.print(" = "); out.print(Arrays.toString((boolean[]) val)); } else if (val.getClass().isArray()) { out.print(" = "); out.print(Arrays.deepToString((Object[]) val)); } else if (SimpleRecord.class.isAssignableFrom(val.getClass())) { out.println(":"); ((SimpleRecord) val).prettyPrint(out, depth + 1); continue; } else { out.print(" = "); out.print(String.valueOf(val)); } out.println(); } }
From source file:org.modica.parser.PrintingSFIntroducerHandler.java
public PrintingSFIntroducerHandler(PrintStream out, int indentSize) { this.out = out; this.indentSize = indentSize; this.indentShift = Strings.repeat(" ", indentSize); }
From source file:mimeparser.MimeMessageParser.java
/*** * Print the structure of the Mime object. * @param p Mime object//from www . ja v a 2s . c o m * @throws Exception */ public static String printStructure(Part p) throws Exception { final StringBuilder result = new StringBuilder(); result.append("-----------Mime Message-----------\n"); walkMimeStructure(p, 0, new WalkMimeCallback() { @Override public void walkMimeCallback(Part p, int level) throws Exception { String s = "> " + Strings.repeat("| ", level) + new ContentType(p.getContentType()).getBaseType(); String[] contentDispositionArr = p.getHeader("Content-Disposition"); if (contentDispositionArr != null) { s += "; " + new ContentDisposition(contentDispositionArr[0]).getDisposition(); } result.append(s); result.append("\n"); } }); result.append("----------------------------------"); return result.toString(); }
From source file:org.gradle.api.internal.tasks.testing.logging.ShortExceptionFormatter.java
private void printException(TestDescriptor descriptor, Throwable exception, boolean cause, int indentLevel, StringBuilder builder) {/*from www .j av a 2 s . com*/ String indent = Strings.repeat(INDENT, indentLevel); builder.append(indent); if (cause) { builder.append("Caused by: "); } String className = exception instanceof PlaceholderException ? ((PlaceholderException) exception).getExceptionClassName() : exception.getClass().getName(); builder.append(className); StackTraceFilter filter = new StackTraceFilter( new ClassMethodNameStackTraceSpec(descriptor.getClassName(), null)); List<StackTraceElement> stackTrace = filter.filter(exception); if (stackTrace.size() > 0) { StackTraceElement element = stackTrace.get(0); builder.append(" at "); builder.append(element.getFileName()); builder.append(':'); builder.append(element.getLineNumber()); } builder.append('\n'); if (testLogging.getShowCauses() && exception.getCause() != null) { printException(descriptor, exception.getCause(), true, indentLevel + 1, builder); } }