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

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

Introduction

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

Prototype

public static String rightPad(String str, int size, String padStr) 

Source Link

Document

Right pad a String with a specified String.

Usage

From source file:nz.co.senanque.schemaparser.restrictions.StringGenerator.java

public static String getString(int l) {
    String ll = Integer.toString(l);
    if (l > ll.length()) {
        String ret = StringUtils.rightPad(ll, l - ll.length(), '.');
        return ret;
    }// w  w  w.j a  v a  2s . c  o m
    String ret = StringUtils.rightPad("", l, '.');
    return ret;
}

From source file:nz.co.senanque.schemaparser.restrictions.TotalDigits.java

public List<CandidateValue> getCandidateValues() {
    if (candidateValues.isEmpty()) {
        candidateValues.add(new CandidateValue(StringUtils.rightPad("9", value + 1, '.'), false, this));
        candidateValues.add(new CandidateValue(StringUtils.rightPad("9", value, '.'), true, this));
    }//from w  ww .j  a v a 2  s .  co m
    return candidateValues;
}

From source file:org.apache.jmeter.protocol.irc.client.IrcBotSampler.java

public void init() {
    //Pad nick with 0s to generate a unique botName
    thisNick = getPropertyAsString(botPrefix) + botNumber;
    thisNick = StringUtils.rightPad(thisNick, getPropertyAsString(botPrefix).length() + 9, "0");

    //Setup possible response list
    List<Set<String>> responseGroups = new ArrayList();
    if (getPropertyAsBoolean(channelCommand))
        responseGroups.add(generateResponseSet(":${thisHostmask} PRIVMSG ${channel} :${command} ${thisNick}"));
    if (getPropertyAsBoolean(PMCommand))
        responseGroups/*w  w w .  jav a  2 s .  c  o  m*/
                .add(generateResponseSet(":${thisHostmask} PRIVMSG ${targetNick} :${command} ${thisNick}"));
    if (getPropertyAsBoolean(channelMessage))
        responseGroups.add(generateResponseSet(":${thisHostmask} PRIVMSG ${channel} :${thisNick}"));
    if (getPropertyAsBoolean(channelAction))
        responseGroups.add(
                generateResponseSet(":${thisHostmask} PRIVMSG ${channel} :\u0001ACTION ${thisNick}\u0001"));
    if (getPropertyAsBoolean(channelNotice))
        responseGroups.add(generateResponseSet(":${thisHostmask} NOTICE ${channel} :${thisNick}"));
    if (getPropertyAsBoolean(PMMessage))
        responseGroups.add(generateResponseSet(":${thisHostmask} PRIVMSG ${targetNick} :${thisNick}"));
    if (getPropertyAsBoolean(PMAction))
        responseGroups.add(
                generateResponseSet(":${thisHostmask} PRIVMSG ${targetNick} :\u0001ACTION ${thisNick}\u0001"));
    if (getPropertyAsBoolean(operatorOp))
        responseGroups.add(generateResponseSet(":${thisHostmask} MODE ${channel} +o ${thisNick}",
                ":${thisHostmask} MODE ${channel} -o ${thisNick}"));
    if (getPropertyAsBoolean(operatorVoice))
        responseGroups.add(generateResponseSet(":${thisHostmask} MODE ${channel} +v ${thisNick}",
                ":${thisHostmask} MODE ${channel} -v ${thisNick}"));
    if (getPropertyAsBoolean(operatorKick))
        responseGroups.add(generateResponseSet(":${thisHostmask} KICK ${channel} ${targetNick}: ${thisNick}",
                ":${thisHostmask} JOIN :${channel}"));
    if (getPropertyAsBoolean(operatorBan))
        responseGroups.add(generateResponseSet(":${thisHostmask} MODE ${channel} +b ${thisNick}!*@*",
                ":${thisHostmask} MODE ${channel} -b ${thisNick}!*@*"));
    if (getPropertyAsBoolean(userPart))
        responseGroups.add(
                generateResponseSet(":${thisHostmask} PART ${channel}", ":${thisHostmask} JOIN :${channel}"));
    if (getPropertyAsBoolean(userQuit))
        responseGroups.add(
                generateResponseSet(":${thisHostmask} QUIT :${thisNick}", ":${thisHostmask} JOIN :${channel}"));

    //Randomly shuffle responses and compact response to a single response queue
    Collections.shuffle(responseGroups);
    for (Set<String> curGroup : responseGroups)
        for (String curResponse : curGroup)
            responseItems.add(curResponse);
}

