Example usage for java.lang Integer decode

List of usage examples for java.lang Integer decode

Introduction

In this page you can find the example usage for java.lang Integer decode.

Prototype

public static Integer decode(String nm) throws NumberFormatException 

Source Link

Document

Decodes a String into an Integer .

Usage

From source file:org.opendaylight.ovsdb.plugin.ConnectionService.java

public void init() {
    ovsdbConnections = new ConcurrentHashMap<String, Connection>();
    int listenPort = defaultOvsdbPort;
    String portString = System.getProperty(OVSDB_LISTENPORT);
    if (portString != null) {
        listenPort = Integer.decode(portString).intValue();
    }//  www .ja va2s  . c  o  m
    ovsdbListenPort = listenPort;

    // Keep the default value if the property is not set
    if (System.getProperty(OVSDB_AUTOCONFIGURECONTROLLER) != null)
        autoConfigureController = Boolean.getBoolean(OVSDB_AUTOCONFIGURECONTROLLER);
}

From source file:org.soaplab.clients.ClientConfig.java

/**************************************************************************
 * If the key is found but its value is not an integer, or if it
 * is not found at all, it returns the given default value. <p>
 **************************************************************************/
public static int getInt(String key, int defaultValue) {

    String strValue = get().getString(key, "" + defaultValue);
    try {/*from w  w w . j a v  a  2  s . co m*/
        return Integer.decode(strValue).intValue();
    } catch (NumberFormatException e) {
        return defaultValue;
    }
}

From source file:org.kie.workbench.common.forms.migration.legacy.services.impl.FormSerializationManagerImpl.java

public Form deserializeForm(Node nodeForm) throws Exception {
    if (!nodeForm.getNodeName().equals(NODE_FORM)) {
        return null;
    }//from  w  w  w  . j  ava2s .  c o  m

    Form form = new Form();
    form.setId(Long.valueOf(
            StringEscapeUtils.unescapeXml(nodeForm.getAttributes().getNamedItem(ATTR_ID).getNodeValue())));

    Set<Field> fields = new TreeSet<>();
    NodeList childNodes = nodeForm.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getNodeName().equals(NODE_PROPERTY)) {
            String propName = node.getAttributes().getNamedItem(ATTR_NAME).getNodeValue();
            String value = StringEscapeUtils
                    .unescapeXml(node.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue());

            if ("subject".equals(propName)) {
                form.setSubject(value);
            } else if ("name".equals(propName)) {
                form.setName(value);
            } else if ("displayMode".equals(propName)) {
                form.setDisplayMode(value);
            } else if ("labelMode".equals(propName)) {
                form.setLabelMode(value);
            } else if ("showMode".equals(propName)) {
                form.setShowMode(value);
            } else if ("status".equals(propName)) {
                form.setStatus(Long.valueOf(value));
            } else if ("formTemplate".equals(propName)) {
                form.setFormTemplate(value);
            } else if ("migrationStep".equals(propName)) {
                form.setMigrationStep(Integer.decode(value));
            }
        } else if (node.getNodeName().equals(NODE_FIELD)) {
            Field field = deserializeField(node);
            field.setForm(form);
            fields.add(field);
        } else if (node.getNodeName().equals(NODE_DATA_HOLDER)) {
            String holderId = getNodeAttributeValue(node, ATTR_ID);
            String holderInputId = getNodeAttributeValue(node, ATTR_INPUT_ID);
            String holderOutId = getNodeAttributeValue(node, ATTR_OUT_ID);
            String holderType = getNodeAttributeValue(node, ATTR_TYPE);
            String holderValue = getNodeAttributeValue(node, ATTR_VALUE);
            String holderRenderColor = getNodeAttributeValue(node, ATTR_NAME);
            String holderSupportedType = getNodeAttributeValue(node, ATTR_SUPPORTED_TYPE);

            DataHolder dataHolder = new DataHolder(holderId, holderInputId, holderOutId, holderType,
                    holderValue, holderRenderColor, holderSupportedType);

            form.setDataHolder(dataHolder);
        }
    }
    if (fields != null) {
        form.setFormFields(fields);
    }
    return form;
}

From source file:uni.bielefeld.cmg.sparkhit.util.ParameterForChisquareTester.java

