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:org.ojbc.adapters.rapbackdatastore.processor.SubsequentResultsQueryProcessor.java

private void createHistorySummaryDocumentElement(Exchange exchange, SubsequentResults subsequentResult,
        Element parentElement) {/*w  w w  . j  av a2 s  . c  om*/

    QueryResponseElementName queryResponseElementName;
    DocumentId documentId;

    switch (subsequentResult.getResultsSender()) {
    case FBI:
        queryResponseElementName = QueryResponseElementName.FBIIdentityHistorySummaryDocument;
        documentId = DocumentId.fbiIdentityHistorySummaryDocument;
        break;
    case State:
    default:
        queryResponseElementName = QueryResponseElementName.StateCriminalHistoryRecordDocument;
        documentId = DocumentId.stateCriminalHistoryRecordDocument;
    }

    byte[] rapSheet = subsequentResult.getRapSheet();
    String documentIdString = documentId.name() + "_"
            + StringUtils.leftPad(subsequentResult.getId().toString(), 8, '0');
    appendDocumentElement(parentElement, queryResponseElementName, documentIdString, rapSheet);
}

From source file:org.ojbc.util.ndex.util.UniqueIDGenerator.java

public String getNextMessageIDInString() throws Exception {
    int n = this.getNextMessageID();
    String numberAsString = String.valueOf(n);
    String paddedNumber = StringUtils.leftPad(numberAsString, 4, '0');
    return paddedNumber;

}

From source file:org.onosproject.t3.cli.T3CliUtils.java

private static StringBuilder printTrace(StaticPacketTrace trace, boolean verbose, StringBuilder tracePrint) {
    List<List<ConnectPoint>> paths = trace.getCompletePaths();
    for (List<ConnectPoint> path : paths) {
        tracePrint.append("Path " + path);
        tracePrint.append("\n");
        ConnectPoint previous = null;//w w  w . j  av  a  2s .  com
        if (path.size() == 1) {
            ConnectPoint connectPoint = path.get(0);
            tracePrint.append("Device " + connectPoint.deviceId());
            tracePrint.append("\n");
            tracePrint.append("Input from " + connectPoint);
            tracePrint.append("\n");
            tracePrint = printFlows(trace, verbose, connectPoint, tracePrint);
            tracePrint = printGroups(trace, verbose, connectPoint, tracePrint);
            tracePrint.append("\n");
        } else {
            for (ConnectPoint connectPoint : path) {
                if (previous == null || !previous.deviceId().equals(connectPoint.deviceId())) {
                    tracePrint.append("Device " + connectPoint.deviceId());
                    tracePrint.append("\n");
                    tracePrint.append("    Input from " + connectPoint);
                    tracePrint.append("\n");
                    tracePrint = printFlows(trace, verbose, connectPoint, tracePrint);
                } else {
                    tracePrint = printGroups(trace, verbose, connectPoint, tracePrint);
                    tracePrint.append("    Output through " + connectPoint);
                    tracePrint.append("\n");
                }
                previous = connectPoint;
            }
        }
        tracePrint.append(StringUtils.leftPad("\n", 100, '-'));
    }
    return tracePrint;
}

From source file:org.onosproject.t3.cli.TroubleshootPingAllCommand.java

