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

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

Introduction

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

Prototype

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

Source Link

Document

Left pad a String with a specified String.

Usage

From source file:com.google.code.rptm.mailarchive.YearMonth.java

/**
 * Format the year and month as YYYYMM.//  w w  w  .  jav  a  2 s. c  om
 * 
 * @return the formatted year and month
 */
public String toSimpleFormat() {
    return year + StringUtils.leftPad(String.valueOf(month), 2, '0');
}

From source file:net.nan21.dnet.module.md.business.ext.org.service.DocSequence_Service.java

/**
 * Create values for the document sequence.
 *//*  w ww. ja v a2  s . c om*/
@Override
public void doCreateValues(String docSequenceId) throws BusinessException {

    DocSequence sequence = null;

    // check if values already exist

    try {
        sequence = this.getEntityManager().createQuery("select e from DocSequence e "
                + " where e.id = :docSeqId "
                + "  and not exists ( select 1 from DocSequenceValue v where v.docSequence.id = e.id  )",
                DocSequence.class).setParameter("docSeqId", docSequenceId).getSingleResult();
    } catch (NoResultException e) {
        throw new BusinessException("Cannot create values for a document sequence which already has values. ");
    }

    // generate values

    String prefix = "";
    String suffix = "";

    if (sequence.getPrefix() != null) {
        prefix = sequence.getPrefix();
    }
    if (sequence.getSuffix() != null) {
        suffix = sequence.getSuffix();
    }

    int from = sequence.getFirstNo();
    int to = sequence.getLastNo();
    int length = 0;

    if (sequence.getPaddingLength() != null) {
        length = sequence.getPaddingLength();
    }

    List<DocSequenceValue> values = new ArrayList<DocSequenceValue>();
    for (int i = from; i <= to; i++) {
        DocSequenceValue value = new DocSequenceValue();
        String _v = i + "";
        if (length > 0) {
            _v = StringUtils.leftPad(_v, length, '0');
        }
        value.setNumericValue(i);
        value.setValue(prefix + _v + suffix);
        value.setDocSequence(sequence);
        values.add(value);
    }

    this.findEntityService(DocSequenceValue.class).insert(values);

}

From source file:com.syaku.commons.DateUtils.java

public static Date setDateString(String date) {
    Date retDate = null;//  w ww.  j a  va 2s . c  om

    try {
        String sysdate_patten = "(^[A-Za-z]{3}), ([0-9]{2}) ([A-Za-z]{3}) ([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2}) ([+0-9]{5})$";
        String yyyy = date.replaceAll(sysdate_patten, "$4");
        String MM = date.replaceAll(sysdate_patten, "$3");
        String dd = date.replaceAll(sysdate_patten, "$2");
        String hh = date.replaceAll(sysdate_patten, "$5");
        String mm = date.replaceAll(sysdate_patten, "$6");
        String ss = date.replaceAll(sysdate_patten, "$7");
        String timezone = date.replaceAll(sysdate_patten, "$8");

        String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
                "Dec" };
        int months_int = months.length;
        for (int i = 0; i < months_int; i++) {
            String month = months[i];
            if (StringUtils.equals(MM, month)) {
                MM = "" + (i + 1);
                MM = StringUtils.leftPad(MM, 2, '0');
                break;
            }
        }

        date = yyyy + MM + dd + hh + mm + ss;
        date = date("yyyy-MM-dd HH:mm:ss", date);
        formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        retDate = formatter.parse(date);
    } catch (Exception e) {
        log.error("[#MEI DateUtils.setDateString] " + e.toString());
    }

    return retDate;
}

From source file:com.ocs.dynamo.utils.DateUtils.java

/**
 * Returns the next week code given an existing week code
 * /*from  w w  w.j  av  a  2  s.c  om*/
 * @param weekCode
 * @return
 */
public static String getNextWeekCode(String weekCode) {
    if (weekCode == null) {
        return null;
    }

    int year = getYearFromWeekCode(weekCode);
    int week = getWeekFromWeekCode(weekCode);

    String next = year + "-" + StringUtils.leftPad(Integer.toString(week + 1), 2, "0");
    if (isValidWeekCode(next)) {
        return next;
    } else {
        return (year + 1) + "-" + "01";
    }
}

From source file:it.sample.parser.util.CommonsUtil.java

/**
 * Metodo di utilita per la composizione di un multichannelId a partire da un abi, un canale e un bt
 * //from   ww w. jav  a 2s.  c  om
 * @param abi
 * @param canale
 * @param userid
 * @return multichannelId
 * @throws IllegalArgumentException
 *             se l'abi, il canale o il bt non sono validi
 */
