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.adobe.acs.commons.httpcache.store.jcr.impl.writer.BucketNodeFactory.java

private String[] getPathArray() {
    final String hashCodeString = StringUtils.leftPad(String.valueOf(key.hashCode()), (int) HASHCODE_LENGTH,
            "0");

    int increment = (int) Math.ceil(HASHCODE_LENGTH / cacheKeySplitDepth);
    final String[] pathArray = new String[cacheKeySplitDepth];

    for (int position = 0, i = 0; i < (cacheKeySplitDepth); position += increment, i++) {
        int endIndex = (position + increment > hashCodeString.length()) ? hashCodeString.length()
                : position + increment;// w  w  w .  j  a  va2 s  .co m
        String nodeName = StringUtils.leftPad(hashCodeString.substring(position, endIndex), 5, "0");
        pathArray[i] = nodeName;
    }
    return pathArray;
}

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

/**
 * get Id after fill padding character.// w w w  . j a v  a  2  s  .  c  o m
 * 
 * @param originalId
 *            original id to be padded.
 * @return padded id
 */
protected String getPaddedId(String originalId) {
    String paddingId = StringUtils.leftPad(originalId, maxCiphers, paddingChar);

    if (!ignoreMaxCiphers && paddingId.length() > maxCiphers) {
        throw new IdCreationException("[IDGeneration Service] ID cannot be have length more than maxCiphers.");
    }
    return paddingId;
}

From source file:com.ppcxy.cyfm.showcase.demos.utilities.string.ApacheStringUtilsDemo.java

@Test
public void otherUtils() {
    // ignoreCase:contains/startWith/EndWith/indexOf/lastIndexOf
    assertThat(StringUtils.containsIgnoreCase("Aaabbb", "aaa")).isTrue();
    assertThat(StringUtils.indexOfIgnoreCase("Aaabbb", "aaa")).isEqualTo(0);

    // 0//from w  w  w. jav  a2s. c  o m
    assertThat(StringUtils.leftPad("1", 3, '0')).isEqualTo("001");
    assertThat(StringUtils.leftPad("12", 3, '0')).isEqualTo("012");

    // ???
    assertThat(StringUtils.abbreviate("abcdefg", 7)).isEqualTo("abcdefg");
    assertThat(StringUtils.abbreviate("abcdefg", 6)).isEqualTo("abc...");

    // ?/?
    assertThat(StringUtils.capitalize("abc")).isEqualTo("Abc");
    assertThat(StringUtils.uncapitalize("Abc")).isEqualTo("abc");
}

From source file:gov.ca.cwds.cals.util.PlacementHomeUtil.java

/**
 * Adds leading zeroes to make sure licence number is of 9 digits.
 *//*from w  ww  .j a  va  2 s.  c o m*/
public static String normalizeLicenseNumber(String facilityNumber) {
    return StringUtils.leftPad(facilityNumber.trim(), 9, '0');
}

From source file:com.stefanbrenner.droplet.service.impl.SimpleMessageProtocol.java

@Override
public String createSetMessage(final IDroplet droplet) {
    String message = "set"; //$NON-NLS-1$

    IValve valve1 = droplet.getDevices(IValve.class).get(0);

    IDurationAction action1 = (IDurationAction) valve1.getActions().get(0);

    int dur1 = action1.getDuration();

    IDurationAction action2 = (IDurationAction) valve1.getActions().get(1);

    int del1 = Math.abs(action2.getOffset() - action1.getOffset());
    int dur2 = action2.getDuration();

    IDurationAction action3 = (IDurationAction) valve1.getActions().get(2);

    int del2 = Math.abs(action3.getOffset() - action2.getOffset());
    int dur3 = action3.getDuration();

    int delCam = Math.abs(
            droplet.getDevices(ICamera.class).get(0).getActions().get(0).getOffset() - action3.getOffset());

    message += StringUtils.leftPad(String.valueOf(dur1), 3, "0"); //$NON-NLS-1$
    message += StringUtils.leftPad(String.valueOf(del1), 3, "0"); //$NON-NLS-1$
    message += StringUtils.leftPad(String.valueOf(dur2), 3, "0"); //$NON-NLS-1$
    message += StringUtils.leftPad(String.valueOf(del2), 3, "0"); //$NON-NLS-1$
    message += StringUtils.leftPad(String.valueOf(dur3), 3, "0"); //$NON-NLS-1$
    message += StringUtils.leftPad(String.valueOf(delCam), 3, "0"); //$NON-NLS-1$

    return message + "\n"; //$NON-NLS-1$
}

