List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:com.ngdata.hbaseindexer.cli.ListIndexersCli.java
/** * Prints out a conf stored in a byte[], under the assumption that it is UTF-8 text. *///from w ww.j a v a 2s . c om private void printConf(byte[] conf, int indent, PrintStream ps, boolean dump) throws Exception { String prefix = Strings.repeat(" ", indent); if (conf == null) { ps.println(prefix + "(none)"); } else { if (dump) { String data = new String(conf, "UTF-8"); for (String line : data.split("\n")) { ps.println(prefix + line); } } else { ps.println(prefix + conf.length + " bytes, use -dump to see content"); } } }
From source file:de.iteratec.iteraplan.presentation.problemreports.RequestProblemReportPart.java
private static String mask(String s) { if (s == null) { return "null"; } else {//ww w .ja v a2 s . c o m return Strings.repeat(MASK_CHAR.toString(), s.length()); } }
From source file:com.enonic.cms.framework.util.JDOMUtil.java
private static String serialize(Document doc, int indent, boolean omitDecl, boolean includeSelf) { final Format format = Format.getPrettyFormat().setIndent(Strings.repeat(" ", indent)) .setOmitDeclaration(omitDecl); return doSerialize(doc, format, includeSelf); }
From source file:org.shaf.server.log.XesWriter.java
/** * Writes the start of the XES element./*from w w w. j a v a 2 s. c om*/ * * @param tag * the element tag name. * @param attributes * the element attributes. * @throws IOException * if an I/O error occurs during writing process. */ private final void writeStartElement(final String tag, final String[][] attributes) throws IOException { this.raf.writeBytes(Strings.repeat(" ", this.tags.size())); this.tags.push(tag); this.raf.writeBytes("<" + tag); if (attributes != null) { for (String[] attribute : attributes) { this.raf.writeBytes(" " + attribute[0] + "=\"" + attribute[1] + "\""); } } this.raf.writeBytes(">" + System.lineSeparator()); }
From source file:com.spotify.helios.cli.command.JobInspectCommand.java
private void printVolumes(final PrintStream out, final Map<String, String> volumes) { final String prefix = "Volumes: "; out.print(prefix);//w w w . j a va 2s. c o m boolean first = true; for (final Map.Entry<String, String> entry : volumes.entrySet()) { if (!first) { out.print(Strings.repeat(" ", prefix.length())); } final String path = entry.getValue(); final String source = entry.getKey(); if (source == null) { out.printf("%s%n", path); } else { // Note that we're printing this in value:key order as that's the host:container:[rw|ro] // order used by docker and the helios create command. out.printf("%s:%s%n", path, source); } first = false; } if (first) { out.println(); } }
From source file:org.joda.railmodel.Model.java
public String explain(Station start, Station end) { JourneyOptions solved = solve(start, end); Journey first = solved.first();/*from w w w . j ava 2 s . c o m*/ StringBuilder buf = new StringBuilder(); buf.append("From ").append(start.description()).append(" to ").append(end.description()); int points = solved.points(); if (this instanceof CurrentSWLondonModel) { buf.append(" (").append(points).append("m)").append(NEWLINE); } else { JourneyOptions currentOptions = CurrentSWLondonModel.MODEL.solve(start, end); int currentPoints = currentOptions.points(); int timeChange = points - currentPoints; if (timeChange > 0) { buf.append(" (").append(timeChange).append("m worse)").append(NEWLINE); } else if (timeChange < 0) { buf.append(" (").append(-timeChange).append("m better)").append(NEWLINE); } else { buf.append(" (No change)").append(NEWLINE); } } buf.append(Strings.repeat("-", buf.length() - NEWLINE.length())).append(NEWLINE); int maxExcess = MAX_EXCESS; if (first.isDirect()) { maxExcess = MAX_EXCESS_WHEN_DIRECT; } for (Journey journey : solved.getJourneys()) { if (journey != first) { int diff = first.differenceTo(journey); if (diff <= maxExcess) { buf.append("* ").append(journey).append(" (+").append(diff).append("m)").append(NEWLINE); } } else { buf.append("* ").append(journey).append(NEWLINE); } } return buf.toString(); }
From source file:de.hasait.majala.MajalaMojo.java
private CollectResult collectArtifact(final Artifact pArtifact) throws MojoExecutionException { getLog().debug("Artifact: " + pArtifact.toString()); final CollectRequest collectRequest = new CollectRequest(); Dependency rootNode = new Dependency(pArtifact, "runtime"); collectRequest.setRoot(rootNode);//from w w w . j ava 2s. c o m collectRequest.setRepositories(repositories); getLog().debug("Repositories: " + repositories); final CollectResult collectResult; try { collectResult = repoSystem.collectDependencies(repoSession, collectRequest); } catch (final Exception e) { throw new MojoExecutionException("Collecting dependencies failed", e); } getLog().info("CollectResult..."); collectResult.getRoot().accept(new DependencyVisitor() { private int depth = 0; public boolean visitEnter(final DependencyNode node) { depth++; getLog().info(Strings.repeat("-", depth) + " " + node.getArtifact() + " "); return true; } public boolean visitLeave(final DependencyNode node) { depth--; return true; } }); return collectResult; }
From source file:com.facebook.buck.cli.AuditRulesCommand.java
/** * @param value in a Map returned by {@link ProjectBuildFileParser#getAllRules(Path)}. * @return a string that represents the Python equivalent of the value. *//*from w w w. j a va2s .c o m*/ @VisibleForTesting static String createDisplayString(@Nullable Object value) { if (value == null) { return "None"; } else if (value instanceof Boolean) { return MoreStrings.capitalize(value.toString()); } else if (value instanceof String) { return Escaper.escapeAsPythonString(value.toString()); } else if (value instanceof Number) { return value.toString(); } else if (value instanceof List) { StringBuilder out = new StringBuilder("[\n"); String indent = Strings.repeat(INDENT, 2); for (Object item : (List<?>) value) { out.append(indent).append(createDisplayString(item)).append(",\n"); } out.append(INDENT).append("]"); return out.toString(); } else { throw new IllegalStateException(); } }
From source file:hudson.plugins.timestamper.action.TimestampsAction.java
private String formatTimestamp(Timestamp timestamp, int precision) { long seconds = timestamp.elapsedMillis / 1000; if (precision == 0) { return String.valueOf(seconds) + "\n"; }// w w w . j ava2 s.com long millis = timestamp.elapsedMillis % 1000; String fractional = String.format("%03d", Long.valueOf(millis)); if (precision <= 3) { fractional = fractional.substring(0, precision); } else if (precision > 3) { fractional += Strings.repeat("0", precision - 3); } return String.valueOf(seconds) + "." + fractional + "\n"; }
From source file:com.google.api.codegen.DiscoveryContext.java
public static List<String> s_lineWrapDoc(String str, int maxWidth, String firstLinePrefix) { int indentWidth = firstLinePrefix.length(); String indent = Strings.repeat(" ", indentWidth); maxWidth = maxWidth - indentWidth;/*from w ww.j a v a2 s . c om*/ List<String> lines = new ArrayList<>(); String prefix = firstLinePrefix; for (String line : str.trim().split("\n")) { line = line.trim(); while (line.length() > maxWidth) { int split = lineWrapIndex(line, maxWidth); lines.add(prefix + line.substring(0, split).trim()); line = line.substring(split).trim(); prefix = indent; } if (!line.isEmpty()) { lines.add(prefix + line); } prefix = indent; } return lines; }