Example usage for com.google.common.base Strings repeat

List of usage examples for com.google.common.base Strings repeat

Introduction

In this page you can find the example usage for com.google.common.base Strings repeat.

Prototype

public static String repeat(String string, int count) 

Source Link

Document

Returns a string consisting of a specific number of concatenated copies of an input string.

Usage

From source file:com.spotify.helios.cli.Table.java

public Table(final PrintStream out, final int padding) {
    this.out = out;
    this.paddingString = Strings.repeat(" ", padding);
}

From source file:com.google.devtools.common.options.OptionsUsage.java

/**
 * Paragraph-fill the specified input text, indenting lines to 'indent' and
 * wrapping lines at 'width'.  Returns the formatted result.
 *//*from  www .  j ava2  s  .  com*/
static String paragraphFill(String in, int indent, int width) {
    String indentString = Strings.repeat(" ", indent);
    StringBuilder out = new StringBuilder();
    String sep = "";
    for (String paragraph : NEWLINE_SPLITTER.split(in)) {
        BreakIterator boundary = BreakIterator.getLineInstance(); // (factory)
        boundary.setText(paragraph);
        out.append(sep).append(indentString);
        int cursor = indent;
        for (int start = boundary.first(), end = boundary
                .next(); end != BreakIterator.DONE; start = end, end = boundary.next()) {
            String word = paragraph.substring(start, end); // (may include trailing space)
            if (word.length() + cursor > width) {
                out.append('\n').append(indentString);
                cursor = indent;
            }
            out.append(word);
            cursor += word.length();
        }
        sep = "\n";
    }
    return out.toString();
}

From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.CodeSpan.java

@Override
public Optional<? extends Inline> createInline(Cursor cursor) {
    char c = cursor.getChar();
    if (c == '`') {
        Matcher matcher = cursor.matcher(pattern);
        if (matcher.matches()) {
            String openingBackticks = matcher.group(1);
            int backtickCount = openingBackticks.length();
            Pattern closingPattern = Pattern.compile(
                    "(?<!`)(" + Strings.repeat("`", backtickCount) + ")([^`]|$)",
                    Pattern.DOTALL | Pattern.MULTILINE);
            cursor.advance(backtickCount);
            String textAtOffset = cursor.getTextAtOffset();
            cursor.rewind(backtickCount);

            Matcher closingMatcher = closingPattern.matcher(textAtOffset);
            if (closingMatcher.find()) {
                String codeText = textAtOffset.substring(0, closingMatcher.start());
                return Optional
                        .of(new Code(cursor.getLineAtOffset(), cursor.getOffset(), backtickCount, codeText));
            }//  ww  w.ja v a 2s .  c o m
        }
    }
    return Optional.absent();
}

From source file:org.apache.jackrabbit.oak.upgrade.SimpleTicker.java

@Override
public String tick() {
    int noOfDots = decreasing ? dotCount-- : dotCount++;
    if (dotCount == 0) {
        decreasing = false;// w  w  w .j  a  va2s . com
    }
    if (dotCount == maxTicks) {
        decreasing = true;
    }
    return Strings.repeat(".", noOfDots);
}

From source file:com.mysema.codegen.AbstractCodeWriter.java

public AbstractCodeWriter(Appendable appendable, int spaces) {
    if (appendable == null) {
        throw new IllegalArgumentException("appendable is null");
    }//ww  w.ja v  a  2  s  .c  om
    this.appendable = appendable;
    this.spaces = spaces;
    this.spacesString = Strings.repeat(" ", spaces);
}

From source file:exec.plm12.LocalRunner.java

