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.github.fhirschmann.clozegen.lib.formatters.PlainTextFormatter.java

@Override
public String format(final JCas jcas) {
    StringBuilder sb = new StringBuilder();
    String text = checkNotNull(jcas).getDocumentText();
    int position = 0;
    for (GapAnnotation gap : JCasUtil.select(jcas, GapAnnotation.class)) {
        sb.append(text.substring(position, gap.getBegin()));
        sb.append(Strings.repeat("_",
                CollectionUtils.getMaximumElementLength(FSCollectionFactory.create(gap.getAllAnswers()))));
        sb.append(FSCollectionFactory.create(gap.getAllAnswers()).toString());
        position = gap.getEnd();/*from ww  w .ja v a2  s  .  c  o m*/
    }
    sb.append(text.substring(position));

    return sb.toString();
}

From source file:org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil.java

public static String formatJavaSource(final String input) {
    Iterable<String> split = Splitter.on("\n").trimResults().split(input);

    int basicIndent = 4;
    StringBuilder sb = new StringBuilder();
    int indents = 0, empty = 0;
    for (String line : split) {
        indents -= StringUtils.countMatches(line, "}");
        if (indents < 0) {
            indents = 0;//from   w  ww  .j a  v  a 2s. com
        }
        if (!line.isEmpty()) {
            sb.append(Strings.repeat(" ", basicIndent * indents));
            sb.append(line);
            sb.append("\n");
            empty = 0;
        } else {
            empty++; // one empty line is allowed
            if (empty < 2) {
                sb.append("\n");
            }
        }
        indents += StringUtils.countMatches(line, "{");
    }
    return ensureEndsWithSingleNewLine(sb.toString());
}

From source file:org.xpect.expectation.impl.AbstractExpectation.java

protected String findValidSeparator(String value, String suggestedSeparator) {
    if (suggestedSeparator != null && !value.contains(suggestedSeparator))
        return suggestedSeparator;
    final String chars = "-~=+*%#$&";
    for (int i = 3; i < 80; i++) {
        for (int c = 0; i < chars.length(); c++) {
            String separator = Strings.repeat(String.valueOf(chars.charAt(c)), i);
            if (!value.contains(separator))
                return separator;
        }/*from  w  w w  .  java  2s  .com*/
    }
    throw new IllegalStateException();
}

From source file:com.google.security.zynamics.binnavi.ZyGraph.Builders.CommentContainer.java

public List<String> getCommentingString() {
    if (this.comment == null) {
        return null;
    }//  w  w  w. ja v a2s.co m
    if (this.comment.getComment().split("\\n").length <= 1) {
        return Lists.newArrayList(
                this.comment.getUser().getUserName() + userNameDelimiter + this.comment.getComment());
    }
    if (this.comment.getComment().split("\\n").length > 1) {
        final String[] commentFragments = this.comment.getComment().split("\\n");
        final List<String> generatedComment = Lists
                .newArrayList(this.comment.getUser().getUserName() + userNameDelimiter + commentFragments[0]);
        for (int i = 1; i < commentFragments.length; i++) {
            generatedComment.add(Strings.repeat(" ",
                    this.comment.getUser().getUserName().length() + userNameDelimiter.length())
                    + commentFragments[i]);
        }
        return generatedComment;
    }
    return null;
}

From source file:io.jeo.cli.ConsoleProgress.java

/**
 * Redraws the progress bar.//from w  w w .j  ava 2 s  .c om
 * <p>
 * This method is called from {@link #inc()} so no need to call it explicitly.
 * </p>
 */
public ConsoleProgress redraw() {
    if (total < 0) {
        return this;
    }

    //number of digits in total to padd count
    int n = (int) (Math.log10(total) + 1);

    StringBuilder sb = new StringBuilder();

    // first encode count/total
    sb.append("[").append(String.format(Locale.ROOT, "%" + n + "d", count)).append("/").append(total)
            .append("]");

    // second is percent
    sb.append(" ").append(String.format(Locale.ROOT, "%3.0f", (count / (float) total * 100))).append("% ");

    //last is progress bar
    int left = console.getTerminal().getWidth() - sb.length() - 2;
    int progress = count * left / total;

    sb.append("[").append(Strings.repeat("=", progress)).append(Strings.repeat(" ", left - progress))
            .append("]");

    output.print(sb.toString() + "\r");
    return this;
}

From source file:org.geowebcache.service.wmts.WMTSService.java

static final String buildRestPattern(int numPathElements, boolean hasStyle) {
    if (!hasStyle) {
        return ".*/service/wmts/rest" + Strings.repeat("/([^/]+)", numPathElements);
    } else {/*from  w  w w  .j ava 2 s.c o  m*/
        return ".*/service/wmts/rest/([^/]+)/([^/]*)" + Strings.repeat("/([^/]+)", numPathElements - 2);
    }
}