From source file:org.apache.oodt.cas.filemgr.structs.type.examples.MajorMinorVersionTypeHandler.java

@Override
protected String getCatalogValue(String origValue) {
    String[] origValueSplit = origValue.split("\\.");
    String majorVersion = origValueSplit[0];
    String minorVersion = origValueSplit[1];
    return StringUtils.leftPad(majorVersion, 2, "0") + "." + StringUtils.rightPad(minorVersion, 2, "0");
}

From source file:org.apache.phoenix.end2end.index.IndexExpressionIT.java

private void verifyResult(ResultSet rs, int i) throws SQLException {
    assertTrue(rs.next());//from ww w. j  a  v a2s. co m
    assertEquals("VARCHAR" + String.valueOf(i) + "_" + StringUtils.rightPad("CHAR" + String.valueOf(i), 6, ' ')
            + "_A.VARCHAR" + String.valueOf(i) + "_"
            + StringUtils.rightPad("B.CHAR" + String.valueOf(i), 10, ' '), rs.getString(1));
    assertEquals(i * 3, rs.getInt(2));
    Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i) * NUM_MILLIS_IN_DAY);
    assertEquals(date, rs.getDate(3));
    assertEquals(date, rs.getDate(4));
    assertEquals(date, rs.getDate(5));
    assertEquals("varchar" + String.valueOf(i), rs.getString(6));
    assertEquals("char" + String.valueOf(i), rs.getString(7));
    assertEquals(i, rs.getInt(8));
    assertEquals(i, rs.getLong(9));
    assertEquals(i * 0.5d, rs.getDouble(10), 0.000001);
    assertEquals(i, rs.getLong(11));
    assertEquals(i, rs.getLong(12));
}

From source file:org.apache.rya.accumulo.mr.merge.util.AccumuloRyaUtils.java

/**
 * Prints the table with pretty formatting using the specified config and additional settings.
 * @param tableName the name of the table to print.
 * @param config the {@link AccumuloRdfConfiguration}.
 * @param shouldAddCommonIterators {@code true} to add the common iterators to the table scanner.
 * {@code false} otherwise.//from   www.  j a va  2s.c  om
 * @param settings the additional {@link IteratorSetting}s to add besides the common ones.
 * @throws IOException
 */
public static void printTablePretty(final String tableName, final Configuration config,
        final boolean shouldAddCommonIterators, final IteratorSetting... settings)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException {
    final Scanner scanner = AccumuloRyaUtils.getScanner(tableName, config, shouldAddCommonIterators);
    for (final IteratorSetting setting : settings) {
        scanner.addScanIterator(setting);
    }

    final String format = "| %-64s | %-24s | %-28s | %-20s | %-20s | %-10s |";
    final int totalFormatLength = String.format(format, 1, 2, 3, 4, 5, 6).length();
    final String instance = config.get(MRUtils.AC_INSTANCE_PROP);
    log.info(StringUtils.rightPad("==================", totalFormatLength, "="));
    log.info(StringUtils.rightPad("| TABLE: " + tableName + " INSTANCE: " + instance, totalFormatLength - 1)
            + "|");
    log.info(StringUtils.rightPad("------------------", totalFormatLength, "-"));
    log.info(String.format(format, "--Row--", "--ColumnVisibility--", "--Timestamp--", "--ColumnFamily--",
            "--ColumnQualifier--", "--Value--"));
    log.info(StringUtils.rightPad("|-----------------", totalFormatLength - 1, "-") + "|");
    for (final Entry<Key, Value> entry : scanner) {
        final Key k = entry.getKey();
        final String rowString = Key.appendPrintableString(k.getRow().getBytes(), 0, k.getRow().getLength(),
                Constants.MAX_DATA_TO_PRINT, new StringBuilder()).toString();
        log.info(String.format(format, rowString, k.getColumnVisibility(), new Date(k.getTimestamp()),
                k.getColumnFamily(), k.getColumnQualifier(), entry.getValue()));
    }
    log.info(StringUtils.rightPad("==================", totalFormatLength, "="));
}

From source file:org.apache.servicecomb.demo.edge.business.Impl.java

