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:net.openhft.chronicle.logger.log4j1.Log4j1VanillaChroniclePerfTest.java

@Test
public void testSingleThreadLoggin3() 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-async");
    final long items = 1000000;
    final String strFmt = StringUtils.leftPad("> v1={}, v2={}, v3={}", 32, 'X');

    warmup(clogger);//  w w w  .j  ava 2  s. c  o  m
    warmup(plogger);

    for (int n = 0; n < 10; n++) {
        long cStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            clogger.info(strFmt, i, i * 7, i / 16);
        }

        long cEnd1 = System.nanoTime();

        long pStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            plogger.info(strFmt, i, i * 7, i / 16);
        }

        long pEnd1 = System.nanoTime();

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

    IOTools.deleteDir(basePath(testId));
}

From source file:net.openhft.chronicle.logger.log4j2.Log4j2VanillaChroniclePerfTest.java

@Ignore
@Test//from w w w.  j a va 2  s. c  o  m
public void testSingleThreadLoggin3() 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-async");
    final long items = 1000000;
    final String strFmt = StringUtils.leftPad("> v1={}, v2={}, v3={}", 32, 'X');

    warmup(clogger);
    warmup(plogger);

    for (int n = 0; n < 10; n++) {
        long cStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            clogger.info(strFmt, i, i * 7, i / 16);
        }

        long cEnd1 = System.nanoTime();

        long pStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            plogger.info(strFmt, i, i * 7, i / 16);
        }

        long pEnd1 = System.nanoTime();

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

    IOTools.deleteDir(basePath(testId));
}

From source file:net.openhft.chronicle.logger.logback.LogbackIndexedChroniclePerfTest.java

@Test
public void testSingleThreadLogging3() 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-async");
    final long items = 1000000;
    final String strFmt = StringUtils.leftPad("> v1={}, v2={}, v3={}", 32, 'X');

    for (int n = 0; n < 10; n++) {
        long cStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            clogger.info(strFmt, i, i * 10, i / 16);
        }// w w w .j a v  a  2  s .  com

        long cEnd1 = System.nanoTime();

        long pStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            plogger.info(strFmt, i, i * 10, i / 16);
        }

        long pEnd1 = System.nanoTime();

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

    ChronicleTools.deleteOnExit(basePath(testId));
}

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

@Test
public void testSingleThreadLogging3() 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-async");
    final long items = 1000000;
    final String strFmt = StringUtils.leftPad("> v1={}, v2={}, v3={}", 32, 'X');

    warmup(clogger);/*www.  j  a  v a2s  .c om*/
    warmup(plogger);

    for (int n = 0; n < 10; n++) {
        long cStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            clogger.info(strFmt, i, i * 10, i / 16);
        }

        long cEnd1 = System.nanoTime();

        long pStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            plogger.info(strFmt, i, i * 10, i / 16);
        }

        long pEnd1 = System.nanoTime();

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

    ChronicleTools.deleteOnExit(basePath(testId));
}

From source file:net.openhft.chronicle.logger.log4j2.Log4j2IndexedChroniclePerfTest.java

@Ignore
@Test/*www.  jav a  2s  .c  om*/
public void testSingleThreadLogging3() 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-async");
    final long items = 1000000;
    final String strFmt = StringUtils.leftPad("> v1={}, v2={}, v3={}", 32, 'X');

    warmup(clogger);
    warmup(plogger);

    for (int n = 0; n < 10; n++) {
        long cStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            clogger.info(strFmt, i, i * 10, i / 16);
        }

        long cEnd1 = System.nanoTime();

        long pStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            plogger.info(strFmt, i, i * 10, i / 16);
        }

        long pEnd1 = System.nanoTime();

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

    ChronicleTools.deleteOnExit(basePath(testId));
}

From source file:com.netsteadfast.greenstep.action.SystemCalendarNoteManagementAction.java

