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

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

Introduction

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

Prototype

public static String repeat(String str, int repeat) 

Source Link

Document

Repeat a String repeat times to form a new String.

Usage

From source file:com.adobe.acs.commons.util.InfoWriterTest.java

@Test
public void testLine_WithIndent() throws Exception {
    String expected = StringUtils.repeat(" ", 10) + StringUtils.repeat("-", 70);

    iw.line(10);//from w ww.j a  v  a 2 s.c o  m

    assertEquals(expected.concat(LS), iw.toString());
}

From source file:adalid.core.expressions.AbstractComparisonX.java

@Override
protected String fieldsToString(int n, String key, boolean verbose, boolean fields, boolean maps) {
    String tab = verbose ? StringUtils.repeat(" ", 4) : "";
    String fee = verbose ? StringUtils.repeat(tab, n) : "";
    String faa = " = ";
    String foo = verbose ? EOL : ", ";
    String string = super.fieldsToString(n, key, verbose, fields, maps);
    Expression e;//w  w  w  . j a v  a2s.co m
    if (fields || verbose) {
        if (verbose) {
            string += fee + tab + "operator" + faa + _operator + foo;
            if (_x != null) {
                if (_x instanceof NaryExpression) {
                    e = (Expression) _x;
                    string += e.toString(n + 1, "x", verbose, fields, maps);
                } else {
                    string += fee + tab + "x" + faa + getValueString(_x) + foo;
                }
            }
            if (_y != null) {
                if (_y instanceof NaryExpression) {
                    e = (Expression) _y;
                    string += e.toString(n + 1, "y", verbose, fields, maps);
                } else {
                    string += fee + tab + "y" + faa + getValueString(_y) + foo;
                }
            }
        }
    }
    return string;
}

From source file:com.cloudbees.plugins.credentials.cli.ListCredentialsCommand.java

/**
 * {@inheritDoc}//  w w w  . ja  v  a2  s .  c o m
 */
@Override
protected int run() throws Exception {
    store.checkPermission(CredentialsProvider.VIEW);
    List<Domain> domains = store.getDomains();
    for (Domain domain : domains) {
        List<Credentials> credentials = store.getCredentials(domain);
        Map<String, String> nameById = new LinkedHashMap<String, String>(credentials.size());
        int maxIdLen = "# of Credentials".length(), maxNameLen = 0;
        int index = 0;
        for (Credentials c : credentials) {
            String id;
            if (c instanceof IdCredentials) {
                id = ((IdCredentials) c).getId();
            } else {
                while (nameById.containsKey("index-" + index)) {
                    index++;
                }
                id = "index-" + index;
                index++;
            }
            String name = CredentialsNameProvider.name(c);
            nameById.put(id, name);
            maxIdLen = Math.max(maxIdLen, id.length());
            maxNameLen = Math.max(maxNameLen, name.length());
        }
        stdout.println(StringUtils.repeat("=", maxIdLen + maxNameLen + 1));
        stdout.println(StringUtils.rightPad("Domain", maxIdLen) + " "
                + (domain.isGlobal() ? "(global)" : domain.getName()));
        stdout.println(StringUtils.rightPad("Description", maxIdLen) + " "
                + StringUtils.defaultString(domain.getDescription()));
        stdout.println(StringUtils.rightPad("# of Credentials", maxIdLen) + " " + credentials.size());
        stdout.println(StringUtils.repeat("=", maxIdLen + maxNameLen + 1));
        stdout.println(StringUtils.rightPad("Id", maxIdLen) + " Name");
        stdout.println(StringUtils.repeat("=", maxIdLen) + " " + StringUtils.repeat("=", maxNameLen));
        for (Map.Entry<String, String> entry : nameById.entrySet()) {
            stdout.println(StringUtils.rightPad(entry.getKey(), maxIdLen) + " " + entry.getValue());
        }
        stdout.println(StringUtils.repeat("=", maxIdLen + maxNameLen + 1));
        stdout.println();
    }
    return 0;
}

From source file:adalid.core.expressions.AbstractDataAggregateX.java

@Override
protected String mapsToString(int n, String key, boolean verbose, boolean fields, boolean maps) {
    String tab = verbose ? StringUtils.repeat(" ", 4) : "";
    String fee = verbose ? StringUtils.repeat(tab, n) : "";
    String faa = " = ";
    String foo = verbose ? EOL : ", ";
    String string = super.mapsToString(n, key, verbose, fields, maps);
    if (maps || verbose) {
        if (_operands != null) {
            for (int i = 0; i < _operands.length; i++) {
                String clave = "operands" + "_" + i;
                if (_operands[i] instanceof NaryExpression) {
                    Expression valor = (Expression) _operands[i];
                    string += valor.toString(n + 1, clave, verbose, fields, maps);
                } else {
                    string += fee + tab + clave + faa + getValueString(_operands[i]) + foo;
                }/*  w  ww.jav a 2 s . c  o  m*/
            }
        }
    }
    return string;
}

From source file:com.adobe.acs.commons.util.InfoWriter.java

/**
 * Creates an indented (with whitespace) line.
 * @param indent number of spaces to indent the line
 *///ww  w  . ja  v  a2 s.  co  m
