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.github.bjoern2.codegen.StringGenerator.java

public void writeLn(int tabs, String prefix, String content, String postfix) {
    if (content == null) {
        return;/*from w  w  w . j  a  v  a 2s .c om*/
    }

    String[] lines = content.split("\\r?\\n");
    for (String line : lines) {
        write(StringUtils.leftPad("", tabs, "\t") + prefix + line + postfix + "\n");
    }
}

From source file:kenh.expl.functions.LeftPad.java

public String process(String str, int size, String padStr) {
    return StringUtils.leftPad(str, size, padStr);
}

From source file:jhc.redsniff.internal.util.IndentingDescription.java

private String indentedNewLine() {
    return "\n" + StringUtils.leftPad("", indentLevel, "\t");
}

From source file:com.espe.distribuidas.protocolocajero.operaciones.DepositoRS.java

@Override
public String asTexto() {
    StringBuilder sb = new StringBuilder();
    sb.append(this.resultado);
    if (this.resultado.equals(DepositoRS.DEPOSITO_EXITOSO)) {
        sb.append(StringUtils.leftPad(Double.toString(this.saldoActual), 10, "0"));
    }/*from   w  w w.j  a va 2s. com*/

    return sb.toString();

}

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

public void setIdFactura(String idFactura) {
    this.idFactura = StringUtils.leftPad(idFactura, 10, "0");
}

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

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

From source file:dk.dma.ais.encode.CommentBlockEncodeTest.java

@Test
public void lineEncodeTest() {
    int pairs = 100;
    int maxLen = 80;
    Random rand = new Random();
    Map<String, String> map = new HashMap<>();
    for (int i = 0; i < pairs; i++) {
        String key = Integer.toString(i);
        char c = (char) (65 + rand.nextInt(23));
        String value = StringUtils.leftPad("", rand.nextInt(70) + 1, c);
        map.put(key, value);/*  w w  w  .  j  a  v  a2  s  .  co  m*/
    }

    CommentBlock cb = new CommentBlock();
    for (Entry<String, String> pair : map.entrySet()) {
        cb.addString(pair.getKey(), pair.getValue());
    }

    String str = cb.encode(maxLen) + "\r\n";
    str += "!AIVDM,1,1,,A,H39LOOQUQPD0000000000000000,4*6D";

    AisPacket packet = AisPacket.from(str);
    cb = packet.getVdm().getCommentBlock();

    for (Entry<String, String> pair : map.entrySet()) {
        String value = cb.getString(pair.getKey());
        Assert.assertEquals(value, pair.getValue());
    }
}

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

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

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

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

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

@Test
void leftBoundOk() {
    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)).isTrue();
}