Example usage for org.apache.commons.lang3.math NumberUtils toInt

List of usage examples for org.apache.commons.lang3.math NumberUtils toInt

Introduction

In this page you can find the example usage for org.apache.commons.lang3.math NumberUtils toInt.

Prototype

public static int toInt(final String str) 

Source Link

Document

Convert a String to an int, returning zero if the conversion fails.

If the string is null, zero is returned.

 NumberUtils.toInt(null) = 0 NumberUtils.toInt("")   = 0 NumberUtils.toInt("1")  = 1 

Usage

From source file:com.mirth.connect.plugins.mllpmode.MLLPv2StreamHandler.java

public MLLPv2StreamHandler(InputStream inputStream, OutputStream outputStream,
        BatchStreamReader batchStreamReader, TransmissionModeProperties transmissionModeProperties) {
    super(inputStream, outputStream, batchStreamReader, transmissionModeProperties);
    MLLPModeProperties props = (MLLPModeProperties) transmissionModeProperties;
    ackBytes = TcpUtil.stringToByteArray(props.getAckBytes());
    nackBytes = TcpUtil.stringToByteArray(props.getNackBytes());
    maxRetries = NumberUtils.toInt(props.getMaxRetries());
    committed = false;//from  w ww  .j a  va  2  s  .c  o  m
}

From source file:com.kegare.bedrocklayer.client.config.CycleIntegerEntry.java

@Override
public void valueButtonPressed(int slotIndex) {
    if (enabled()) {
        if (++currentValue > NumberUtils.toInt(configElement.getMaxValue().toString())) {
            currentValue = 0;/*  w ww .  ja v  a  2 s.  c  om*/
        }

        updateValueButtonText();
    }
}

From source file:Data.Player.java

public void nhlnumbers(String input) {
    temp = input.split("<td>");

    String pdata[] = temp[0].split(":");
    name = pdata[4].substring(pdata[4].indexOf(">") + 1, pdata[4].indexOf("</")).split(", ")[1] + " "
            + pdata[4].substring(pdata[4].indexOf(">") + 1, pdata[4].indexOf("</")).split(", ")[0];
    fixname();//from   www .  j ava2  s .  c om
    BTN_index = name.toLowerCase().replaceAll("[^A-Za-z]", "");

    jersey = NumberUtils.toInt(pdata[1].substring(1, pdata[1].indexOf("&")));

    position = pdata[3].substring(1, 2);
    age = NumberUtils.toInt(pdata[4].substring(1, pdata[4].indexOf("&")));

    if (!temp[1].contains("unknown")) {
        team = temp[1].substring(temp[1].indexOf(">") + 1, temp[1].indexOf("</"));
    }

    gp = NumberUtils.toInt(temp[2].substring(1, temp[2].indexOf("<") - 1));
    goals = NumberUtils.toInt(temp[3].substring(1, temp[3].indexOf("<") - 1));
    assists = NumberUtils.toInt(temp[4].substring(1, temp[4].indexOf("<") - 1));
    points = NumberUtils.toInt(temp[5].substring(1, temp[5].indexOf("<") - 1));
    plusminus = NumberUtils.toInt(temp[6].substring(1, temp[6].indexOf("<") - 1));
    pim = NumberUtils.toInt(temp[7].substring(1, temp[7].indexOf("<") - 1));
    hits = NumberUtils.toInt(temp[8].substring(1, temp[8].indexOf("<") - 1));
    blocks = NumberUtils.toInt(temp[9].substring(1, temp[9].indexOf("<") - 1));
    ppg = NumberUtils.toInt(temp[10].substring(1, temp[10].indexOf("<") - 1));
    ppa = NumberUtils.toInt(temp[11].substring(1, temp[11].indexOf("<") - 1));
    shg = NumberUtils.toInt(temp[12].substring(1, temp[12].indexOf("<") - 1));
    sha = NumberUtils.toInt(temp[13].substring(1, temp[13].indexOf("<") - 1));
    stp = ppg + ppa + shg + sha;
    esp = points - stp;
    gwg = NumberUtils.toInt(temp[14].substring(1, temp[14].indexOf("<") - 1));
    sog = NumberUtils.toInt(temp[15].substring(1, temp[15].indexOf("<") - 1));
    sht_pcnt = round(Float.parseFloat(temp[16].substring(1, temp[16].indexOf("<") - 1)) * 100, 2);
}