public void line(int indent) {
    if (indent < 0) {
        indent = 0;
    }

    pw.println(StringUtils.repeat(" ", indent) + StringUtils.repeat(LINE_CHAR, LINE_LENGTH - indent));
}

From source file:de.pellepelster.ant.statistics.AsciiTable.java

private void createRow(Map<Integer, Integer> maxColumnWidths, String[] row, StringBuffer result) {

    result.append(HORIZONTAL_TABLE_BORDER);
    for (int columnIndex = 0; columnIndex < row.length; columnIndex++) {
        String cellText = row[columnIndex];

        result.append(StringUtils.repeat(" ", HORIZONTAL_CELLPADDING));
        result.append(StringUtils.center(cellText, maxColumnWidths.get(columnIndex)));
        result.append(StringUtils.repeat(" ", HORIZONTAL_CELLPADDING));

        if (columnIndex < headers.length - 1) {
            result.append(HORIZONTAL_TABLE_BORDER);
        }//  w  ww  .  ja va  2  s. c  o  m

    }
    result.append(HORIZONTAL_TABLE_BORDER);
    result.append(NEWLINE);
}

From source file:de.codesourcery.luaparser.LuaToJSON.java

public static String toErrorString(String input, int errorPosition, String msg) {
    final String lines[] = input.split("\n");

    String line = lines[0];//  w w w. j  av a 2 s . c o m
    int currentLineStart = 0;
    int lineNo = 0;
    while (lineNo < lines.length) {
        line = lines[lineNo];
        if (currentLineStart + line.length() + 1 >= errorPosition) {
            break;
        }
        line = lines[lineNo++];
        currentLineStart += line.length() + 1;
    }

    final int offsetInLine = errorPosition - currentLineStart;
    final String indent = StringUtils.repeat(" ", offsetInLine);
    String result = "";
    for (int start = lineNo - 5; start < lineNo; start++) {
        if (start >= 0) {
            result += lines[start] + "\n";
        }
    }
    return "\nLine " + (lineNo + 1) + ", col " + (offsetInLine + 1) + ", offset " + errorPosition + ":\n"
            + result + line + "\n" + indent + "^ " + msg;
}

From source file:com.pcb.pcbridge.listeners.OnPlayerAsyncChatEvent.java

/**
 * Send a filtered message to anyone with swearblock enabled
 * // www .j  ava  2  s. c o  m
 * @param event
 */
private void FilterSwearing(AsyncPlayerChatEvent event) {
    if (event.isCancelled())
        return;

    StaticCache<UUID, PlayerConfig> cache = GetEnv().GetPlayerCache();
    PlayerConfig senderConfig = cache.Get(event.getPlayer().getUniqueId());

    Matcher matcher = _pattern.matcher(event.getMessage());
    if (matcher.find()) {
        // only swearblock activated players need to see filtered messages,
        // so we have to handle filtering on a per-player basis

        String caught = matcher.group();
        String stars = StringUtils.repeat("*", caught.length());
        String edited = event.getMessage().replace(caught, stars);

        for (Player player : event.getRecipients()) {
            PlayerConfig config = cache.Get(player.getUniqueId());
            if (config.IsSwearblockEnabled)
                player.sendMessage(FormatMessage(event.getPlayer(), senderConfig, edited));
            else
                player.sendMessage(FormatMessage(event.getPlayer(), senderConfig, event.getMessage()));
        }

        event.setCancelled(true);

        // manually log the message or else it won't show up in console anymore
        GetEnv().GetLogger().info("FILTERED: " + event.getMessage());
    } else {
        event.getRecipients().forEach(player -> {
            player.sendMessage(FormatMessage(event.getPlayer(), senderConfig, event.getMessage()));
        });
        event.setCancelled(true);
    }

    // a player's Tab list name changes everytime they chat, so we need to
    // rebuild their name again
    GetEnv().BroadcastEvent(new PlayerNameChangedEvent(event.getPlayer()));
}

From source file:de.Keyle.MyPet.util.Updater.java

private void notifyVersion() {
    String m = "#  A new ";
    m += MyPetVersion.isDevBuild() ? "build" : "version";
    m += " is available: " + latest + " #";
    MyPetApi.getLogger().info(StringUtils.repeat("#", m.length()));
    MyPetApi.getLogger().info(m);/*from   w  w w .ja v  a2  s. co  m*/
    MyPetApi.getLogger()
            .info("#  https://mypet-plugin.de/download" + StringUtils.repeat(" ", m.length() - 35) + "#");
    MyPetApi.getLogger().info(StringUtils.repeat("#", m.length()));
}

From source file:com.adobe.acs.commons.util.InfoWriterTest.java

@Test
public void testGetInfo() throws Exception {
    final String expected = LS + StringUtils.repeat("-", 80) + LS + "Info Title" + LS
            + StringUtils.repeat("=", 80) + LS + "This is line 1" + LS + "This is line 2" + LS
            + StringUtils.repeat("-", 80) + LS;

    iw.title("Info Title");
    iw.message("This is line 1");
    iw.message("This is line 2");
    iw.end();/*from  w  w  w.  j  av  a2  s.  com*/

    assertEquals(expected, iw.toString());
}