@Override
protected void execute() {
    TroubleshootService service = get(TroubleshootService.class);

    EtherType type = EtherType.valueOf(ethType.toUpperCase());

    print("Tracing between all %s hosts", ethType);

    if (!type.equals(EtherType.IPV4) && !type.equals(EtherType.IPV6)) {
        print("Command only support IPv4 or IPv6");
    } else {/*from w  w w.j  a  v  a 2  s. c om*/
        //Create the generator for the list of traces.
        Generator<Set<StaticPacketTrace>> generator = service.pingAllGenerator(type);
        Host previousHost = null;
        int totalTraces = 0;
        List<StaticPacketTrace> failedTraces = new ArrayList<>();
        boolean ipv4 = type.equals(EtherType.IPV4);
        while (generator.iterator().hasNext()) {
            Set<StaticPacketTrace> traces = generator.iterator().next();
            totalTraces++;
            for (StaticPacketTrace trace : traces) {
                //no verbosity is mininet style output
                if (!verbosity1 && !verbosity2) {
                    if (trace.getEndpointHosts().isPresent()) {
                        Host src = trace.getEndpointHosts().get().getLeft();
                        if (previousHost == null || !previousHost.equals(src)) {
                            print("%s", StringUtils.rightPad("", 125, '-'));
                            previousHost = printSrc(trace, ipv4, src);
                        }
                        String host = getDstString(trace, ipv4, src);
                        if (!trace.isSuccess()) {
                            host = host + " " + trace.resultMessage();
                            failedTraces.add(trace);
                        }
                        print("%s", host);
                    }
                } else {
                    print("%s", StringUtils.leftPad("", 125, '-'));

                    if (trace.getInitialPacket() != null) {
                        if (verbosity1) {
                            printResultOnly(trace, ipv4);
                        } else if (verbosity2) {
                            printVerbose(trace);
                        }
                    } else {
                        if (trace.getEndpointHosts().isPresent()) {
                            Host source = trace.getEndpointHosts().get().getLeft();
                            Host destination = trace.getEndpointHosts().get().getRight();
                            print("Source %s --> Destination %s", source.id(), destination.id());
                        }
                        print("Error in obtaining trace: %s", trace.resultMessage());
                    }
                }
            }
            try {
                sleep(delay);
            } catch (InterruptedException e) {
                log.debug("interrupted while sleep");
            }
        }
        print("%s", StringUtils.rightPad("", 125, '-'));
        print("Failed Traces: %s", failedTraces.size());
        print("%s", StringUtils.rightPad("", 125, '-'));
        failedTraces.forEach(t -> {
            if (t.getEndpointHosts().isPresent()) {
                printSrc(t, ipv4, t.getEndpointHosts().get().getLeft());
                String dst = getDstString(t, ipv4, t.getEndpointHosts().get().getRight());
                dst = dst + " " + t.resultMessage();
                print("%s", dst);
                print("%s", StringUtils.rightPad("", 125, '-'));
            }
        });
        print("Summary");
        print("Total Traces %s, errors %s", totalTraces, failedTraces.size());
    }
}

From source file:org.opencb.opencga.storage.hadoop.variant.VariantHbaseWriter.java

private String buildRowkey(Variant v) {
    StringBuilder builder = new StringBuilder();
    builder.append(StringUtils.leftPad(v.getChromosome(), 4, '0'));
    builder.append("_");
    builder.append(v.getStart());/*from  ww w  .j  a v a2 s . c  om*/
    builder.append("_");
    if (v.getReference().length() < Variant.SV_THRESHOLD) {
        builder.append(v.getReference());
    } else {
        builder.append(new String(CryptoUtils.encryptSha1(v.getReference())));
    }

    builder.append("_");

    if (v.getAlternate().length() < Variant.SV_THRESHOLD) {
        builder.append(v.getAlternate());
    } else {
        builder.append(new String(CryptoUtils.encryptSha1(v.getAlternate())));
    }

    return builder.toString();
}

From source file:org.opencb.opencga.storage.mongodb.variant.converters.VariantStringIdConverter.java

private static StringBuilder buildId(String chromosome, int start, StringBuilder stringBuilder) {

    appendChromosome(chromosome, stringBuilder).append(SEPARATOR_CHAR)
            .append(StringUtils.leftPad(Integer.toString(start), 10, " "));
    return stringBuilder;
}

From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerService.java

private File getBackupFile(File artifact) {
    int backupNumber = 0;
    String candidate = artifact.getAbsolutePath();
    File candFile = new File(candidate);
    while (candFile.exists()) {
        backupNumber++;/*  w w w  .  j  a  v  a2s . c o  m*/
        String suffix = StringUtils.leftPad(Integer.toString(backupNumber), 3, "0");
        candidate = artifact.getAbsolutePath() + "_" + suffix;
        candFile = new File(candidate);
    }
    return candFile;
}

From source file:org.openhab.binding.intertechno.internal.parser.V3Parser.java

