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.skratchdot.electribe.model.esx.impl.SampleTuneImpl.java

/**
 * <!-- begin-user-doc -->/*from  w w  w  .ja  v  a  2  s .  c  o  m*/
 * <!-- end-user-doc -->
 * @generated NOT
 */
public void setCurrentValueFromShort(short packedShort) {
    byte sampleTuneNegative = (byte) EsxUtil.unpackInt(packedShort, 1, 15);
    byte sampleTuneWhole = (byte) EsxUtil.unpackInt(packedShort, 7, 8);
    byte sampleTuneDecimal = (byte) EsxUtil.unpackInt(packedShort, 8, 0);

    // valid sampleTuneDecimal values are between 0-99
    if (sampleTuneDecimal > 99 || sampleTuneDecimal < 0) {
        sampleTuneDecimal = 0;
    }

    // Now construct the float value as a string
    String sampleTuneAsString = "";
    if (sampleTuneNegative == 1 && sampleTuneWhole > 0) {
        sampleTuneAsString = "-";
    }
    sampleTuneAsString = sampleTuneAsString + sampleTuneWhole + "."
            + StringUtils.leftPad(Integer.toString(sampleTuneDecimal), 2, "0");

    this.setValue(Float.parseFloat(sampleTuneAsString));
}

From source file:com.github.hexosse.pluginframework.pluginapi.command.predifined.CommandHelp.java

/**
 * Executes the given command, returning its success
 *
 * @param commandInfo Info about the command
 *
 * @return true if a valid command, otherwise false
 *//*w  w  w.  j  a  v  a 2  s. c  o  m*/
@Override
public boolean onCommand(CommandInfo commandInfo) {
    //List<Data> datas = Lists.newArrayList();
    HelpLines helpLines = new HelpLines(CLOSED_CHAT_PAGE_HEIGHT - 1);

    // Command
    PluginCommand<?> command = commandInfo.getCommand();

    // Parent command
    PluginCommand<?> parentCommand = command.getParentCommand();

    // Main command
    PluginCommand<?> mainCommand = command.getName().toLowerCase().equals(HELP.toLowerCase()) ? parentCommand
            : command;
    if (mainCommand.getMaxArgs() > 0) {
        CommandInfo mainCommandInfo = new CommandInfo(commandInfo.getSender(), mainCommand,
                mainCommand.getName(), new String[0], null);
        Help mainHelp = new Help(mainCommandInfo);

        if (command.getPermission() == null)
            helpLines.add(new HelpLine(mainCommandInfo, mainHelp));
        else if (command.getPermission() != null && command.getPermission().isEmpty() == false
                && commandInfo.getSender().hasPermission(command.getPermission()) == true)
            helpLines.add(new HelpLine(mainCommandInfo, mainHelp));
    }

    // Sub command
    for (Map.Entry<String, PluginCommand<?>> entry : mainCommand.getSubCommands().entrySet()) {
        PluginCommand<?> subCommand = entry.getValue();

        CommandInfo subCommandInfo = new CommandInfo(commandInfo.getSender(), subCommand, subCommand.getName(),
                new String[0], null);
        Help subHelp = new Help(subCommandInfo);

        if (subCommandInfo.getCommand().getPermission() == null
                || subCommandInfo.getCommand().getPermission().isEmpty() == true)
            helpLines.add(new HelpLine(subCommandInfo, subHelp));
        else if (subCommandInfo.getCommand().getPermission().isEmpty() == false
                && commandInfo.getSender().hasPermission(subCommandInfo.getCommand().getPermission()) == true)
            helpLines.add(new HelpLine(subCommandInfo, subHelp));
    }

    // Page requested
    int page = Integer
            .parseInt(commandInfo.hasNamedArg("page") == true ? commandInfo.getNamedArg("page") : "1");
    int maxPages = helpLines.currentPage;

    // Check page number
    page = ((page >= maxPages) ? maxPages : ((page <= 0) ? 1 : page));

    // Title line
    MessagePart prev = getPrev(command, page - 1, maxPages);
    MessagePart help = new MessagePart(
            " " + MessageText.help_for_command + " \"" + parentCommand.getName() + "\" ")
                    .color(MessageColor.DESCRIPTION);
    MessagePart index = getIndex(command, page, maxPages);
    MessagePart next = getNext(command, page + 1, maxPages);
    int len = (prev.getText() + help.getText() + index.getText() + next.getText()).length();
    MessagePart dash = new MessagePart(ChatColor.STRIKETHROUGH
            + StringUtils.leftPad("", (GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - len) / 2, "-"))
                    .color(MessageColor.DESCRIPTION);

    Message m = new Message(new MessageLine().add(dash).add(prev).add(help).add(index).add(next).add(dash));
    plugin.messageManager.send(commandInfo, new Message(""));
    plugin.messageManager.send(commandInfo, m);

    // Help lines
    for (HelpLine line : helpLines.lines) {
        if (line.page == page)
            plugin.messageManager.send(line.commandInfo, line.message);
    }

    return true;
}