public static String getMultichannelId(String abi, String canale, String userid) {

    if (abi == null || abi.length() > 5)
        throw new IllegalArgumentException("Stringa ABI troppo lunga");

    if (canale == null || canale.length() > 2)
        throw new IllegalArgumentException("Stringa canale troppo lunga");

    if (userid == null || userid.length() > 8)
        throw new IllegalArgumentException("Stringa userid troppo lunga");

    StringBuffer buf = new StringBuffer(17);
    buf.append(StringUtils.leftPad(abi, 5, "0"));
    buf.append(PREFISSO_CANALE);
    buf.append(StringUtils.leftPad(canale, 2, "0"));
    buf.append(StringUtils.leftPad(userid, 8, "0"));
    return buf.toString();
}

From source file:net.sourceforge.fenixedu.domain.accounting.util.PersonPaymentCodeGenerator.java

private String getPersonCodeDigits(Person person) {
    if (person.getIstUsername().length() > 9) {
        throw new RuntimeException(
                "SIBS Payment Code: " + person.getIstUsername() + " exceeded maximun size accepted");
    }/*from w  w  w  . j  a  va 2 s. com*/
    return StringUtils.leftPad(person.getIstUsername().replace("ist", ""), PERSON_CODE_LENGTH, CODE_FILLER);
}

From source file:com.haulmont.cuba.core.global.TimeZones.java

/**
 * @return string representing the offset of the given time zone from GMT
 *///from  ww  w. j av  a2s.  c o  m
public String getDisplayOffset(@Nullable TimeZone timeZone) {
    if (timeZone == null)
        return "";

    int offsetSec = timeZone.getOffset(timeSource.currentTimeMillis()) / 1000;
    int offsetHours = offsetSec / 3600;
    int offsetMins = (offsetSec % 3600) / 60;
    String str = StringUtils.leftPad(String.valueOf(Math.abs(offsetHours)), 2, '0') + ":"
            + StringUtils.leftPad(String.valueOf(Math.abs(offsetMins)), 2, '0');
    String sign = offsetHours >= 0 ? "+" : "-";
    return "GMT" + sign + str;
}

From source file:com.iisigroup.cap.rule.service.impl.FactorMntServiceImpl.java

@Override
public void insertTestCaseInfoData() {
    BigDecimal[] amount = new BigDecimal[] { new BigDecimal(100000), new BigDecimal(150000),
            new BigDecimal(900000), new BigDecimal(999999), new BigDecimal(50000), new BigDecimal(330000),
            new BigDecimal(550000), new BigDecimal(330000), new BigDecimal(150000), new BigDecimal(260000),
            new BigDecimal(440000), new BigDecimal(100000), new BigDecimal(880000), new BigDecimal(330000),
            new BigDecimal(150000), new BigDecimal(150000), new BigDecimal(250000), new BigDecimal(440000),
            new BigDecimal(130000), new BigDecimal(300000) };

    Integer[] overDueDay = new Integer[] { 20, 90, 20, 31, 20, 20, 44, 29, 20, 77, 30, 66, 88, 20, 66, 90, 11,
            30, 20, 15 };//from  w  ww  . j  a v  a  2  s. c o m
    List<CaseInfo> caseList = new ArrayList<CaseInfo>();
    Calendar cal = Calendar.getInstance();
    int count = 1;
    for (int j = 1; j <= 20; j++) {
        for (int i = count; i <= (5000 * j); i++) {
            CaseInfo cas = new CaseInfo();
            cas.setCasNo(StringUtils.leftPad(String.valueOf(i), 20, '0'));
            int result = (int) (Math.random() * (20 - 1) + 1);
            cas.setAmount(amount[result]);
            result = (int) (Math.random() * (20 - 1) + 1);
            cas.setOverDueDay(overDueDay[result]);
            cas.setCreator("System");
            cas.setCreateTime(new Timestamp(cal.getTimeInMillis()));
            caseList.add(cas);
            count++;
        }
        caseInfoDao.save(caseList);
        System.out.println(" case info records :: " + caseList.size());
    }
}

From source file:com.artivisi.iso8583.Message.java

public String getPrimaryBitmapStream() {
    if (primaryBitmap == null) {
        return null;
    }/* ww w .  jav a2 s .c  o  m*/
    return StringUtils.leftPad(primaryBitmap.toString(16).toUpperCase(), 16, "0");
}

From source file:de.codesourcery.eve.skills.ui.utils.ResizingTextField.java

protected Dimension calcSize(String text) {
    final FontMetrics fm = this.getFontMetrics(this.getFont());
    final int height = fm.getHeight();

    final int colCount = Math.max(getColumns(), 1);
    final String realText = StringUtils.isBlank(text) ? StringUtils.leftPad("X", colCount, " ")
            : " " + text + " ";

    int width = (int) (1.2f * fm.stringWidth(realText));
    return new Dimension(width, height + 6);
}