public void run(String selector, int numIterations, Injector injector) throws Exception {
    Asserts.assertNotNull(selector);//from w ww. j a v a  2s  .co  m
    Asserts.assertGreaterThan(numIterations, 0);

    for (int itNum = 0; itNum < numIterations; itNum++) {
        String itHeader = String.format("##### iteration %d/%d ", (itNum + 1), numIterations);
        log(Strings.repeat("#", 80));
        log(Strings.padEnd(itHeader, 80, '#'));
        log(Strings.repeat("#", 80));
        log("");

        TaskScheduler<?> scheduler = createScheduler(selector, injector);
        Runnable task = scheduler.getNextNullableTask();
        while (task != null) {
            String taskHeader = String.format("##### next task (in iteration %d/%d) ", (itNum + 1),
                    numIterations);
            log(Strings.padEnd(taskHeader, 80, '#'));
            log("");
            if (task instanceof InjectableRunnable) {
                ((InjectableRunnable) task).injectionForMembers(injector);
            }
            task.run();
            task = scheduler.getNextNullableTask();
        }
    }

    String itHeader = String.format("##### %d iterations finished ", numIterations);
    log(Strings.repeat("#", 80));
    log(Strings.padEnd(itHeader, 80, '#'));
    log(Strings.repeat("#", 80));
}

From source file:org.nest.nestml._ast.ASTDerivative.java

public String getNameOfDerivedVariable() {
    return name + Strings.repeat("'", Math.max(0, getDifferentialOrder().size() - 1));
}

From source file:org.shaf.core.process.cmd.CommandLineHandler.java

/**
 * Returns a {@link Process process} settings containing 'key/value' pairs,
 * where 'key' - name of the process class filed and 'value' - value to
 * which this field need to be set.// w ww  .  j a v a2  s. c  o m
 * 
 * @param descr
 *            the process descriptor.
 * @param args
 *            the process arguments.
 * @return the process execution settings.
 * @throws ParseException
 *             if parsing of the command line has failed.
 */
public final static Properties getSettings(final DescriptionContent descr, final String[] args)
        throws ParseException {

    LOG.trace(Strings.repeat("=", 80));
    LOG.trace("| Block for converting the description content and arguments into");
    LOG.trace("| the settings object.");
    LOG.trace("| Content:   " + descr);
    LOG.trace("| Arguments: " + StringUtils.array2string(args));

    /*
     * Converts the process description into the command line options.
     */
    Options options = CommandOptionHandler.getOptions(descr);

    /*
     * Uses the obtained process options to parse command line arguments.
     */
    CommandLine line = new BasicParser().parse(options, args);

    /*
     * Creates process settings object.
     */
    Properties settings = new Properties();
    for (Object elm : options.getOptions()) {

        LOG.trace(Strings.repeat("-", 80));

        /*
         * Converts a single Option or OptionGroup into array of options.
         * Obviously is we converting a single option array will contain
         * only one element.
         */
        Option[] group = new Option[0];
        if (elm instanceof Option) {
            Option o = (Option) elm;
            group = ObjectArrays.concat(group, o);
        } else {
            OptionGroup og = (OptionGroup) elm;
            for (Object e : og.getOptions()) {
                Option o = (Option) e;
                group = ObjectArrays.concat(group, o);
            }
        }

        /*
         * Populates the process execution settings.
         */
        for (Option option : group) {
            LOG.trace("| Select option:   " + option);

            ResourceInfo resInfo = descr.getResourceInfo(option.getOpt());
            SingleOptionInfo optInfo = (SingleOptionInfo) resInfo.getOptionInfo();
            FieldInfo fldInfo = resInfo.getFieldInfo();

            LOG.trace("| Select resource: " + resInfo);

            String fldName = null;
            String fldValue = null;
            if (fldInfo == null) {
                fldName = optInfo.getName();
                if (!Strings.isNullOrEmpty(optInfo.getValue())) {
                    fldValue = line.getOptionValue(optInfo.getName(), optInfo.getValue());
                } else {
                    fldValue = line.getOptionValue(optInfo.getName());
                }
            } else {
                fldName = fldInfo.getName();
                if (boolean.class.getCanonicalName().equals(fldInfo.getType())
                        || Boolean.class.getCanonicalName().equals(fldInfo.getType())) {
                    fldValue = String.valueOf(line.hasOption(optInfo.getName()));
                } else {
                    if (!Strings.isNullOrEmpty(optInfo.getValue())) {
                        fldValue = line.getOptionValue(optInfo.getName(), optInfo.getValue());
                    } else {
                        fldValue = line.getOptionValue(optInfo.getName());
                    }
                }
            }

            if (fldValue != null) {
                settings.put(fldName + ".option", optInfo.getName());
                LOG.trace("| Set: " + fldName + ".option=" + optInfo.getName());

                settings.put(fldName + ".value", fldValue);
                LOG.trace("| Set: " + fldName + ".value=" + fldValue);
            }
        }
    }

    LOG.trace(Strings.repeat("=", 80));

    LOG.debug("Initialized the process settings: " + settings);

    return settings;
}

