Example usage for org.apache.commons.lang3 StringUtils repeat

List of usage examples for org.apache.commons.lang3 StringUtils repeat

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils repeat.

Prototype

public static String repeat(final char ch, final int repeat) 

Source Link

Document

<p>Returns padding using the specified delimiter repeated to a given length.</p> <pre> StringUtils.repeat('e', 0) = "" StringUtils.repeat('e', 3) = "eee" StringUtils.repeat('e', -2) = "" </pre> <p>Note: this method doesn't not support padding with <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a> as they require a pair of char s to be represented.

Usage

From source file:com.gmarciani.gmparser.commons.TestNonDeterministicFunction.java

@Test
public void createCompleteFunction() {
    System.out.println("#createCompleteFunction");
    GSet<Character> domainX = new GSet<Character>();
    domainX.add('a');
    domainX.add('b');
    domainX.add('c');
    GSet<Integer> domainY = new GSet<Integer>();
    domainY.add(1);//w  ww.  j  a  v  a2 s.c om
    domainY.add(2);
    domainY.add(3);
    GSet<String> domainZ = new GSet<String>();

    for (Character c : domainX) {
        for (Integer n : domainY) {
            for (int i = 1; i <= n; i++)
                domainZ.add(StringUtils.repeat(c, i));
        }
    }

    Function<Character, Integer, String> function = new NonDeterministicFunction<Character, Integer, String>(
            domainX, domainY, domainZ);

    for (Character c : domainX) {
        for (Integer n : domainY) {
            for (int i = 1; i <= n; i++)
                function.add(c, n, StringUtils.repeat(c, i));
        }
    }

    System.out.println(function);
    System.out.println(function.toFormattedFunction());
}

From source file:com.kakao.hbase.manager.command.BalanceFactor.java

public static StringBuilder usage(int indent) {
    StringBuilder sb = new StringBuilder();
    for (BalanceFactor balanceFactor : BalanceFactor.values()) {
        if (balanceFactor != EMPTY)
            sb.append(StringUtils.repeat(INDENT_CHAR, indent)).append(balanceFactor.shortName()).append(" : ")
                    .append(balanceFactor.name()).append("\n");
    }/*from   www  .  ja v  a 2s  .  c  o m*/
    return sb;
}

From source file:com.hortonworks.registries.storage.tool.shell.ShellMigrationExecutor.java

@Override
public void execute(Connection connection) throws SQLException {
    String scriptLocation = this.shellScriptResource.getLocationOnDisk();
    try {//  w ww .j a v  a  2 s  . com
        List<String> args = new ArrayList<String>();
        args.add(scriptLocation);
        ProcessBuilder builder = new ProcessBuilder(args);
        builder.redirectErrorStream(true);
        Process process = builder.start();
        Scanner in = new Scanner(process.getInputStream());
        System.out.println(StringUtils.repeat("+", 200));
        while (in.hasNextLine()) {
            System.out.println(in.nextLine());
        }
        int returnCode = process.waitFor();
        System.out.println(StringUtils.repeat("+", 200));
        if (returnCode != 0) {
            throw new FlywayException("script exited with value : " + returnCode);
        }
    } catch (Exception e) {
        LOG.error(e.toString());
        // Only if SQLException or FlywaySqlScriptException is thrown flyway will mark the migration as failed in the metadata table
        throw new SQLException(String.format("Failed to run script \"%s\", %s", scriptLocation, e.getMessage()),
                e);
    }
}

From source file:cz.hobrasoft.pdfmu.TextOutput.java

/**
 * Prints a message on a separate line/*from w  ww  .jav a 2 s . c  o  m*/
 *
 * <p>
 * The message is indented by the current indentation level (starting at 0)
 * and printed using the specified {@link PrintStream}.
 *
 * <p>
 * Mimics {@link PrintStream#println(String x)}.
 *
 * @param x message to print
 */
public void println(String x) {
    if (ps != null) {
        assert indentLevel >= 0;
        String prefix = StringUtils.repeat(indentString, indentLevel);
        ps.println(String.format("%s%s", prefix, x));
    }
}

From source file:net.sf.jsignpdf.Signer.java

/**
 * Prints formatted help message (command line arguments).
 *//*from w  w  w.  j  av  a  2  s  . co m*/
private static void printHelp() {
    final HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(80, "java -jar JSignPdf.jar [file1.pdf [file2.pdf ...]]", RES.get("hlp.header"),
            SignerOptionsFromCmdLine.OPTS, NEW_LINE + RES.get("hlp.footer.exitCodes") + NEW_LINE
                    + StringUtils.repeat("-", 80) + NEW_LINE + RES.get("hlp.footer.examples"),
            true);
}

From source file:com.cloudera.impala.catalog.StructField.java

/**
 * Pretty prints this field with lpad number of leading spaces.
 * Calls prettyPrint(lpad) on this field's type.
 *//*from   w  w  w.ja v  a 2s .  c  o  m*/
public String prettyPrint(int lpad) {
    String leftPadding = StringUtils.repeat(' ', lpad);
    StringBuilder sb = new StringBuilder(leftPadding + name_);
    if (type_ != null) {
        // Pass in the padding to make sure nested fields are aligned properly,
        // even if we then strip the top-level padding.
        String typeStr = type_.prettyPrint(lpad);
        typeStr = typeStr.substring(lpad);
        sb.append(":" + typeStr);
    }
    if (comment_ != null)
        sb.append(String.format(" COMMENT '%s'", comment_));
    return sb.toString();
}

From source file:com.nike.cerberus.operation.vault.VaultHealthCheckOperation.java

@Override
public void run(VaultHealthCheckCommand command) {
    List<String> msgList = Lists.newLinkedList();
    boolean toggle = false;
    do {/*ww  w . ja  v a 2  s.co m*/
        final List<VaultAdminClient> clients = vaultAdminClientFactory.getClientsForCluster();
        clients.forEach(client -> {
            try {
                VaultHealthResponse response = client.health();
                msgList.add(String.format("%s: Initialized: %s, Sealed: %s, Standby: %s", client.getVaultUrl(),
                        colorify(response.isInitialized()), colorify(response.isSealed()),
                        colorify(response.isStandby())));
            } catch (Throwable t) {
                msgList.add(String.format("ERROR: %s", t.getMessage()));
            }
        });

        String sym = toggle ? "*" : "+";
        sym = StringUtils.repeat(sym, 20);

        if (command.isPoll()) {
            logger.info(Ansi.eraseScreen());
        }

        logger.info(String.format("%s - Vault Health Status - %s", sym, sym));
        msgList.forEach(logger::info);
        msgList.clear();
        toggle = !toggle;

        try {
            Thread.sleep(TimeUnit.SECONDS.toMillis(1));
        } catch (InterruptedException e) {
            break;
        }
    } while (command.isPoll());
}

From source file:com.linkedin.restli.datagenerator.csharp.CSharpUtil.java

public static String spaces(int n) {
    return StringUtils.repeat(" ", n);
}

From source file:fi.helsinki.moodi.util.TabularFormat.java

private String toString(final String template) {
    final StringBuilder sb = new StringBuilder();
    for (final List<String> row : rows) {
        sb.append(StringUtils.repeat(' ', paddingLeft)).append(String.format(template, row.toArray()))
                .append('\n');
    }/* w  w  w.j  a v  a  2 s .  co  m*/

    return sb.toString();
}

From source file:com.github.mbenson.privileged.weaver.Body.java

private void prepare() {
    if (!lineStarted) {
        lineStarted = true;
        content.append(StringUtils.repeat(indent, level));
    }
}