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

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

Introduction

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

Prototype

public static String leftPad(final String str, final int size, String padStr) 

Source Link

Document

Left pad a String with a specified String.

Pad to a size of size .

 StringUtils.leftPad(null, *, *)      = null StringUtils.leftPad("", 3, "z")      = "zzz" StringUtils.leftPad("bat", 3, "yz")  = "bat" StringUtils.leftPad("bat", 5, "yz")  = "yzbat" StringUtils.leftPad("bat", 8, "yz")  = "yzyzybat" StringUtils.leftPad("bat", 1, "yz")  = "bat" StringUtils.leftPad("bat", -1, "yz") = "bat" StringUtils.leftPad("bat", 5, null)  = "  bat" StringUtils.leftPad("bat", 5, "")    = "  bat" 

Usage

From source file:com.thruzero.common.core.support.Time.java

@Override
public String toString() {
    return StringUtils.leftPad(Byte.toString(hours), 2, "0") + ":"
            + StringUtils.leftPad(Byte.toString(minutes), 2, "0");
}

From source file:com.daraf.projectdarafprotocol.appdb.ingresos.IngresoFacturaRQ.java

public void setNumeroDetalles(String numeroDetalles) {
    this.numeroDetalles = StringUtils.leftPad(numeroDetalles, 4, "0");
}

From source file:com.kurniakue.telebot.admin.ItemsHandler.java

private boolean displayItems(List<Item> list) {
    Replier replier = getReplier();/*from w  w w  . ja v a  2s.  co m*/

    int count = 0;
    for (Item item : list) {
        count += 1;
        String strCount = StringUtils.leftPad(count + ". ", 5, "0");
        final String itemName = item.getString(Item.F.ItemName);
        replier.addLine(strCount).add("/").add(item.getString(Item.F.ItemNo)).add("-").add(itemName).add(": ");
        long price = item.getLong(Item.F.Price);
        replier.add(Tool.formatMoney(price));
    }

    replier.keyboard(C.Home.cmd, cmd_all_items.getCmd(), cmd_products.getCmd());
    replier.send();

    return true;
}

From source file:com.github.bjoern2.codegen.StringGenerator.java

@Override
public Generator writeLines(String content, String prefix, String postfix, int tabs) {
    String[] lines = content.split("\\r?\\n");
    for (String line : lines) {
        write(StringUtils.leftPad("", tabs, "\t") + prefix + line + postfix + "\n");
    }/*from   w w  w .  j a  va2s.  c  o m*/
    return this;
}

From source file:com.github.robozonky.strategy.natural.conditions.AverageStoryConditionTest.java

@Test
void shorterNotOk() {
    final Wrapper<?> l = mock(Wrapper.class);
    final String story = StringUtils.leftPad("", AbstractStoryCondition.SHORT_STORY_THRESHOLD - 1, '*');
    when(l.getStory()).thenReturn(story);
    assertThat(new AverageStoryCondition().test(l)).isFalse();
}

From source file:net.openhft.chronicle.logger.log4j1.Log4j1VanillaChroniclePerfTest.java

@Test
public void testSingleThreadLogging1() throws IOException {
    Thread.currentThread().setName("perf-plain-vanilla");

    final String testId = "perf-binary-vanilla-chronicle";
    final Logger clogger = LoggerFactory.getLogger(testId);
    final Logger plogger = LoggerFactory.getLogger("perf-plain-vanilla");
    final long items = 1000000;

    warmup(clogger);/* w w  w .  j a  v  a  2 s . c om*/
    warmup(plogger);

    for (int s = 64; s <= 1024; s += 64) {
        final String staticStr = StringUtils.leftPad("", s, 'X');

        long cStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            clogger.info(staticStr);
        }

        long cEnd1 = System.nanoTime();

        long pStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            plogger.info(staticStr);
        }

        long pEnd1 = System.nanoTime();

        System.out.printf(
                "items=%03d size=%04d => chronology=%.3f ms, chronology-average=%.3f us, plain=%d, plain-average=%.3f us\n",
                items, staticStr.length(), (cEnd1 - cStart1) / 1e6, (cEnd1 - cStart1) / items / 1e3,
                (pEnd1 - pStart1), (pEnd1 - pStart1) / items / 1e3);
    }

    IOTools.deleteDir(basePath(testId));
}

From source file:de.upb.wdqa.wdvd.revisiontags.SHA1Converter.java

private static String getBase(int base, byte[] bytes) {
    String result;//w w w .ja v a2  s.c  o  m

    if (bytes != null) {
        if (bytes.length != 0) {
            BigInteger bi = new BigInteger(1, bytes);
            String tmp = bi.toString(base);

            int numberOfDigits = (int) Math.ceil(160.0 / (Math.log(base) / Math.log(2.0)));

            result = StringUtils.leftPad(tmp, numberOfDigits, '0');
        } else {
            result = "";
        }
    } else {
        result = null;
    }

    return result;
}

From source file:net.openhft.chronicle.logger.log4j1.Log4j1IndexedChroniclePerfTest.java

@Test
public void testSingleThreadLogging1() throws IOException {
    Thread.currentThread().setName("perf-plain-indexed");

    final String testId = "perf-binary-indexed-chronicle";
    final Logger clogger = LoggerFactory.getLogger(testId);
    final Logger plogger = LoggerFactory.getLogger("perf-plain-indexed");
    final long items = 1000000;

    warmup(clogger);/*from  w  w  w. j  av  a 2s  .co m*/
    warmup(plogger);

    for (int s = 64; s <= 1024; s += 64) {
        final String staticStr = StringUtils.leftPad("", s, 'X');

        long cStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            clogger.info(staticStr);
        }

        long cEnd1 = System.nanoTime();

        long pStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            plogger.info(staticStr);
        }

        long pEnd1 = System.nanoTime();

        System.out.printf(
                "items=%03d size=%04d => chronology=%.3f ms, chronology-average=%.3f us, plain=%d, plain-average=%.3f us\n",
                items, staticStr.length(), (cEnd1 - cStart1) / 1e6, (cEnd1 - cStart1) / items / 1e3,
                (pEnd1 - pStart1), (pEnd1 - pStart1) / items / 1e3);
    }

    ChronicleTools.deleteOnExit(basePath(testId));
}

From source file:br.com.binarti.simplesearchexpr.converter.StringNumericSearchDataConverter.java

@Override
protected Object asSingleObject(SimpleSearchExpressionField field, String value, Map<String, Object> params,
        Class<?> targetType) {
    if (value == null)
        return null;
    value = value.replaceAll("\\D", "");
    if (params != null && params.containsKey(PARAM_SIZE)) {
        int size = (Integer) params.get(PARAM_SIZE);
        return StringUtils.leftPad(value, size, FILL_CHAR);
    }//from w w w.jav a 2 s  .  c  o  m
    return value;
}

From source file:me.j360.idgen.impl.strategy.MixPrefixStrategy.java

/**
 * convert original id to a new id which apply a specific assembling rule
 * //www  .  j a  v  a2  s .  c  o  m
 * @param originalId
 *            original id to be converted
  * @param clazz
 *          class information that call ID generation service.
 * @return assembled id
 */
public String makeId(String originalId, Class<?> clazz) {
    return prefix + StringUtils.leftPad(originalId, maxCiphers, paddingChar);
}