From source file:test.SourceVisitor.java

@SuppressWarnings("UseOfSystemOutOrSystemErr")
@Test// w  w w  . j  a v a2s  . co m
public void test() throws IOException {
    try (PrintStream target = new PrintStream("target/test.txt", "ISO-8859-1")) {
        String dashes = Strings.repeat("-", 45);
        StringWriter sw = new StringWriter();
        PrintWriter out = new PrintWriter(sw);
        Files.walk(Paths.get("src/main"))
                .filter(path -> path.getFileName().toString().matches(".*\\.(html|jspx?)")).forEach(path -> {
                    try {
                        String string = new String(Files.readAllBytes(path), StandardCharsets.ISO_8859_1);
                        string = string.replaceFirst(
                                "/\\*[\000-\uFFFF]+?org/licenses/LICENSE[\000-\uFFFF]+?\\*/\r?\n?", "");
                        string = string
                                .replaceFirst("\r?\n?/\\*[\000-\uFFFF]+?@author zhanhb[\000-\uFFFF]+?\\*/", "");
                        out.println(dashes + path.getFileName() + dashes);
                        out.println(string);
                    } catch (IOException ex) {
                        throw new UncheckedIOException(ex);
                    }
                });
        Files.walk(Paths.get("src/main")).filter(path -> path.getFileName().toString().endsWith(".java"))
                .filter(path -> !path.getFileName().toString().equals("package-info.java")).forEach(path -> {
                    try {
                        String string = new String(Files.readAllBytes(path), StandardCharsets.ISO_8859_1);
                        if (!string.contains("@author zhanhb")) {
                            System.err.println(path);
                            return;
                        }
                        string = string.replaceFirst(
                                "/\\*[\000-\uFFFF]+?org/licenses/LICENSE[\000-\uFFFF]+?\\*/\r?\n?", "");
                        string = string
                                .replaceFirst("\r?\n?/\\*[\000-\uFFFF]+?@author zhanhb[\000-\uFFFF]+?\\*/", "");
                        out.println(dashes + path.getFileName() + dashes);
                        out.println(string);
                    } catch (IOException ex) {
                        throw new UncheckedIOException(ex);
                    }
                });
        out.flush();
        String s = new BufferedReader(new StringReader(sw.toString())).lines()
                .filter(str -> !str.startsWith("import ")).filter(str -> !str.startsWith("package "))
                .collect(Collectors.joining("\n"));
        target.print(s.replaceAll(dashes + "(\\r?\\n)+", dashes + "\\\n"));
    }
}

From source file:com.facebook.buck.rules.FakeAbiRuleBuildRule.java

@Override
public Sha1HashCode getAbiKeyForDeps(RuleKeyBuilderFactory defaultRuleKeyBuilderFactory) {
    if (abiKey == null) {
        String hashCode = String.valueOf(Math.abs(this.hashCode()));
        abiKey = Sha1HashCode.of(Strings.repeat(hashCode, 40 / hashCode.length() + 1).substring(0, 40));
    }/*from ww  w  .  j  ava 2s . com*/
    return abiKey;
}