List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:com.planet57.gshell.internal.ShellImpl.java
private static void renderMessage(final IO io, @Nullable String message) { if (message != null) { // HACK: branding does not have easy access to Terminal; so allow a line to be rendered via replacement token if (message.contains(BrandingSupport.LINE_TOKEN)) { message = message.replace(BrandingSupport.LINE_TOKEN, Strings.repeat("-", io.terminal.getWidth() - 1)); }/*from w w w. java 2 s . c om*/ io.out.println(message); io.out.flush(); } }
From source file:google.registry.tools.server.ListObjectsAction.java
/** Converts the provided table of data to text, formatted using the provided column widths. */ private List<String> generateFormattedData(ImmutableTable<T, String, String> data, ImmutableMap<String, Integer> columnWidths) { Function<Map<String, String>, String> rowFormatter = makeRowFormatter(columnWidths); List<String> lines = new ArrayList<>(); if (isHeaderRowInUse(data)) { // Add a row of headers (column names mapping to themselves). Map<String, String> headerRow = Maps.asMap(data.columnKeySet(), Functions.<String>identity()); lines.add(rowFormatter.apply(headerRow)); // Add a row of separator lines (column names mapping to '-' * column width). Map<String, String> separatorRow = Maps.transformValues(columnWidths, new Function<Integer, String>() { @Override/*from w w w . j a v a2s.c om*/ public String apply(Integer width) { return Strings.repeat("-", width); } }); lines.add(rowFormatter.apply(separatorRow)); } // Add the actual data rows. for (Map<String, String> row : data.rowMap().values()) { lines.add(rowFormatter.apply(row)); } return lines; }
From source file:io.github.aritzhack.aritzh.bds.BDSCompound.java
private String pretty(final int level) { StringBuilder builder = new StringBuilder(); int cLevel = level; builder.append(Strings.repeat(" ", cLevel * 4)).append("[").append(this.getType()).append(":") .append(this.getName()).append("]\n").append(Strings.repeat(" ", cLevel * 4)).append("{"); cLevel++;//w w w . ja va 2 s . com boolean some = false; for (BDS b : this.items) { some = true; if (b instanceof BDSCompEnd) continue; if (b instanceof BDSCompound) { builder.append("\n").append(((BDSCompound) b).pretty(cLevel)); continue; } builder.append("\n").append(Strings.repeat(" ", cLevel * 4)).append(b); } if (!some) builder.append("\n").append(Strings.repeat(" ", cLevel * 4)).append("[EMPTY COMPOUND]"); cLevel--; builder.append("\n").append(Strings.repeat(" ", cLevel * 4)).append("}"); return builder.toString(); }
From source file:alluxio.cli.fsadmin.report.CapacityCommand.java
/** * Prints indented information.//from w w w . j a v a 2 s .co m * * @param text information to print */ private void print(String text) { String indent = Strings.repeat(" ", mIndentationLevel * INDENT_SIZE); mPrintStream.println(indent + text); }
From source file:com.splicemachine.derby.impl.sql.execute.operations.ScanOperation.java
@Override public String prettyPrint(int indentLevel) { String indent = "\n" + Strings.repeat("\t", indentLevel); return "Scan:" + indent + "resultSetNumber:" + resultSetNumber + indent + "optimizerEstimatedCost:" + optimizerEstimatedCost + "," + indent + "optimizerEstimatedRowCount:" + optimizerEstimatedRowCount + "," + indent + "scanInformation:" + scanInformation + indent + "tableName:" + tableName; }
From source file:com.doctusoft.bean.apt.AnnotationProcessor.java
public void emitPropertyDescriptorClass(TypeElement enclosingType, Collection<ElementDescriptor> descriptors) throws Exception { PackageElement pck = (PackageElement) enclosingType.getEnclosingElement(); ByteArrayOutputStream sourceBytes = new ByteArrayOutputStream(); Writer writer = new PrintWriter(sourceBytes); writer.write("package " + pck.getQualifiedName() + ";\n\n"); writer.write("import com.doctusoft.bean.ModelObject;\n"); writer.write("import com.doctusoft.bean.Property;\n"); writer.write("import com.doctusoft.bean.ObservableProperty;\n"); writer.write("import com.doctusoft.bean.ListenerRegistration;\n"); writer.write("import com.doctusoft.bean.ValueChangeListener;\n"); writer.write("import com.doctusoft.bean.ModelObjectDescriptor;\n"); writer.write("import com.doctusoft.bean.BeanPropertyChangeListener;\n"); writer.write("import com.doctusoft.bean.internal.PropertyListeners;\n\n"); writer.write("import com.doctusoft.bean.internal.BeanPropertyListeners;\n\n"); writer.write("import com.google.common.collect.ImmutableList;\n"); DeclaredType holderType = (DeclaredType) enclosingType.asType(); String holderTypeSimpleName = ((TypeElement) holderType.asElement()).getSimpleName().toString(); String holderTypeName = holderTypeSimpleName; if (!holderType.getTypeArguments().isEmpty()) { int parametersCount = holderType.getTypeArguments().size(); holderTypeName += "<" + Strings.repeat("?,", parametersCount - 1) + "?>"; }//from www .j a v a2 s . co m writer.write("\npublic class " + holderTypeSimpleName + "_ {\n"); // write individual descriptors for (ElementDescriptor descriptor : descriptors) { if (descriptor instanceof PropertyDescriptor) { emitPropertyLiteral(writer, (PropertyDescriptor) descriptor, holderType, holderTypeSimpleName); } if (descriptor instanceof MethodDescriptor) { emitMethodLiteral(writer, (MethodDescriptor) descriptor, holderTypeName, holderTypeSimpleName); } } if (typeImplements(enclosingType, ModelObject.class.getName())) { emitObservableAttributesList(writer, descriptors, enclosingType); emitModelObjectDescriptor(writer, holderTypeName, enclosingType, !descriptors.isEmpty()); } writer.write("\n}"); writer.close(); // open the file only after everything worked fine and the source is ready String fileName = enclosingType.getQualifiedName() + "_"; JavaFileObject source = filer.createSourceFile(fileName); OutputStream os = source.openOutputStream(); os.write(sourceBytes.toByteArray()); os.close(); }
From source file:org.eclipse.elk.layered.JsonDebugUtil.java
/** * Begins a new list of child nodes with the given indentation. * //from www. ja v a 2 s.c om * @param writer * writer to write to. * @param indentation * the indentation level to use. * @throws IOException * if anything goes wrong with the writer. */ private static void beginChildNodeList(final Writer writer, final int indentation) throws IOException { writer.write(",\n" + Strings.repeat(INDENT, indentation) + "\"children\": ["); }
From source file:org.apache.james.quota.search.QuotaSearcherContract.java
default MessageManager.AppendCommand withSize(int size) { byte[] bytes = Strings.repeat("a", size).getBytes(StandardCharsets.UTF_8); return MessageManager.AppendCommand.from(new ByteArrayInputStream(bytes)); }
From source file:net.sourceforge.docfetcher.build.BuildMain.java
private static void runTests() { Util.println("Running tests..."); final List<String> classNames = new ArrayList<String>(); new FileWalker() { protected void handleFile(File file) { String name = file.getName(); if (!name.endsWith(".java")) return; name = Util.splitFilename(name)[0]; if (!name.startsWith("Test") && !name.endsWith("Test")) return; String path = file.getPath(); int start = "src/".length(); int end = path.length() - ".java".length(); path = path.substring(start, end); path = path.replace("/", ".").replace("\\", "."); if (path.equals(TestFiles.class.getName())) return; classNames.add(path);//from www . ja v a2 s . co m } }.run(new File("src")); Collections.sort(classNames); JUnitCore junit = new JUnitCore(); junit.addListener(new RunListener() { public void testFailure(Failure failure) throws Exception { Util.printErr(Strings.repeat(" ", 8) + "FAILED"); } }); for (String className : classNames) { /* * AppUtil.Const must be cleared before each test, otherwise one * test class could load AppUtil.Const and thereby hide * AppUtil.Const loading failures in subsequent tests. */ AppUtil.Const.clear(); try { Class<?> clazz = Class.forName(className); Util.println(Strings.repeat(" ", 4) + className); junit.run(clazz); } catch (ClassNotFoundException e) { Util.printErr(e); } } AppUtil.Const.clear(); }
From source file:com.zimbra.cs.volume.VolumeCLI.java
private void printOpt(String optStr, int leftPad) { Options options = getOptions();//from w ww . j ava 2 s .com Option opt = options.getOption(optStr); StringBuilder buf = new StringBuilder(); buf.append(Strings.repeat(" ", leftPad)); buf.append('-').append(opt.getOpt()).append(",--").append(opt.getLongOpt()); if (opt.hasArg()) { buf.append(" <arg>"); } buf.append(Strings.repeat(" ", 35 - buf.length())); buf.append(opt.getDescription()); System.err.println(buf.toString()); }