List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:parquet.tools.util.PrettyPrintWriter.java
public void setTabLevel(int level) { this.tabLevel = level; this.tabs = Strings.repeat(" ", tabWidth * level); if (flushOnTab) flushColumns();/*from w w w .j ava2 s .c o m*/ }
From source file:io.prestosql.cli.Console.java
private static void runConsole(QueryRunner queryRunner, AtomicBoolean exiting) { try (TableNameCompleter tableNameCompleter = new TableNameCompleter(queryRunner); LineReader reader = new LineReader(getHistory(), commandCompleter(), lowerCaseCommandCompleter(), tableNameCompleter)) { tableNameCompleter.populateCache(); StringBuilder buffer = new StringBuilder(); while (!exiting.get()) { // read a line of input from user String prompt = PROMPT_NAME; String schema = queryRunner.getSession().getSchema(); if (schema != null) { prompt += ":" + schema; }//from w w w .j a v a2 s .c om if (buffer.length() > 0) { prompt = Strings.repeat(" ", prompt.length() - 1) + "-"; } String commandPrompt = prompt + "> "; String line = reader.readLine(commandPrompt); // add buffer to history and clear on user interrupt if (reader.interrupted()) { String partial = squeezeStatement(buffer.toString()); if (!partial.isEmpty()) { reader.getHistory().add(partial); } buffer = new StringBuilder(); continue; } // exit on EOF if (line == null) { System.out.println(); return; } // check for special commands if this is the first line if (buffer.length() == 0) { String command = line.trim(); if (HISTORY_INDEX_PATTERN.matcher(command).matches()) { int historyIndex = parseInt(command.substring(1)); History history = reader.getHistory(); if ((historyIndex <= 0) || (historyIndex > history.index())) { System.err.println("Command does not exist"); continue; } line = history.get(historyIndex - 1).toString(); System.out.println(commandPrompt + line); } if (command.endsWith(";")) { command = command.substring(0, command.length() - 1).trim(); } switch (command.toLowerCase(ENGLISH)) { case "exit": case "quit": return; case "history": for (History.Entry entry : reader.getHistory()) { System.out.printf("%5d %s%n", entry.index() + 1, entry.value()); } continue; case "help": System.out.println(); System.out.println(getHelpText()); continue; } } // not a command, add line to buffer buffer.append(line).append("\n"); // execute any complete statements String sql = buffer.toString(); StatementSplitter splitter = new StatementSplitter(sql, ImmutableSet.of(";", "\\G")); for (Statement split : splitter.getCompleteStatements()) { OutputFormat outputFormat = OutputFormat.ALIGNED; if (split.terminator().equals("\\G")) { outputFormat = OutputFormat.VERTICAL; } process(queryRunner, split.statement(), outputFormat, tableNameCompleter::populateCache, true, true, System.out, System.out); reader.getHistory().add(squeezeStatement(split.statement()) + split.terminator()); } // replace buffer with trailing partial statement buffer = new StringBuilder(); String partial = splitter.getPartialStatement(); if (!partial.isEmpty()) { buffer.append(partial).append('\n'); } } } catch (IOException e) { System.err.println("Readline error: " + e.getMessage()); } }
From source file:org.apache.james.mailrepository.MailRepositoryContract.java
@Test default void storeBigMailShouldNotFail() throws Exception { MailRepository testee = retrieveRepository(); String bigString = Strings.repeat("my mail is big ?", 1_000_000); Mail mail = createMail(MAIL_1, bigString); testee.store(mail);/*from www .j a v a2s. co m*/ }
From source file:org.robotframework.ide.eclipse.main.plugin.tableeditor.source.SuiteSourceFormattingStrategy.java
private String formatWithDynamicSeparator(final String content, final String delimiter, final FormatterProperties properties) { String tabsFreeContent;/*from w ww. j a v a 2 s . co m*/ try (BufferedReader reader = new BufferedReader(new StringReader(content))) { final StringBuilder contentWithoutTabs = new StringBuilder(); String line = reader.readLine(); while (line != null) { contentWithoutTabs.append(line.replaceAll("\t", " ")); contentWithoutTabs.append(delimiter); line = reader.readLine(); } tabsFreeContent = contentWithoutTabs.toString(); } catch (final IOException e) { return content; } final Map<Integer, Integer> columnsLength = Maps.newHashMap(); try (BufferedReader reader = new BufferedReader(new StringReader(tabsFreeContent))) { String line = reader.readLine(); while (line != null) { updateCellLengths(line, columnsLength); line = reader.readLine(); } } catch (final IOException e) { return content; } try (BufferedReader reader = new BufferedReader(new StringReader(tabsFreeContent))) { final StringBuilder formattedContent = new StringBuilder(); String line = reader.readLine(); while (line != null) { int column = 0; final StringBuilder formattedLine = new StringBuilder(); for (final String cell : Splitter.onPattern(" +").splitToList(line)) { formattedLine.append(Strings.padEnd(cell, columnsLength.get(column), ' ')); formattedLine.append(Strings.repeat(" ", properties.separatorLength)); column++; } formattedContent.append(formattedLine.toString().replaceAll(" +$", "")); formattedContent.append(delimiter); line = reader.readLine(); } return formattedContent.toString(); } catch (final IOException e) { return content; } }
From source file:com.google.template.soy.jssrc.internal.JsCodeBuilder.java
/** * Helper for the various indent methods. * @param chg The number of indent levels to change. *//*from w ww . ja v a 2s . c o m*/ private JsCodeBuilder changeIndentHelper(int chg) { int newIndentDepth = indent.length() + chg * INDENT_SIZE; Preconditions.checkState(newIndentDepth >= 0); indent = Strings.repeat(" ", newIndentDepth); return this; }
From source file:org.eclipse.xtext.ui.util.PluginProjectFactory.java
/** * @since 2.8/*from www . j av a 2s .c o m*/ */ protected void addToBuildProperties(StringBuilder content, Iterable<String> entries, String entryName) { if (entries != null && !Iterables.isEmpty(entries)) { String assigment = entryName + " = "; String indent = Strings.repeat(" ", assigment.length()); content.append(assigment); for (final Iterator<String> iterator = entries.iterator(); iterator.hasNext();) { content.append(iterator.next()); if (iterator.hasNext()) { content.append(",\\\n"); content.append(indent); } } } }
From source file:org.eclipse.xtext.xtext.wizard.ProjectDescriptor.java
private String buildPropertiesEntry(final String key, final Iterable<String> value) { String _xblockexpression = null; {// ww w. ja v a 2s.c o m boolean _isEmpty = IterableExtensions.isEmpty(value); if (_isEmpty) { return ""; } final String assignment = (key + " = "); final String indent = Strings.repeat(" ", assignment.length()); String _join = IterableExtensions.join(value, (",\\\n" + indent)); _xblockexpression = (assignment + _join); } return _xblockexpression; }
From source file:org.lilyproject.tools.generatesplitkeys.GenerateSplitKeys.java
private String toFixedLengthHex(long value, int length) { String hex = Long.toHexString(value); if (hex.length() > length) { throw new RuntimeException("Unexpected: hex representation is longer than it should be: " + hex + ", expected only " + length + " characters"); }/*from ww w . j a va 2 s.c om*/ return Strings.repeat("0", length - hex.length()) + hex; }
From source file:com.google.template.soy.jssrc.internal.JsCodeBuilder.java
void setIndent(int indentCt) { this.indent = Strings.repeat(" ", indentCt); }
From source file:ezbake.deployer.utilities.Utilities.java
private static String ppList(List<?> list, int depth) { List<String> entries = Lists.newArrayList(); final String indent = Strings.repeat(" ", depth); for (int i = 0; i < list.size(); i++) { entries.add(s("%s[%d] = %s", indent, i, ppObject(list.get(i), depth))); }//w w w . j a va2 s .c o m return entries.isEmpty() ? "[]" : s("[\n%s\n%s]", Joiner.on(",\n").join(entries), Strings.repeat(" ", depth - 1)); }