From source file:ninja.leaping.permissionsex.util.command.args.ArgumentParseException.java

public String getAnnotatedPosition() {
    String source = this.source;
    int position = this.position;
    if (source.length() > 80) {
        if (position >= 37) {
            int startPos = position - 37, endPos = Math.min(source.length(), position + 37);
            if (endPos < source.length()) {
                source = "..." + source.substring(startPos, endPos) + "...";
            } else {
                source = "..." + source.substring(startPos, endPos);
            }//w w  w  .  j  a v a 2s  .c  om
            position -= 40;
        } else {
            source = source.substring(0, 77) + "...";
        }
    }
    return source + "\n" + Strings.repeat(" ", position) + "^";
}

From source file:com.technophobia.substeps.runner.BuildFailureManager.java

private static String getBuildInfoString(final String msg, final List<List<IExecutionNode>> failures) {

    final StringBuilder buf = new StringBuilder();

    if (failures != null && !failures.isEmpty()) {

        buf.append("\n");
        buf.append(msg);/*from   w ww.  j  av  a2 s .c  o m*/

        for (List<IExecutionNode> failurePath : failures) {

            buf.append("\n\n");

            IExecutionNode lastNode = failurePath.get(failurePath.size() - 1);

            ThrowableInfo throwableInfo = lastNode.getResult().getFailure().getThrowableInfo();

            if (throwableInfo != null && throwableInfo.getMessage() != null) {

                buf.append(throwableInfo.getMessage() + "\n");
            }

            buf.append("Trace:\n\n");

            for (IExecutionNode node : failurePath) {

                buf.append(node.getId() + ":");
                buf.append(Strings.repeat("   ", node.getDepth()));
                buf.append(node.getDescription() + "\n");

            }
        }
    }

    return buf.toString();
}

From source file:com.clarkparsia.openrdf.query.sparql.SparqlTupleExprRenderer.java

private String indent() {
    return Strings.repeat(" ", mIndent);
}

From source file:fr.xebia.demo.amazon.aws.SelfSignedX509CertificateGeneratorDemo.java

/**
 * <p>// w w  w  .  j ava 2 s  .c  o  m
 * Generate a self signed X509 certificate .
 * </p>
 * <p>
 * TODO : do the same with
 * {@link org.bouncycastle.cert.X509v1CertificateBuilder} instead of the
 * deprecated {@link org.bouncycastle.x509.X509V1CertificateGenerator}.
 * </p>
 */
@SuppressWarnings("deprecation")
static void generateSelfSignedX509Certificate() throws NoSuchAlgorithmException, NoSuchProviderException,
        CertificateEncodingException, SignatureException, InvalidKeyException, IOException {

    // yesterday
    Date validityBeginDate = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000);
    // in 2 years
    Date validityEndDate = new Date(System.currentTimeMillis() + 2 * 365 * 24 * 60 * 60 * 1000);

    // GENERATE THE PUBLIC/PRIVATE RSA KEY PAIR
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", "BC");
    keyPairGenerator.initialize(1024, new SecureRandom());

    KeyPair keyPair = keyPairGenerator.generateKeyPair();

    // GENERATE THE X509 CERTIFICATE
    X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();
    X500Principal dnName = new X500Principal("CN=John Doe");

    certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
    certGen.setSubjectDN(dnName);
    certGen.setIssuerDN(dnName); // use the same
    certGen.setNotBefore(validityBeginDate);
    certGen.setNotAfter(validityEndDate);
    certGen.setPublicKey(keyPair.getPublic());
    certGen.setSignatureAlgorithm("SHA256WithRSAEncryption");

    X509Certificate cert = certGen.generate(keyPair.getPrivate(), "BC");

    // DUMP CERTIFICATE AND KEY PAIR
    System.out.println(Strings.repeat("=", 80));
    System.out.println("CERTIFICATE TO_STRING");
    System.out.println(Strings.repeat("=", 80));
    System.out.println();
    System.out.println(cert);
    System.out.println();

    System.out.println(Strings.repeat("=", 80));
    System.out.println("CERTIFICATE PEM (to store in a cert-johndoe.pem file)");
    System.out.println(Strings.repeat("=", 80));
    System.out.println();
    PEMWriter pemWriter = new PEMWriter(new PrintWriter(System.out));
    pemWriter.writeObject(cert);
    pemWriter.flush();
    System.out.println();

    System.out.println(Strings.repeat("=", 80));
    System.out.println("PRIVATE KEY PEM (to store in a priv-johndoe.pem file)");
    System.out.println(Strings.repeat("=", 80));
    System.out.println();
    pemWriter.writeObject(keyPair.getPrivate());
    pemWriter.flush();
    System.out.println();
}