Example usage for org.apache.commons.lang NumberUtils stringToInt

List of usage examples for org.apache.commons.lang NumberUtils stringToInt

Introduction

In this page you can find the example usage for org.apache.commons.lang NumberUtils stringToInt.

Prototype

public static int stringToInt(String str) 

Source Link

Document

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

Usage

From source file:massbank.svn.SVNServiceManager.java

/**
 * Initialization/*  w  ww .java2  s.  c  o  m*/
 */
public void init() throws ServletException {
    this.SVN_BASE_URL = getInitParameter("URL");
    try {
        InputStream stream = getClass().getClassLoader().getResourceAsStream("svn.info");
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
        String data = reader.readLine();
        this.SVN_INFO = Crypt.decrypt("massbank", data);
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
    String[] serviceNames = { "RegistrationCommitter", "MSDBUpdater", "OpenDataUpdater" };
    for (int i = 0; i < serviceNames.length; i++) {
        String val = getInitParameter(serviceNames[i]);
        if (val == null || val.equals("")) {
            continue;
        }
        String[] items = val.split(",");
        String enable = items[0].trim().toLowerCase();
        int startDelay = 0;
        int interval = 0;
        if (items.length == 3) {
            startDelay = NumberUtils.stringToInt(items[1].trim());
            interval = NumberUtils.stringToInt(items[2].trim());
        }
        if (enable.equals("true")) {
            if (serviceNames[i].equals("RegistrationCommitter")) {
                this.committer = new RegistrationCommitter(startDelay, interval);
                this.committer.start();
            }
            if (serviceNames[i].equals("MSDBUpdater")) {
                this.updaterDB = new MSDBUpdater(startDelay, interval);
                this.updaterDB.start();
            }
            if (serviceNames[i].equals("OpenDataUpdater")) {
                this.updaterOpen = new OpenDataUpdater(startDelay, interval);
                this.updaterOpen.start();
            }
        }
    }
}

From source file:org.gocom.components.coframe.framework.AppFunctionService.java

@SuppressWarnings("deprecation")
private IManagedResource adapt(AppFunction function) {
    IManagedResource resource = new DefaultManagedResource(null, function.getFunccode(), function.getFuncname(),
            IAuthConstants.FUNCTION_TO_STATES, IAuthConstants.FUNCTION_TO_RESOURCE_TYPE, null,
            function.getFuncdesc(), true, function.getTenant_id());
    AppApplication application = function.getAppFuncgroup().getAppApplication();
    if (application != null) {
        String appType = application.getApptype();
        String protocolType = application.getProtocoltype();
        String ipAddr = application.getIpaddr();
        String ipPort = application.getIpport();
        if (ipPort == null || "".equals(ipPort)) {
            ipPort = "80";
        }//from www. j a  v a2  s . co  m
        String contextPath = application.getUrl();
        if ("1".equals(appType)) {
            try {
                URL url = new URL(protocolType, ipAddr, NumberUtils.stringToInt(ipPort), contextPath);
                resource.addAttribute(IAppConstants.APP_URL, url.toString());
            } catch (MalformedURLException e) {
                log.error("Get Appurl [appid=" + application.getAppid()
                        + "] failure, please do the operation again or contact the sysadmin.", e);
            }
        }
    }
    resource.addAttribute(IAppConstants.FUNCTION_IS_CHECK, function.getIscheck());
    resource.addAttribute(IAppConstants.FUNCTION_PARA_INFO, function.getParainfo());
    resource.addAttribute(IAppConstants.FUNCTION_URL, function.getFuncaction());
    return resource;
}

From source file:org.talend.dataprofiler.core.ui.editor.preview.model.states.freq.BenfordLawFrequencyStateTest.java

/**
 * Test method for/*from   w w w.j  a  v a2  s .  com*/
 * {@link org.talend.dataprofiler.core.ui.editor.preview.model.states.freq.BenfordLawFrequencyState#sortIndicator(org.talend.dq.indicators.ext.FrequencyExt[])}
 * . just test normal cases: contains 1~9
 */
@SuppressWarnings("deprecation")
@Test
public void testSortIndicator() {
    FrequencyExt[] frequencyExt = new FrequencyExt[9];
    Long value = 100l;
    for (int i = 0; i < 9; i++) {
        frequencyExt[i] = new FrequencyExt();
        frequencyExt[i].setKey(i + 1);
        frequencyExt[i].setValue(value);

        if (i > 4) {
            value = value * 2;
        } else {
            value = value / 2;
        }
    }
    benState.sortIndicator(frequencyExt);
    for (int i = 0; i < 8; i++) {
        // Assert.assertTrue(frequencyExt[i].getValue() > frequencyExt[i + 1].getValue());
        Assert.assertTrue(NumberUtils.stringToInt(frequencyExt[i].getKey().toString()) < NumberUtils
                .stringToInt(frequencyExt[i + 1].getKey().toString()));
    }
}