From source file:com.shadows.hkprogrammer.core.MessageHandler.java

private void WritePayloadOfParameterMessage(ParameterMessage message, ByteArray messageBytes) {
    ByteArray payload = new ByteArray(65);
    String Model = Integer.toBinaryString(message.getTXModelType().getValue()),
            Craft = Integer.toBinaryString(message.getCraftTypeNum().getValue());
    payload.Write(Integer.parseInt(StringUtils.leftPad(Model, 4, "0") + StringUtils.leftPad(Craft, 4, "0"), 2));
    String Bitmask = "";
    for (Boolean reverse : message.getReverseBitmask())
        Bitmask = (reverse ? 1 : 0) + Bitmask;
    Bitmask = "00" + Bitmask;
    payload.Write((byte) Integer.parseInt(Bitmask, 2));
    for (ParameterDRValue DRValue : message.getDRValues()) {
        payload.Write((byte) DRValue.getOnValue());
        payload.Write((byte) DRValue.getOffValue());
    }//from   w w  w .j  av  a  2s  .  com
    for (int Swash : message.getSwash())
        payload.Write((byte) Swash);
    for (PotmeterEndPoint Endpoint : message.getEndPoints()) {
        payload.Write((byte) Endpoint.getLeft());
        payload.Write((byte) Endpoint.getRigth());
    }
    for (ThrottleCurve Curve : message.getThrottleCurves()) {
        payload.Write((byte) Curve.getNormal());
        payload.Write((byte) Curve.getID());
    }
    for (PitchCurve Curve : message.getPitchCurves()) {
        payload.Write((byte) Curve.getNormal());
        payload.Write((byte) Curve.getID());
    }
    for (int Subtrim : message.getSubtrim())
        payload.Write((byte) Subtrim);
    for (MixSetting Mix : message.getMixes()) {
        String Source = Integer.toBinaryString(Mix.getSource().getValue()),
                Destination = Integer.toBinaryString(Mix.getDestination().getValue());
        payload.Write((byte) Integer
                .parseInt(StringUtils.leftPad(Source, 4, "0") + StringUtils.leftPad(Destination, 4, "0"), 2));
        payload.Write((byte) Mix.getUprate());
        payload.Write((byte) Mix.getDownrate());
        payload.Write((byte) Mix.getSwitch().getValue());
    }
    for (SwitchFunction Switch : message.getSwitchFunction())
        payload.Write((byte) Switch.getValue());
    for (VRFunction VR : message.getVRModes())
        payload.Write((byte) VR.getValue());
    messageBytes.Write(payload);
    messageBytes.Write(payload.ChecksumBySB());
}

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

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

    warmup(clogger);/* w  ww. j  a  v a2 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.log4j1.Log4j1IndexedChroniclePerfTest.java

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

    warmup(clogger);/*  w w w . j  a v a 2  s .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.slf4j.Slf4jVanillaChronicleBinaryLoggerPerfTest.java

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

    final String testId = "perf-binary-vanilla-chronicle";
    final Logger clogger = LoggerFactory.getLogger(testId);
    final long items = 1000000;
    final String strFmt = StringUtils.leftPad("> v1={}, v2={}, v3={}", 32, 'X');

    warmup(clogger);// ww w .  j ava2s. c  o  m

    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();

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

    ChronicleTools.deleteOnExit(basePath(testId));
}

From source file:net.openhft.chronicle.logger.slf4j.Slf4jIndexedChronicleBinaryLoggerPerfTest.java

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

    final String testId = "perf-binary-indexed-chronicle";
    final Logger clogger = LoggerFactory.getLogger(testId);
    final long items = 1000000;
    final String strFmt = StringUtils.leftPad("> v1={}, v2={}, v3={}", 32, 'X');

    warmup(clogger);// www  . ja v  a 2 s  . co  m

    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();

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

    ChronicleTools.deleteOnExit(basePath(testId));
}