From source file:de.bmarwell.j9kwsolver.J9kwUserAPI.java

/**
 * Gets the apikey users's balance./*from ww  w.j a v  a2  s.  c o  m*/
 * @return - the balance in credits.
 */
public int getBalance() {
    int balance = -1;

    UserBalance ub = new UserBalance();
    ub.setApikey(PropertyService.getProperty("apikey"));

    lock();
    URI scuri = RequestToURI.userBalanceToURI(ub);
    String userbalanceresponse = HttpConnectorFactory.getBodyFromRequest(scuri);
    LOG.debug("User credits as String: {}.", userbalanceresponse);
    unlock();

    if (NumberUtils.isDigits(userbalanceresponse)) {
        balance = NumberUtils.toInt(userbalanceresponse);
        LOG.debug("User credits as int: {}.", balance);
    }

    return balance;
}

From source file:com.blackducksoftware.integration.jira.mocks.issue.PluginConfigurationDetailsMock.java

@Override
public HubServerConfigBuilder createHubServerConfigBuilder() {
    final HubServerConfigBuilderMock configBuilder = new HubServerConfigBuilderMock();

    configBuilder.setHubUrl(getHubUrl());
    configBuilder.setUsername(getHubUsername());
    configBuilder.setPassword(getHubPasswordEncrypted());
    configBuilder.setPasswordLength(NumberUtils.toInt(getHubPasswordLength()));
    configBuilder.setTimeout(getHubTimeoutString());

    configBuilder.setProxyHost(getHubProxyHost());
    configBuilder.setProxyPort(getHubProxyPort());
    configBuilder.setIgnoredProxyHosts(getHubProxyNoHost());
    configBuilder.setProxyUsername(getHubProxyUser());
    configBuilder.setProxyPassword(getHubProxyPassEncrypted());
    configBuilder.setProxyPasswordLength(NumberUtils.toInt(getHubProxyPassLength()));

    return configBuilder;
}

From source file:gov.nih.nci.caintegrator.domain.application.SegmentDataResultValue.java

/**
 * @param segmentDataResultValue to compare
 * @return the comparator code//from   w w w  .ja va  2  s  . co m
 */
public int compareTo(SegmentDataResultValue segmentDataResultValue) {
    int i = 0;
    if (NumberUtils.isNumber(chromosomalLocation.getChromosome())) {
        i = Ints.compare(NumberUtils.toInt(chromosomalLocation.getChromosome()),
                NumberUtils.toInt(segmentDataResultValue.getChromosomalLocation().getChromosome()));
    } else {
        i = chromosomalLocation.getChromosome()
                .compareTo(segmentDataResultValue.getChromosomalLocation().getChromosome());
    }
    if (i == 0) {
        i = Ints.compare(chromosomalLocation.getStartPosition(),
                segmentDataResultValue.getChromosomalLocation().getStartPosition());
    }
    if (i == 0) {
        i = Ints.compare(chromosomalLocation.getEndPosition(),
                segmentDataResultValue.getChromosomalLocation().getEndPosition());
    }
    return i;
}

From source file:com.cognifide.aet.job.common.modifiers.sleep.SleepModifier.java

@Override
public void setParameters(Map<String, String> params) throws ParametersException {
    milliseconds = NumberUtils.toInt(params.get(DURATION_PARAM));
    ParametersValidator.checkRange(milliseconds, 1, MAX_SLEEP_TIME, "Duration time should be greater than 0");
}

From source file:com.netsteadfast.greenstep.struts2.dispatcher.CustomJFreeChartResult.java