From source file:com.haulmont.cuba.web.AbstractConnection.java

protected TimeZone detectTimeZone() {
    Page page = AppUI.getCurrent().getPage();
    WebBrowser webBrowser = page.getWebBrowser();

    int offset = webBrowser.getTimezoneOffset() / 1000 / 60;
    String hours = StringUtils.leftPad(String.valueOf(offset / 60), 2, '0');
    String mins = StringUtils.leftPad(String.valueOf(offset % 60), 2, '0');
    char sign = offset >= 0 ? '+' : '-';
    return TimeZone.getTimeZone("GMT" + sign + hours + mins);
}

From source file:com.zigbee.framework.common.util.Utils.java

/**
 * //from   w ww .  j  ava2 s.  co m
 * @Date        :      2011-7-6
 * @param currentContactCodeSeq
 * @return
 */
public static String getNextContactCodeSeq(String dealerOrgCode, Integer contactCodeSeq) {

    int year = Calendar.getInstance().get(Calendar.YEAR);

    contactCodeSeq = contactCodeSeq + 1;

    return dealerOrgCode + year + StringUtils.leftPad(contactCodeSeq + "", 6, "0");

}

From source file:net.sourceforge.fenixedu.presentationTier.Action.library.ManageCapacityAndLockersDA.java

private void setLockers(Space library, int lockers, DateTime today) {
    int highestLocker = 0;
    for (Space relSpace : library.getChildren()) {
        Space space = relSpace;/*  w ww .  j  a v a  2s .co  m*/
        int lockerNumber;
        try {
            lockerNumber = Integer.parseInt(space.getName());
            if (lockerNumber > lockers) {
                final InformationBean bean = space.bean();
                bean.setValidUntil(today);
                space.bean(bean);
            } else {
                setCapacity(space, 1);
            }
            if (lockerNumber > highestLocker) {
                highestLocker = lockerNumber;
            }
        } catch (NumberFormatException e) {
        }
    }
    if (highestLocker < lockers) {
        for (int i = highestLocker + 1; i <= lockers; i++) {
            final InformationBean bean = Information.builder()
                    .name(StringUtils.leftPad(Integer.toString(i), String.valueOf(lockers).length(), '0'))
                    .classification(SpaceClassification.getByName(SpaceUtils.ROOM_SUBDIVISION)).validFrom(today)
                    .allocatableCapacity(1).bean();
            new Space(library, bean);
        }
    }
}

From source file:au.org.theark.lims.web.component.biospecimenuidtemplate.SearchResultsPanel.java