private void init() throws ServiceException, Exception {
    this.accountMap = this.accountService.findForAllMap(true);
    for (int hour = 0; hour < 24; hour++) {
        String hourStr = StringUtils.leftPad(String.valueOf(hour), 2, "0");
        hourMap.put(hourStr, hourStr);//from  www  .j a  v  a  2 s.co m
    }
    for (int mins = 0; mins < 60; mins++) {
        String minsStr = StringUtils.leftPad(String.valueOf(mins), 2, "0");
        minutesMap.put(minsStr, minsStr);
    }
}

From source file:com.stratio.cassandra.lucene.schema.mapping.BigDecimalMapper.java

/** {@inheritDoc} */
@Override//from  w  w w .j a  v  a2  s  . c o m
protected String doBase(String name, Object value) {

    // Parse big decimal
    BigDecimal bd;
    try {
        bd = new BigDecimal(value.toString());
    } catch (NumberFormatException e) {
        throw new IndexException("Field '%s' requires a base 10 decimal, but found '%s'", name, value);
    }

    // Split integer and decimal part
    bd = bd.stripTrailingZeros();
    String[] parts = bd.toPlainString().split("\\.");
    validateIntegerPart(name, value, parts);
    validateDecimalPart(name, value, parts);

    BigDecimal complemented = bd.add(complement);
    String bds[] = complemented.toString().split("\\.");
    String integerPart = StringUtils.leftPad(bds[0], integerDigits + 1, '0');
    String decimalPart = bds.length == 2 ? bds[1] : "0";

    return integerPart + "." + decimalPart;
}

From source file:de.codecentric.batch.listener.ProtocolListener.java

/**
 * Create line with defined char/*www.j  av a  2s  . co m*/
 * 
 * @param filler
 */
private String createFilledLine(char filler) {
    return StringUtils.leftPad("", DEFAULT_WIDTH, filler) + "\n";
}

From source file:com.netsteadfast.greenstep.service.impl.SysMailHelperServiceImpl.java

@Override
public String findForMaxMailIdComplete(String mailId) throws ServiceException, Exception {
    if (StringUtils.isBlank(mailId) || !SimpleUtils.isDate(mailId)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }/*from ww  w . j  a  v a 2 s. co m*/
    String maxMailId = this.findForMaxMailId(mailId);
    if (StringUtils.isBlank(maxMailId)) {
        return mailId + "000000001";
    }
    int maxSeq = Integer.parseInt(maxMailId.substring(8, 17)) + 1;
    if (maxSeq > 999999999) {
        throw new ServiceException(
                SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS) + " over max mail-id 999999999!");
    }
    return mailId + StringUtils.leftPad(String.valueOf(maxSeq), 9, "0");
}

From source file:com.streamsets.pipeline.kafka.impl.TestKafkaProducer09.java

@Test
public void testKafkaProducer09WriteFailsRecordTooLarge() throws IOException, StageException {

    HashMap<String, Object> kafkaProducerConfigs = new HashMap<>();
    kafkaProducerConfigs.put("retries", 0);
    kafkaProducerConfigs.put("batch.size", 100);
    kafkaProducerConfigs.put("linger.ms", 0);
    // Set the message size to 510 as "message.max.bytes" is set to 500
    final String message = StringUtils.leftPad("a", 510, "b");
    SdcKafkaProducer sdcKafkaProducer = createSdcKafkaProducer(port, kafkaProducerConfigs);
    sdcKafkaProducer.init();//from ww  w . ja va  2 s .c  om
    String topic = getNextTopic();
    sdcKafkaProducer.enqueueMessage(topic, message.getBytes(), "0");
    try {
        sdcKafkaProducer.write();
        fail("Expected exception but didn't get any");
    } catch (StageException se) {
        assertEquals(KafkaErrors.KAFKA_69, se.getErrorCode());
    } catch (Exception e) {
        fail("Expected Stage Exception but got " + e);
    }
}