public DefaultParam importCommandLine() {

    /* Assigning Parameter ID to an ascending number */
    putParameterID();/*from w ww  .  j  a va 2  s  . co m*/

    /* Assigning parameter descriptions to each parameter ID */
    addParameterInfo();

    /* need a Object parser of PosixParser class for the function parse of CommandLine class */
    PosixParser parser = new PosixParser();

    /* print out help information */
    HelpParam help = new HelpParam(parameter, parameterMap);

    /* check each parameter for assignment */
    try {
        long input_limit = -1;
        int threads = Runtime.getRuntime().availableProcessors();

        /* Set Object cl of CommandLine class for Parameter storage */
        CommandLine cl = parser.parse(parameter, arguments, true);
        if (cl.hasOption(HELP)) {
            help.printStatisticerHelp();
            System.exit(0);
        }

        if (cl.hasOption(HELP2)) {
            help.printStatisticerHelp();
            System.exit(0);
        }

        if (cl.hasOption(VERSION)) {
            System.exit(0);
        }

        /* Checking all parameters */

        String value;

        if ((value = cl.getOptionValue(PARTITIONS)) != null) {
            param.partitions = Integer.decode(value);
        }

        if ((value = cl.getOptionValue(COLUMN)) != null) {
            param.columns = value;
            param.columnStart = Integer.decode(value.split("-")[0]);
            param.columnEnd = Integer.decode(value.split("-")[1]);
        } else {
            param.columnStart = Integer.decode(param.columns.split("-")[0]);
            param.columnEnd = Integer.decode(param.columns.split("-")[1]);
        }

        if ((value = cl.getOptionValue(COLUMN2)) != null) {
            param.columns2 = value;
            param.column2Start = Integer.decode(value.split("-")[0]);
            param.column2End = Integer.decode(value.split("-")[1]);
        } else {
            param.column2Start = Integer.decode(param.columns.split("-")[0]);
            param.column2End = Integer.decode(param.columns.split("-")[1]);
        }

        if (cl.hasOption(CACHE)) {
            param.cache = true;
        }

        if ((value = cl.getOptionValue(INPUT_VCF)) != null) {
            param.inputFqPath = value;
        } else if ((value = cl.getOptionValue(INPUT_TAB)) != null) {
            param.inputFqPath = value;
        } else {
            help.printStatisticerHelp();
            System.exit(0);
            //                throw new IOException("Input file not specified.\nUse -help for list of options");
        }

        /* not applicable for HDFS and S3 */
        /* using TextFileBufferInput for such purpose */
        //         File inputFastq = new File(param.inputFqPath).getAbsoluteFile();
        //         if (!inputFastq.exists()){
        //            err.println("Input query file not found.");
        //            return;
        //i         }

        if ((value = cl.getOptionValue(OUTPUT_LINE)) != null) {
            param.outputPath = value;
        } else {
            help.printStatisticerHelp();
            info.readMessage("Output file not set with -outfile options");
            info.screenDump();
            System.exit(0);
        }

        File outfile = new File(param.outputPath).getAbsoluteFile();
        if (outfile.exists()) {
            info.readParagraphedMessages(
                    "Output file : \n\t" + param.outputPath + "\nalready exists, will be overwrite.");
            info.screenDump();
            Runtime.getRuntime().exec("rm -rf " + param.outputPath);
        }

    } catch (IOException e) { // Don`t catch this, NaNaNaNa, U can`t touch this.
        info.readMessage("Parameter settings incorrect.");
        info.screenDump();
        e.printStackTrace();
        System.exit(0);
    } catch (RuntimeException e) {
        info.readMessage("Parameter settings incorrect.");
        info.screenDump();
        e.printStackTrace();
        System.exit(0);
    } catch (ParseException e) {
        info.readMessage("Parameter settings incorrect.");
        info.screenDump();
        e.printStackTrace();
        System.exit(0);
    }

    return param;
}

From source file:io.gromit.geolite2.geonames.CityFinder.java

/**
 * Read cities./* w w w.j av  a 2 s .c o m*/
 *
 * @param citiesLocationUrl the cities location url
 * @return the city finder
 */