public String getBiospecimenUidExample(BiospecimenUidTemplate biospecimenUidTemplate) {
    String biospecimenUidPrefix = new String("");
    String biospecimenUidToken = new String("");
    String biospecimenUidPaddedIncrementor = new String("");
    String biospecimenUidPadChar = new String("0");
    String biospecimenUidStart = new String("1");
    StringBuilder biospecimenUidExample = new StringBuilder();

    if (biospecimenUidTemplate.getBiospecimenUidPrefix() != null)
        biospecimenUidPrefix = biospecimenUidTemplate.getBiospecimenUidPrefix();

    if (biospecimenUidTemplate.getBiospecimenUidToken() != null)
        biospecimenUidToken = biospecimenUidTemplate.getBiospecimenUidToken().getName();

    if (biospecimenUidTemplate.getBiospecimenUidPadChar() != null) {
        biospecimenUidPadChar = biospecimenUidTemplate.getBiospecimenUidPadChar().getName().trim();
    }//from ww  w . j a  v a 2  s  .co m

    int size = Integer.parseInt(biospecimenUidPadChar);
    biospecimenUidPaddedIncrementor = StringUtils.leftPad(biospecimenUidStart, size, "0");

    biospecimenUidExample.append(biospecimenUidPrefix);
    biospecimenUidExample.append(biospecimenUidToken);
    biospecimenUidExample.append(biospecimenUidPaddedIncrementor);

    return biospecimenUidExample.toString();
}

From source file:au.org.theark.lims.web.component.biospecimenuidtemplate.form.DetailForm.java

public String getBiospecimenUidExample() {
    String biospecimenUidPrefix = new String("");
    String biospecimenUidToken = new String("");
    String biospecimenUidPaddedIncrementor = new String("");
    String biospecimenUidPadChar = new String("0");
    String biospecimenUidStart = new String("1");
    StringBuilder biospecimenUidExample = new StringBuilder();

    biospecimenUidPrefix = biospecimenUidPrefixTxtFld.getDefaultModelObjectAsString();

    if (biospecimenUidTokenDdc.getModelObject() != null) {
        biospecimenUidToken = biospecimenUidTokenDdc.getModelObject().getName();
    }//  ww w  .java  2 s  .com

    if (biospecimenUidPadCharDdc.getModelObject() != null) {
        biospecimenUidPadChar = biospecimenUidPadCharDdc.getModelObject().getName();
    }

    if (biospecimenUidPadChar.isEmpty()) {
        biospecimenUidPadChar = new String("0");
    }
    int size = Integer.parseInt(biospecimenUidPadChar);
    biospecimenUidPaddedIncrementor = StringUtils.leftPad(biospecimenUidStart, size, "0");

    biospecimenUidExample.append(biospecimenUidPrefix);
    biospecimenUidExample.append(biospecimenUidToken);
    biospecimenUidExample.append(biospecimenUidPaddedIncrementor);

    return biospecimenUidExample.toString();
}

From source file:com.smartitengineering.dao.hbase.ddl.TableGenerationTest.java

protected String getPaddedId(long longId) {
    return StringUtils.leftPad(String.valueOf(longId), 10, '0');
}

From source file:eu.squadd.timesheets.eolas.TimeTemplate.java

private Map extractHolidays(String[] args) {
    Map<String, String> holidays = new HashMap();
    int j = 1;// ww w  .j av a2s  .  c  o m
    while (j < args.length) {
        String[] period = args[j].split("-");
        int start = Integer.parseInt(period[0]);
        int end = period.length > 1 ? Integer.parseInt(period[1]) : 0;
        if (end > 0) {
            for (int i = start; i <= end; i++) {
                String dayOfMonth = StringUtils.leftPad(String.valueOf(i), 2, '0').concat("/")
                        .concat(StringUtils.leftPad(String.valueOf(month), 2, '0')).concat("/")
                        .concat(StringUtils.leftPad(String.valueOf(year), 2, '0'));

                holidays.put(dayOfMonth, "Leave");
            }
        } else {
            String dayOfMonth = StringUtils.leftPad(String.valueOf(start), 2, '0').concat("/")
                    .concat(StringUtils.leftPad(String.valueOf(month), 2, '0')).concat("/")
                    .concat(StringUtils.leftPad(String.valueOf(year), 2, '0'));

            holidays.put(dayOfMonth, "Leave");
        }
        j++;
    }
    return holidays;
}

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

public static String time(String format, String time) {
    time = time.replaceAll("[^0-9]+", "");
    time = StringUtils.rightPad(time, 6, '0');
    time = StringUtils.leftPad(time, 14, '0');
    return date(format, time);
}