@Override
public void parseConfig(List<String> configParts) throws BindingConfigParseException {
    String id = "";
    Boolean group = false;// www .  j av a  2 s  . c om
    Integer channelID = 0;

    // Extract parameter values from config parts
    for (int i = 0; i < configParts.size(); i++) {
        String paramName = configParts.get(i).split("=")[0].toLowerCase();
        String paramValue = configParts.get(i).split("=")[1];

        switch (paramName) {
        case "id":
            id = paramValue;
            break;
        case "group":
            if (paramValue.equals("1") || paramValue.toLowerCase().equals("true")) {
                group = true;
            }
            break;
        case "channel":
            try {
                channelID = Integer.parseInt(paramValue);
            } catch (NumberFormatException e) {
                throw new BindingConfigParseException("Channel ID (" + paramValue + ") is not a number.");
            }
        }
    }

    // Check parameter values
    if (id.length() != 26) {
        throw new BindingConfigParseException("The ID must contain exactly 26 digits!");
    }

    for (int i = 0; i < id.length(); i++) {
        if (id.charAt(i) != '0' && id.charAt(i) != '1') {
            throw new BindingConfigParseException("The ID must contains only the digits 1 and 0!");
        }
    }

    if (channelID < 0 || channelID > 15) {
        throw new BindingConfigParseException("The channel ID must be in a range from 0 to 15!");
    }

    // Build command strings
    String channelIDCode = StringUtils.leftPad(Integer.toBinaryString(channelID), 4, "0");

    commandON = id + getGroupCode(group) + "1" + channelIDCode;
    commandOFF = id + getGroupCode(group) + "0" + channelIDCode;

    logger.trace("commandON = {}", commandON);
    logger.trace("commandOFF = {}", commandOFF);
}

From source file:org.openhab.binding.nikobus.internal.config.ModuleChannelGroup.java

/**
 * Push the state of all channels to the Nikobus.
 * /* w  w w.j a va  2s. c  o  m*/
 * @param moduleChannel
 */
public void publishStateToNikobus(ModuleChannel moduleChannel, NikobusBinding binding) {

    log.trace("Publishing group {}-{} status to eventbus and nikobus", address, group);

    // update the channel on the event bus..
    binding.postUpdate(moduleChannel.getName(), moduleChannel.getState());

    StringBuilder command = new StringBuilder();
    command.append(statusUpdateGroup);
    command.append(address);

    for (int i = 0; i < 6; i++) {

        if (channels[i] == null) {
            // no channel defined
            command.append(LOW_BYTE);
            continue;
        }

        State channelState = channels[i].getState();
        if (channelState == null || channelState.equals(OnOffType.OFF)
                || channelState.equals(PercentType.ZERO)) {
            command.append(LOW_BYTE);
        } else if (channelState.equals(UpDownType.UP)) {
            command.append(UP_BYTE);
        } else if (channelState.equals(UpDownType.DOWN)) {
            command.append(DOWN_BYTE);
        } else if (channelState instanceof PercentType) {
            // calculate dimmer value...
            PercentType currentState = (PercentType) channelState;
            int value = BigDecimal.valueOf(255).multiply(currentState.toBigDecimal())
                    .divide(BigDecimal.valueOf(100), 0, BigDecimal.ROUND_UP).intValue();
            command.append(StringUtils.leftPad(Integer.toHexString(value), 2, "0").toUpperCase());
        } else {
            command.append(HIGH_BYTE);
        }

    }

    command.append(HIGH_BYTE);

    NikobusCommand cmd = new NikobusCommand(
            CRCUtil.appendCRC2(STATUS_CHANGE_CMD + CRCUtil.appendCRC(command.toString())));

    try {
        binding.sendCommand(cmd);
    } catch (Exception e) {
        log.error("Error sending command.", e);
    }
}

From source file:org.openhab.binding.nikobus.internal.util.CRCUtil.java

/**
 * Calculate the CRC16-CCITT checksum on the input string and return the
 * input string with the checksum appended.
 * //from   w w  w  . jav a 2 s . c  om
 * @param input
 *            String representing hex numbers.
 * @return input string + CRC.
 */
public static String appendCRC(String input) {

    if (input == null) {
        return null;
    }

    int check = CRC_INIT;

    for (byte b : DatatypeConverter.parseHexBinary(input)) {
        for (int i = 0; i < 8; i++) {
            if (((b >> (7 - i) & 1) == 1) ^ ((check >> 15 & 1) == 1)) {
                check = check << 1;
                check = check ^ POLYNOMIAL;
            } else {
                check = check << 1;
            }
        }
    }
    check = check & CRC_INIT;
    String checksum = StringUtils.leftPad(Integer.toHexString(check), 4, "0");
    return (input + checksum).toUpperCase();
}