@RequestMapping(path = "/channel/news/subscribe", method = RequestMethod.POST)
public AppClientDataRsp subscribeNewsColumn(@RequestBody ChannelRequestBase request) {
    AppClientDataRsp response = new AppClientDataRsp();
    String rsp = StringUtils.rightPad("edge test", 1024, "*");
    response.setRsp(rsp);//from   w w  w  .jav a  2  s.  c  om
    return response;
}

From source file:org.apache.sqoop.shell.utils.TableDisplayer.java

/**
 * Display given columns in nice table structure to given IO object.
 *
 * @param headers List of headers/* w  ww .ja  v a 2s .co m*/
 * @param columns Array of columns
 */
public static void display(List<String> headers, List<String>... columns) {
    assert headers != null;
    assert columns != null;
    assert headers.size() == columns.length;

    // Count of columns
    int columnCount = headers.size();

    // List of all maximal widths of each column
    List<Integer> widths = new LinkedList<Integer>();
    for (int i = 0; i < columnCount; i++) {
        widths.add(getMaximalWidth(headers.get(i), columns[i]));
    }

    // First line is border
    drawLine(widths);

    // Print out header (text is centralised)
    print("| ");
    for (int i = 0; i < columnCount; i++) {
        print(StringUtils.center(headers.get(i), widths.get(i), ' '));
        print((i == columnCount - 1) ? " |" : " | ");
    }
    println();

    // End up header by border
    drawLine(widths);

    // Number of rows in the table
    int rows = getMaximalRows(columns);

    // Print out each row
    for (int row = 0; row < rows; row++) {
        print("| ");
        for (int i = 0; i < columnCount; i++) {
            print(StringUtils.rightPad(columns[i].get(row), widths.get(i), ' '));
            print((i == columnCount - 1) ? " |" : " | ");
        }
        println();
    }

    // End table by final border
    drawLine(widths);
}

From source file:org.apache.tajo.engine.function.string.Rpad.java

@Override
public Datum eval(Tuple params) {
    if (params.isBlankOrNull(0) || params.isBlankOrNull(1)) {
        return NullDatum.get();
    }/*from  w  w  w  . j a v a 2 s  . c  o  m*/

    String fillText;
    if (hasFillCharacters) {
        fillText = params.getText(2);
    } else {
        fillText = " ";
    }

    String input = params.getText(0);
    int expected = params.getInt4(1);

    int templen = expected - params.size(0);

    if (templen <= 0) {
        return DatumFactory.createText(input.substring(0, expected));
    }

    return DatumFactory.createText(StringUtils.rightPad(input, expected, fillText));
}

From source file:org.apache.tajo.storage.regex.RegexLineSerializer.java

private String convertToString(int columnIndex, Tuple tuple, String nullChars) throws IOException {

    Column col = schema.getColumn(columnIndex);
    TajoDataTypes.DataType dataType = col.getDataType();

    if (tuple.isBlankOrNull(columnIndex)) {
        switch (dataType.getType()) {
        case CHAR:
        case TEXT:
            return nullChars;
        default:/*from  w w w  . j  a  v a  2s .com*/
            return StringUtils.EMPTY;
        }
    }

    switch (dataType.getType()) {
    case BOOLEAN:
        return tuple.getBool(columnIndex) ? "true" : "false";
    case CHAR:
        int size = dataType.getLength() - tuple.size(columnIndex);
        if (size < 0) {
            throw new ValueTooLongForTypeCharactersException(dataType.getLength());
        }

        return StringUtils.rightPad(tuple.getText(columnIndex), size, "");
    case TEXT:
    case BIT:
    case INT2:
    case INT4:
    case INT8:
    case FLOAT4:
    case FLOAT8:
    case DATE:
    case INTERVAL:
    case TIME:
        return tuple.getText(columnIndex);
    case TIMESTAMP:
        // UTC to table timezone
        return TimestampDatum.asChars(tuple.getTimeDate(columnIndex), tableTimezone, false);
    case BLOB:
        return Base64.encodeBase64String(tuple.getBytes(columnIndex));
    case PROTOBUF:
        ProtobufDatum protobuf = (ProtobufDatum) tuple.getProtobufDatum(columnIndex);
        return protobufJsonFormat.printToString(protobuf.get());
    case NULL_TYPE:
    default:
        return StringUtils.EMPTY;
    }
}