private CityFinder readCities(String citiesLocationUrl) {
    ZipInputStream zipis = null;
    CsvParserSettings settings = new CsvParserSettings();
    settings.setSkipEmptyLines(true);
    settings.trimValues(true);
    CsvFormat format = new CsvFormat();
    format.setDelimiter('\t');
    format.setLineSeparator("\n");
    format.setComment('\0');
    format.setCharToEscapeQuoteEscaping('\0');
    format.setQuote('\0');
    settings.setFormat(format);
    CsvParser parser = new CsvParser(settings);
    try {
        zipis = new ZipInputStream(new URL(citiesLocationUrl).openStream(), Charset.forName("UTF-8"));
        ZipEntry zipEntry = zipis.getNextEntry();
        logger.info("reading " + zipEntry.getName());
        if (crc == zipEntry.getCrc()) {
            logger.info("skipp, same CRC");
            return this;
        }
        RTree<City, Geometry> rtreeRead = RTree.create();
        List<String[]> lines = parser.parseAll(new InputStreamReader(zipis, "UTF-8"));
        for (String[] entry : lines) {
            City city = new City();
            city.setGeonameId(Integer.decode(entry[0]));
            city.setName(entry[1]);
            try {
                try {
                    city.setLatitude(Double.valueOf(entry[2]));
                    city.setLongitude(Double.valueOf(entry[3]));
                    rtreeRead = rtreeRead.add(city,
                            Geometries.pointGeographic(city.getLongitude(), city.getLatitude()));
                } catch (NumberFormatException | NullPointerException e) {
                }
                city.setCountryIsoCode(entry[4]);
                city.setSubdivisionOne(entry[5]);
                city.setSubdivisionTwo(entry[6]);
                city.setTimeZone(entry[7]);
            } catch (ArrayIndexOutOfBoundsException e) {
            }
            geonameMap.put(city.getGeonameId(), city);
        }
        this.rtree = rtreeRead;
        logger.info("loaded " + geonameMap.size() + " cities");
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        try {
            zipis.close();
        } catch (Exception e) {
        }
        ;
    }
    return this;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.SBISpeedometer.java

/**
 * set parameters for the creation of the chart getting them from template or from LOV.
 * /*w w w. jav a  2s .c o m*/
 * @param content the content of the template.
 * 
 * @return A chart that displays a value as a dial.
 */

public void configureChart(SourceBean content) {

    super.configureChart(content);

    logger.debug("IN");

    if (!isLovConfDefined) {
        logger.debug("Configuration set in template");
        if (confParameters.get("increment") != null) {
            String increment = (String) confParameters.get("increment");
            setIncrement(Double.valueOf(increment).doubleValue());
        } else {
            logger.error("increment not defined");
            return;
        }
        if (confParameters.get("minor_tick") != null) {
            String minorTickCount = (String) confParameters.get("minor_tick");
            setMinorTickCount(Integer.valueOf(minorTickCount).intValue());
        } else {
            setMinorTickCount(10);
        }

        if (confParameters.get("dialtextuse") != null) {
            String dialtextusetemp = (String) confParameters.get("dialtextuse");
            if (dialtextusetemp.equalsIgnoreCase("true")) {
                dialtextuse = true;
            } else
                dialtextuse = false;
        }

        if (dialtextuse && confParameters.get("dialtext") != null) {
            dialtext = (String) confParameters.get("dialtext");
        }

        //reading intervals information
        SourceBean intervalsSB = (SourceBean) content.getAttribute("INTERVALS");
        if (intervalsSB == null) {
            intervalsSB = (SourceBean) content.getAttribute("CONF.INTERVALS");
        }
        List intervalsAttrsList = null;
        if (intervalsSB != null) {
            intervalsAttrsList = intervalsSB.getContainedSourceBeanAttributes();
        }

        if (intervalsAttrsList == null || intervalsAttrsList.isEmpty()) { // if intervals are not defined realize a single interval
            logger.warn("intervals not defined; default settings");
            KpiInterval interval = new KpiInterval();
            interval.setMin(getLower());
            interval.setMax(getUpper());
            interval.setColor(Color.WHITE);
            addInterval(interval);
        } else {

            Iterator intervalsAttrsIter = intervalsAttrsList.iterator();
            while (intervalsAttrsIter.hasNext()) {
                SourceBeanAttribute paramSBA = (SourceBeanAttribute) intervalsAttrsIter.next();
                SourceBean param = (SourceBean) paramSBA.getValue();
                String min = (String) param.getAttribute("min");
                String max = (String) param.getAttribute("max");
                String col = (String) param.getAttribute("color");

                KpiInterval interval = new KpiInterval();
                interval.setMin(Double.valueOf(min).doubleValue());
                interval.setMax(Double.valueOf(max).doubleValue());

                Color color = new Color(Integer.decode(col).intValue());
                if (color != null) {
                    interval.setColor(color);
                } else {
                    // sets default color
                    interval.setColor(Color.WHITE);
                }
                addInterval(interval);
            }
        }
    } else {
        logger.debug("configuration defined in LOV" + confDataset);
        String increment = (String) sbRow.getAttribute("increment");
        String minorTickCount = (String) sbRow.getAttribute("minor_tick");
        setIncrement(Double.valueOf(increment).doubleValue());
        setMinorTickCount(Integer.valueOf(minorTickCount).intValue());

        String intervalsNumber = (String) sbRow.getAttribute("intervals_number");
        if (intervalsNumber == null || intervalsNumber.equals("") || intervalsNumber.equals("0")) { // if intervals are not specified
            KpiInterval interval = new KpiInterval();
            interval.setMin(getLower());
            interval.setMax(getUpper());
            interval.setColor(Color.WHITE);
            addInterval(interval);
        } else {
            for (int i = 1; i <= Integer.valueOf(intervalsNumber).intValue(); i++) {
                KpiInterval interval = new KpiInterval();
                String min = (String) sbRow.getAttribute("min" + (new Integer(i)).toString());
                String max = (String) sbRow.getAttribute("max" + (new Integer(i)).toString());
                String col = (String) sbRow.getAttribute("color" + (new Integer(i)).toString());
                interval.setMin(Double.valueOf(min).doubleValue());
                interval.setMax(Double.valueOf(max).doubleValue());
                Color color = new Color(Integer.decode(col).intValue());
                interval.setColor(color);
                addInterval(interval);

            }
        }
    }
    logger.debug("out");
}

From source file:org.ohmage.domain.campaign.prompt.SingleChoicePrompt.java

/**
 * Validates that a given value is valid and, if so, converts it into an
 * appropriate object./*from   w w w.  j a va 2  s  . co  m*/
 * 
 * @param value The value to be validated. This must be one of the
 *             following:<br />
 *             <ul>
 *             <li>{@link NoResponse}</li>
 *             <li>{@link Integer} that represents the key of the item the
 *               user chose.</li>
 *             <li>{@link String} that represents:</li>
 *               <ul>
 *                 <li>{@link NoResponse}</li>
 *                 <li>The key of the item the user chose.</li>
 *               <ul>
 *             </ul>
 * 
 * @return An Integer representing a key or a {@link NoResponse} object.
 * 
 * @throws DomainException The value is invalid.
 */
@Override
public Object validateValue(final Object value) throws DomainException {
    Integer keyValue;

    // If it's already a NoResponse value, then return make sure that if it
    // was skipped that it as skippable.
    if (value instanceof NoResponse) {
        if (NoResponse.SKIPPED.equals(value) && (!skippable())) {
            throw new DomainException("The prompt, '" + getId() + "', was skipped, but it is not skippable.");
        }

        return value;
    } else if (value instanceof Integer) {
        keyValue = (Integer) value;
    } else if (value instanceof String) {
        try {
            return NoResponse.valueOf((String) value);
        } catch (IllegalArgumentException notNoResponse) {
            try {
                keyValue = Integer.decode((String) value);
            } catch (NumberFormatException notChoiceKey) {
                throw new DomainException(
                        "The value was not a valid response value for this prompt, '" + getId() + "'.",
                        notChoiceKey);
            }
        }
    } else {
        throw new DomainException(
                "The value is not decodable as a reponse value for prompt '" + getId() + "'.");
    }

    if (!getChoices().keySet().contains(keyValue)) {
        throw new DomainException("The value is not a value choice for prompt '" + getId() + "'.");
    }

    return keyValue;
}

From source file:org.ohmage.domain.campaign.prompt.ChoicePrompt.java

/**
 * Validates that a given condition-value pair's value is a valid key for
 * this prompt./*from  w  w w . j  a v a2  s  .c  o m*/
 * 
 * @param pair The condition-value pair to validate.
 * 
 * @throws DomainException The value of the condition-value pair is not 
 *                      valid.
 */
@Override
public void validateConditionValuePair(final ConditionValuePair pair) throws DomainException {

    try {
        int key = Integer.decode(pair.getValue());

        if (!choices.containsKey(key)) {
            throw new DomainException(
                    "The value for a condition is not a valid key for this choice prompt: " + key);
        }
    } catch (NumberFormatException e) {
        throw new DomainException("The value of the condition is not a number: " + pair.getValue(), e);
    }
}

From source file:com.github.jessemull.microflex.plate.Well.java

/**
 * Creates a new Well object using the numerical type flag, row string and 
 * column number.//from  w  w w.j  a v  a 2 s.c  om
 * @param    int       the numerical data type
 * @param    String    the well row
 * @param    int       the well column
 */
public Well(int type, String row, int column) {

    try {
        this.row = Integer.decode(row);
    } catch (NumberFormatException e) {
        this.row = parseRow(row);
    }

    this.column = column;
    this.type = type;

    validateIndices(this.row, this.column);
}

From source file:com.github.jessemull.microflexbigdecimal.plate.WellPrecursor.java

/**
 * Creates a new Well object using the numerical type flag, row string and 
 * column number.//from  w ww.j  a v a2s. c  o m
 * @param    int       the numerical data type
 * @param    String    the well row
 * @param    int       the well column
 */
public WellPrecursor(int type, String row, int column) {

    try {
        this.row = Integer.decode(row);
    } catch (NumberFormatException e) {
        this.row = parseRow(row);
    }

    this.column = column;
    this.type = type;

    validateIndices(this.row, this.column);
}