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 write(int tabs, String content) {
    write(StringUtils.leftPad("", tabs, "\t") + content + "");
}

From source file:br.com.ararati.operacoes.ConstroiChaveAcesso.java

public String constroiChaveDeAcesso(InfNFe infnfe) throws NFeException {
    try {//from ww  w. j  a v a2s  .c  o  m
        String cUF = infnfe.getIde().getCUF(); // Cdigo da UF do emitente do Documento Fiscal.
        String dataAAMM = infnfe.getIde().getDhEmi().substring(2, 4)
                + infnfe.getIde().getDhEmi().substring(5, 7); // Ano e Ms de emisso da NF-e.  
        String cnpjCpf = infnfe.getEmit().getCNPJ(); // CNPJ do emitente.
        String mod = infnfe.getIde().getMod(); // Modelo do Documento Fiscal.  
        String serie = infnfe.getIde().getSerie();// Srie do Documento Fiscal.  
        String tpEmis = infnfe.getIde().getTpEmis();// Forma de emisso da NF-e  
        String nNF = infnfe.getIde().getNNF();// Nmero do Documento Fiscal.  
        String cNF = infnfe.getIde().getCNF();// Cdigo Numrico que compe a Chave de Acesso.  

        StringBuilder chave = new StringBuilder();
        chave.append(StringUtils.leftPad(cUF, 2, '0'));
        chave.append(StringUtils.leftPad(dataAAMM, 4, '0'));
        chave.append(StringUtils.leftPad(cnpjCpf.replaceAll("\\D", ""), 14, '0'));
        chave.append(StringUtils.leftPad(mod, 2, '0'));
        chave.append(StringUtils.leftPad(serie, 3, '0'));
        chave.append(StringUtils.leftPad(String.valueOf(nNF), 9, '0'));
        chave.append(StringUtils.leftPad(tpEmis, 1, '0'));
        chave.append(StringUtils.leftPad(cNF, 8, '0'));
        chave.append(modulo11(chave.toString()));

        return chave.toString();
    } catch (Exception e) {
        throw new NFeException("Erro ao construir chave de acesso!");
    }
}

From source file:com.espe.distribuidas.protocolocajero.operaciones.RetiroRS.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"));
    }//  w  w w .j  a v  a2s. com

    return sb.toString();
}

From source file:edu.pitt.dbmi.edda.operator.regexop.regex.RegularExpression.java

public RegularExpression(String name, String value, int regularExpressionNumber) {
    this.name = name;
    this.value = value;
    this.regularExpressionNumber = regularExpressionNumber;
    this.key = ":" + StringUtils.leftPad(regularExpressionNumber + "", 10, "0");
    /* @todo//from w  ww . j a  v  a  2s .  c  o m
     *    Add regex parameters into UI
     */
    //      this.pattern = Pattern.compile(value, Pattern.DOTALL
    //            | Pattern.CASE_INSENSITIVE);
    this.pattern = Pattern.compile(value, Pattern.DOTALL);
}

From source file:com.netsteadfast.greenstep.util.PdfConvertUtils.java

@SuppressWarnings("unchecked")
public static List<File> toImageFiles(File pdfFile, int resolution) throws Exception {
    PDDocument document = PDDocument.loadNonSeq(pdfFile, null);
    List<PDPage> pages = document.getDocumentCatalog().getAllPages();
    File tmpDir = new File(Constants.getWorkTmpDir() + "/" + PdfConvertUtils.class.getSimpleName() + "/"
            + System.currentTimeMillis() + "/");
    FileUtils.forceMkdir(tmpDir);//from  w  w w . j av a 2s  .  c  o m
    List<File> files = new LinkedList<File>();
    int len = String.valueOf(pages.size() + 1).length();
    for (int i = 0; i < pages.size(); i++) {
        String name = StringUtils.leftPad(String.valueOf(i + 1), len, "0");
        BufferedImage bufImage = pages.get(i).convertToImage(BufferedImage.TYPE_INT_RGB, resolution);
        File imageFile = new File(tmpDir.getPath() + "/" + name + ".png");
        FileOutputStream fos = new FileOutputStream(imageFile);
        ImageIOUtil.writeImage(bufImage, "png", fos, resolution);
        fos.flush();
        fos.close();
        files.add(imageFile);
    }
    document.close();
    tmpDir = null;
    return files;
}

From source file:ec.edu.distri.clientejava.protocolo.model.Canal.java

@Override
public String asTexto() {
    return nombre + descripcion + StringUtils.leftPad(costo.toPlainString(), 5, "0");
}

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

private boolean showBalance() {
    Calendar calendar = Calendar.getInstance();
    String ThisYearMonth = DateInfo.getDateInfo(calendar).getString(DateInfo.F.ThisYearMonth);

    List<Record> list = new Transaction().getRekapOfMonthPerCustomer(ThisYearMonth);
    Replier replier = getReplier();/*from  w  ww  .j a v a2 s.  c  o  m*/

    long totalPay = 0;
    long totalBill = 0;
    int count = 0;
    for (Record record : list) {
        long amount = record.getLong(Transaction.V.Rekap);
        if (amount == 0) {
            continue;
        }
        count += 1;
        String strCount = StringUtils.leftPad(count + ". ", 5, "0");
        final String customer = record.getString(Transaction.F._id);
        replier.addLine(strCount).add(customer).add(": ");

        if (amount < 0) {
            totalBill -= amount;
            replier.add(Tool.formatMoney(-amount));
        } else if (amount > 0) {
            totalPay += amount;
            replier.add(Tool.formatMoney(amount)).add(" \uD83D\uDC4C");
        }
    }
    replier.addLine("");
    replier.addLine("Total Tagihan : ").add(Tool.formatMoney(totalBill));
    replier.addLine("Total Saldo   : ").add(Tool.formatMoney(totalPay));

    replier.send();

    return petunjuk();
}

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

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

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

@Override
public String asTexto() {
    StringBuilder sb = new StringBuilder();
    sb.append(this.cuenta);
    sb.append("_").append(this.tipo).append("_");
    sb.append(StringUtils.leftPad(Double.toString(this.valorRetiro), 10, "0"));
    sb.append("_").append(this.documetoDepositante).append("_");
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy/HH/mm/ss");
    sb.append(sdf.format(this.fecha));
    return sb.toString();
}

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

@Override
public String asTexto() {
    StringBuilder sb = new StringBuilder();
    sb.append(this.cuenta);
    sb.append("_").append(this.tipo).append("_");
    sb.append(StringUtils.leftPad(Double.toString(this.valorDeposito), 10, "0"));
    sb.append("_").append(this.documetoDepositante).append("_");
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy/HH/mm/ss");
    sb.append(sdf.format(this.fecha));

    return sb.toString();
}