@Override
public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
    Object newWidth = ActionContext.getContext().getValueStack().findValue("width");
    Object newHeight = ActionContext.getContext().getValueStack().findValue("height");
    if (NumberUtils.isNumber(String.valueOf(newWidth)) && NumberUtils.isNumber(String.valueOf(newHeight))) {
        int w = NumberUtils.toInt(String.valueOf(newWidth));
        int h = NumberUtils.toInt(String.valueOf(newHeight));
        if (w > MAX_WIDTH) {
            w = MAX_WIDTH;//from   w w  w. java  2  s. com
        }
        if (h > MAX_HEIGHT) {
            h = MAX_HEIGHT;
        }
        if (w < MIN_WIDTH) {
            w = MIN_WIDTH;
        }
        if (h < MIN_HEIGHT) {
            h = MIN_HEIGHT;
        }
        super.setWidth(String.valueOf(w));
        super.setHeight(String.valueOf(h));
        logger.info("reset chart width=" + w + " , heigh=" + h);
    }
    super.doExecute(finalLocation, invocation);
}

From source file:de.bmarwell.j9kwsolver.util.ResponseUtils.java

/**
 * @param response The response sent by the server.
 * @return null if response is null or empty, else a HashMap.
 *///w  ww .  java 2  s . c o  m
public static Map<String, Integer> stringResponseToIntMap(final String response) {
    Map<String, Integer> result = new HashMap<String, Integer>();

    if (StringUtils.isEmpty(response)) {
        /* 
         * Response should be like so:
         * worker=15|avg24h=12s|avg1h=12s|avg15m=13s|avg5m=13s|inwork=8|
         *     queue=0|queue1=0|queue2=0|workermouse=13|
         *     workerconfirm=14|workertext=13
         */
        return null;
    }

    List<String> serverstatelist = Arrays.asList(StringUtils.split(response, '|'));

    /* Iterate each item in response */
    for (String item : serverstatelist) {
        String[] keyValue = StringUtils.split(item, '=');
        int value = 0;

        if (keyValue.length != 2) {
            LOG.warn("Key-Value splitting on '=' doesn't return 2 items: {}.", item);
            continue;
        }

        String key = keyValue[0];
        String textvalue = keyValue[1];
        textvalue = StringUtils.removeEnd(textvalue, "s");

        if (!NumberUtils.isDigits(textvalue)) {
            LOG.warn("Key-Value where value is non-numeric: {}", item);
            continue;
        } else {
            value = NumberUtils.toInt(textvalue);
        }

        result.put(key, value);
    }

    return result;
}

From source file:com.awcoleman.ExampleJobSummaryLogWithOutput.BinRecRecordReader.java

@Override
public boolean nextKeyValue() throws InterruptedException {

    /*      out.writeUTF( RandomStringUtils.randomAlphabetic(10) );
    out.writeLong( ++recid );//from ww  w .  ja  v a2 s . c  o  m
    out.writeInt( rangen.nextInt(32) );
    out.writeInt( rangen.nextInt(3600) );
    out.writeUTF( generateDatetime() );
     */
    try {
        BinRecForPartitions datum = BinRecForPartitions.newBuilder().setName(fsin.readUTF())
                .setRecid(fsin.readLong()).setEventType(fsin.readInt()).setEventDurationSec(fsin.readInt())
                .setEndDatetime(fsin.readUTF()).setEndDate("UNK").setEndHour(-1).build();

        //Still need endDate,endHour before wrapping in Avro wrapper
        String thisEndDatetime = datum.getEndDatetime().toString();
        String thisEndDate = thisEndDatetime.substring(0, 4) + "-" + thisEndDatetime.substring(4, 6) + "-"
                + thisEndDatetime.substring(6, 8);
        int thisEndHour = NumberUtils.toInt(thisEndDatetime.substring(8, 10));

        datum.setEndDate(thisEndDate);
        datum.setEndHour(thisEndHour);

        //update val
        val = new AvroValue<BinRecForPartitions>(datum);

        //update key
        key.set(key.get() + 1L);

        //Update pos for progress status
        pos = fsin.getPos();

        return true;
    } catch (IOException ioe) {
        return false;
    }
}