List of usage examples for java.lang Integer decode
public static Integer decode(String nm) throws NumberFormatException
From source file:com.prowidesoftware.swift.model.SwiftBlockUser.java
/** * Returns the block number (if it can be converted to an integer, -1 otherwise). * @return Integer containing the block's name as an integer or -1 if the block name is not numeric *///www . ja va 2s . com public Integer getNumber() { // assume -1 (not numeric) and try to convert Integer blockNumber = new Integer(-1); try { blockNumber = Integer.decode(blockName); } catch (NumberFormatException fe) { } ; return (blockNumber); }
From source file:com.github.jessemull.microflexbigdecimal.plate.WellPrecursor.java
/** * Creates a new Well object using the numerical type flag, row number and * column string.// w ww . j a v a 2 s .c om * @param int the numerical data type * @param int the well row * @param String the well column * @throws IllegalArgumentException invalid column value */ public WellPrecursor(int type, int row, String column) { this.row = row; this.type = type; try { this.column = Integer.decode(column); } catch (Exception e) { throw new IllegalArgumentException("Illegal column value: " + column); } validateIndices(this.row, this.column); }
From source file:org.apache.struts.validator.validwhen.ValidWhenParser.java
public final void integer() throws RecognitionException, TokenStreamException { Token d = null;//w ww . j a va2 s .c o m Token h = null; Token o = null; switch (LA(1)) { case DECIMAL_LITERAL: { d = LT(1); match(DECIMAL_LITERAL); argStack.push(Integer.decode(d.getText())); break; } case HEX_LITERAL: { h = LT(1); match(HEX_LITERAL); argStack.push(Integer.decode(h.getText())); break; } case OCTAL_LITERAL: { o = LT(1); match(OCTAL_LITERAL); argStack.push(Integer.decode(o.getText())); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } }
From source file:uni.bielefeld.cmg.sparkhit.util.ParameterForCluster.java
public DefaultParam importCommandLine() { /* Assigning Parameter ID to an ascending number */ putParameterID();/*from w ww . j av a 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(WINDOW)) != null) { param.window = 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 (cl.hasOption(CACHE)) { param.cache = true; } if ((value = cl.getOptionValue(MODELS)) != null) { param.model = Integer.decode(value); } if ((value = cl.getOptionValue(CLUSTER)) != null) { param.clusterNum = Integer.decode(value); } if ((value = cl.getOptionValue(ITERATION)) != null) { param.iterationNum = Integer.decode(value); } 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:uni.bielefeld.cmg.sparkhit.util.ParameterForRegressioner.java
public DefaultParam importCommandLine() { /* Assigning Parameter ID to an ascending number */ putParameterID();// w w w . j a va2 s. c o 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(WINDOW)) != null) { param.window = 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 (cl.hasOption(CACHE)) { param.cache = true; } if ((value = cl.getOptionValue(MODELS)) != null) { param.model = Integer.decode(value); } if ((value = cl.getOptionValue(ITERATION)) != null) { param.iterationNum = Integer.decode(value); } 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"); } if ((value = cl.getOptionValue(INPUT_TRAIN)) != null) { param.inputTrainPath = value; } else { help.printStatisticerHelp(); System.exit(0); } /* 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:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.SpeedometerMultiValue.java
/** * set parameters for the creation of the chart getting them from template or from LOV. * /*from ww w . j a va2 s . 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"); 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_INTERVAL); String max = (String) param.getAttribute(MAX_INTERVAL); String col = (String) param.getAttribute(COLOR_INTERVAL); 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); } } //reading values colors if present SourceBean colors = (SourceBean) content.getAttribute(VALUES_COLORS); if (colors != null) { colorMap = new HashMap(); List atts = colors.getContainedAttributes(); String colorValue = ""; for (Iterator iterator = atts.iterator(); iterator.hasNext();) { SourceBeanAttribute object = (SourceBeanAttribute) iterator.next(); String valueName = new String(object.getKey()); colorValue = new String((String) object.getValue()); Color col = new Color(Integer.decode(colorValue).intValue()); if (col != null) { colorMap.put(valueName, col); } } } } 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); } } //reading values colors if present String valuesNumber = (String) sbRow.getAttribute("series_number"); colorMap = new HashMap(); if (valuesNumber != null && !valuesNumber.equals("") && !valuesNumber.equals("0")) { for (int i = 1; i <= Integer.valueOf(valuesNumber).intValue(); i++) { String valueName = (String) sbRow.getAttribute("value_name" + (new Integer(i)).toString()); String colorValue = (String) sbRow.getAttribute("value_color" + (new Integer(i)).toString()); Color col = new Color(Integer.decode(colorValue).intValue()); if (col != null) { colorMap.put(valueName, col); } } } } logger.debug("out"); }
From source file:org.fire.platform.util.DateUtil.java
public static int getNowDay() { return Integer.decode(getTime("yyyyMMdd", new Date())); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java
public void configureChart(SourceBean content) { logger.debug("IN"); super.configureChart(content); try {/*from w w w . j a v a 2 s . com*/ xLowerBound = confParameters.get(X_LOWER_BOUND) != null ? Double.valueOf(confParameters.get(X_LOWER_BOUND).toString()) : null; xUpperBound = confParameters.get(X_UPPER_BOUND) != null ? Double.valueOf(confParameters.get(X_UPPER_BOUND).toString()) : null; yLowerBound = confParameters.get(Y_LOWER_BOUND) != null ? Double.valueOf(confParameters.get(Y_LOWER_BOUND).toString()) : null; yUpperBound = confParameters.get(Y_UPPER_BOUND) != null ? Double.valueOf(confParameters.get(Y_UPPER_BOUND).toString()) : null; scaleLowerBound = confParameters.get(SCALE_LOWER_BOUND) != null ? Double.valueOf(confParameters.get(SCALE_LOWER_BOUND).toString()) : null; scaleUpperBound = confParameters.get(SCALE_UPPER_BOUND) != null ? Double.valueOf(confParameters.get(SCALE_UPPER_BOUND).toString()) : null; logger.debug("Configuration found: xLowerBound = " + xLowerBound + "xUpperBound = " + xUpperBound + "yLowerBound = " + yLowerBound + "yUpperBound = " + yUpperBound + "scaleLowerBound = " + scaleLowerBound + "scaleUpperBound = " + scaleUpperBound); } catch (Exception e) { logger.error("Error in converting lower and upepr Bounds: use automatic Bounds ", e); xLowerBound = null; xUpperBound = null; yLowerBound = null; yUpperBound = null; scaleLowerBound = null; scaleUpperBound = null; } Object blocHeightOb = confParameters.get(BLOCK_HEIGHT); Object blocWidthOb = confParameters.get(BLOCK_WIDTH); try { blockWidth = Double.valueOf(blocWidthOb.toString()); blockHeight = Double.valueOf(blocHeightOb.toString()); } catch (Exception e) { logger.error( "Error in converting block_width and block height parameters: they should be double instead they are block_width=" + blockWidth + " and block_height=" + blockHeight, e); throw new RuntimeException( "Error in converting block_width and block height parameters: they should be double instead they are block_width=" + blockWidth + " and block_height=" + blockHeight, e); } logger.debug( "BLock dimension by template are block_width=" + blockWidth + " and block_height=" + blockHeight); SourceBean zranges = (SourceBean) content.getAttribute("ZRANGES"); if (zranges != null && zranges.getAttributeAsList("RANGE") != null) { logger.debug("Z Ranges defined in template"); List ranges = zranges.getAttributeAsList("RANGE"); int rangesNum = ranges.size(); zRangeArray = new ZRange[rangesNum]; Iterator rangesIter = ranges.iterator(); int num = 0; for (Iterator iterator = ranges.iterator(); iterator.hasNext();) { SourceBean range = (SourceBean) iterator.next(); String label = (String) range.getAttribute("label"); String colour = (String) range.getAttribute("colour"); Color col = null; try { col = new Color(Integer.decode(colour).intValue()); } catch (Exception e) { logger.error("Could not convert " + colour + " into a color", e); throw new RuntimeException("Could not convert " + colour + " into a color", e); } String value = (String) range.getAttribute("value"); Double valueD = null; try { valueD = Double.valueOf(value); } catch (Exception e) { logger.error("Could not convert " + value + " into a double", e); throw new RuntimeException("Could not convert " + value + " into a double", e); } if (minScaleValue == null) minScaleValue = valueD; if (maxScaleValue == null) maxScaleValue = valueD; if (valueD < minScaleValue) { minScaleValue = valueD; } if (valueD > maxScaleValue) { maxScaleValue = valueD; } ZRange zRange = new ZRange(label, valueD, col); zRangeArray[num] = zRange; num++; } grayPaintScale = false; } else { logger.debug("Z Ranges not defined in template, use gray scale as default"); grayPaintScale = true; } logger.debug("OUT"); }
From source file:edu.cornell.mannlib.vedit.util.FormUtils.java
public static List<Option> makeOptionListFromBeans(List beanList, String valueField, String bodyField, String selectedValue, String selectedBody, boolean forceSelectedInclusion) { List<Option> optList = new LinkedList(); if (beanList == null) return optList; Iterator beanIt = beanList.iterator(); boolean foundSelectedValueInBeans = false; while (beanIt.hasNext()) { Object bean = beanIt.next(); String value = ""; Method valueMeth = null;/*from ww w .ja v a 2 s. co m*/ Object valueObj = null; try { valueMeth = bean.getClass().getMethod("get" + valueField, (Class[]) null); valueObj = valueMeth.invoke(bean, (Object[]) null); } catch (Exception e) { log.warn("Could not find method get" + valueField + " on " + bean.getClass()); } if (valueObj != null) { value = valueObj.toString(); } String body = ""; Method bodyMeth = null; Object bodyObj = null; try { bodyMeth = bean.getClass().getMethod("get" + bodyField, (Class[]) null); bodyObj = bodyMeth.invoke(bean, (Object[]) null); } catch (Exception e) { log.warn(" could not find method get" + bodyField); } if (bodyObj != null) { body = bodyObj.toString(); } Option opt = new Option(); opt.setValue(value); opt.setBody(body); if (selectedValue != null) { if (selectedValue.equals(value)) { opt.setSelected(true); foundSelectedValueInBeans = true; } } else { if (selectedBody != null) { if (selectedBody.equals(body)) { opt.setSelected(true); foundSelectedValueInBeans = true; } } } optList.add(opt); } // if the list of beans doesn't include the selected value/body, // insert it anyway so we don't inadvertently change the value of the // field to the first thing that happens to be in the select list boolean skipThisStep = !forceSelectedInclusion; // For now, if the value is a negative integer, we won't try to // preserve it, as the bean was probably just instantiated. // Should switch to a more robust way of handling inital bean values. if (selectedValue == null) { skipThisStep = true; } else { try { int selectedValueInt = Integer.decode(selectedValue); if (selectedValueInt < 0) skipThisStep = true; } catch (NumberFormatException e) { } } if (!foundSelectedValueInBeans && !skipThisStep) { log.trace("Adding the selected option!"); Option sOpt = new Option(); sOpt.setValue(selectedValue); if (selectedBody == null || selectedBody.length() == 0) sOpt.setBody(selectedValue.toString()); else sOpt.setBody(selectedBody); sOpt.setSelected(true); optList.add(sOpt); } return optList; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.RestrictionOperationController.java
private void processCreate(VitroRequest request, EditProcessObject epo, OntModel origModel) { Model temp = ModelFactory.createDefaultModel(); Model dynamicUnion = ModelFactory.createUnion(temp, origModel); OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, dynamicUnion); OntProperty onProperty = ontModel.getOntProperty((String) request.getParameter("onProperty")); String conditionTypeStr = request.getParameter("conditionType"); String restrictionTypeStr = (String) epo.getAttribute("restrictionType"); Restriction rest = null;//from www . ja v a 2 s . co m OntClass ontClass = ontModel.getOntClass((String) epo.getAttribute("VClassURI")); String roleFillerURIStr = request.getParameter("ValueClass"); Resource roleFiller = null; if (roleFillerURIStr != null) { roleFiller = ontModel.getResource(roleFillerURIStr); } int cardinality = -1; String cardinalityStr = request.getParameter("cardinality"); if (cardinalityStr != null) { cardinality = Integer.decode(cardinalityStr); } if (restrictionTypeStr.equals("allValuesFrom")) { rest = ontModel.createAllValuesFromRestriction(null, onProperty, roleFiller); } else if (restrictionTypeStr.equals("someValuesFrom")) { rest = ontModel.createSomeValuesFromRestriction(null, onProperty, roleFiller); } else if (restrictionTypeStr.equals("hasValue")) { String valueURI = request.getParameter("ValueIndividual"); if (valueURI != null) { Resource valueRes = ontModel.getResource(valueURI); if (valueRes != null) { rest = ontModel.createHasValueRestriction(null, onProperty, valueRes); } } else { String valueLexicalForm = request.getParameter("ValueLexicalForm"); if (valueLexicalForm != null) { String valueDatatype = request.getParameter("ValueDatatype"); Literal value = null; if (valueDatatype != null && valueDatatype.length() > 0) { RDFDatatype dtype = null; try { dtype = TypeMapper.getInstance().getSafeTypeByName(valueDatatype); } catch (Exception e) { log.warn("Unable to get safe type " + valueDatatype + " using TypeMapper"); } if (dtype != null) { value = ontModel.createTypedLiteral(valueLexicalForm, dtype); } else { value = ontModel.createLiteral(valueLexicalForm); } } else { value = ontModel.createLiteral(valueLexicalForm); } rest = ontModel.createHasValueRestriction(null, onProperty, value); } } } else if (restrictionTypeStr.equals("minCardinality")) { rest = ontModel.createMinCardinalityRestriction(null, onProperty, cardinality); } else if (restrictionTypeStr.equals("maxCardinality")) { rest = ontModel.createMaxCardinalityRestriction(null, onProperty, cardinality); } else if (restrictionTypeStr.equals("cardinality")) { rest = ontModel.createCardinalityRestriction(null, onProperty, cardinality); } if (conditionTypeStr.equals("necessary")) { ontClass.addSuperClass(rest); } else if (conditionTypeStr.equals("necessaryAndSufficient")) { ontClass.addEquivalentClass(rest); } origModel.add(temp); }