List of usage examples for java.lang Integer decode
public static Integer decode(String nm) throws NumberFormatException
From source file:com.aurel.track.fieldType.runtime.custom.select.CustomSelectBaseRT.java
/** * Convert a string to object value/* w ww. j a v a 2 s.com*/ * @param value * @return */ @Override public Object convertFromString(String value) { Object[] result = null; if (value != null) { String[] tokens = value.split(OPTION_SPLITTER_VALUES_STRING); if (tokens != null && tokens.length > 0) { List<Integer> valueList = new ArrayList<Integer>(tokens.length); Integer intValue; for (int i = 0; i < tokens.length; i++) { try { intValue = Integer.decode(tokens[i]); valueList.add(intValue); } catch (Exception e) { //ignore } } LOGGER.debug("convertfromString :" + valueList); result = new Object[valueList.size()]; valueList.toArray(result); } } return result; }
From source file:tax.MainForm.java
private void dateTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dateTextKeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) { if (!dateText.getText().equals("")) { Util.fadeInAndOut(dateText, Util.darkGreen); priceText.setEnabled(true);//from w w w .j a v a 2 s .co m priceText.requestFocus(); } else Util.fadeInAndOut(dateText, Util.darkOrange); } else if (!evt.isActionKey() && !evt.isAltDown() && !evt.isControlDown() && !evt.isShiftDown() && !evt.isMetaDown() && (evt.getKeyCode() != KeyEvent.VK_BACK_SPACE) && (evt.getKeyCode() != KeyEvent.VK_DELETE) && (evt.getKeyCode() != KeyEvent.VK_ESCAPE)) { EventQueue.invokeLater(new Runnable() { @Override public void run() { String text = dateText.getText(); int dateLength = text.length(); while (lastDateTextLength == dateLength) { try { Thread.sleep(100); System.out.println("text: " + text); System.out.println(lastDateTextLength + " " + dateLength); return; } catch (InterruptedException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } text = dateText.getText(); dateLength = text.length(); } try { int num = Integer.decode(text); if (num > 31) { if (text.length() > 0) dateText.setText(text.substring(0, dateLength - 1)); else dateText.setText(""); return; } } catch (Exception e) { if (text.length() > 0) dateText.setText(text.substring(0, dateLength - 1)); else dateText.setText(""); return; } lastDateTextLength = dateLength; } }); } }
From source file:com.comcast.oscar.configurationfile.ConfigurationFileExport.java
/** * /* w ww . j a va 2 s. co m*/ * Example: TLV Dot Notation: 25.1.2 * * @param sTlvDotNotation * @return String*/ public String getTlvDefintion(String sTlvDotNotation) { boolean localDebug = Boolean.FALSE; String sTlvDescription = ""; String sTlvName = ""; String sDisplayHint = ""; List<String> lsTlvDotNotation = new ArrayList<String>(); lsTlvDotNotation = Arrays.asList(sTlvDotNotation.split("\\.")); if (debug | localDebug) System.out.println("ConfigrationFileExport.getTlvDefintion(): " + lsTlvDotNotation.toString()); //Get TLV Dictionary for the Top Level JSONObject joTlvDictionary = dsqDictionarySQLQueries .getTlvDefinition(Integer.decode(lsTlvDotNotation.get(0))); //Search for TLV Definition if (lsTlvDotNotation.size() == 1) { try { sTlvName = joTlvDictionary.getString(Dictionary.TLV_NAME); sTlvDescription = joTlvDictionary.getString(Dictionary.TLV_DESCRIPTION); } catch (JSONException e) { e.printStackTrace(); } sDisplayHint = getDisplayHint(joTlvDictionary); } else if (lsTlvDotNotation.size() >= 1) { int iRecursiveSearch = 0; while (iRecursiveSearch < lsTlvDotNotation.size()) { if (debug | localDebug) System.out.println("ConfigrationFileExport.getTlvDefintion(): WHILE-LOOP"); try { if (joTlvDictionary.getString(Dictionary.TYPE).equals(lsTlvDotNotation.get(iRecursiveSearch))) { if (joTlvDictionary.getBoolean(Dictionary.ARE_SUBTYPES)) { try { JSONArray jaTlvDictionary = joTlvDictionary.getJSONArray(Dictionary.SUBTYPE_ARRAY); for (int iIndex = 0; iIndex < jaTlvDictionary.length(); iIndex++) { if (debug | localDebug) System.out.println("ConfigrationFileExport.getTlvDefintion(): FOR-LOOP"); JSONObject joTlvDictionaryTemp = jaTlvDictionary.getJSONObject(iIndex); if (joTlvDictionaryTemp.getString(Dictionary.TYPE) .equals(lsTlvDotNotation.get(iRecursiveSearch + 1))) { joTlvDictionary = joTlvDictionaryTemp; iRecursiveSearch++; break; } } } catch (JSONException e) { e.printStackTrace(); } } else { sTlvName = joTlvDictionary.getString(Dictionary.TLV_NAME); sTlvDescription = joTlvDictionary.getString(Dictionary.TLV_DESCRIPTION); sDisplayHint = getDisplayHint(joTlvDictionary); iRecursiveSearch++; } } } catch (JSONException e1) { e1.printStackTrace(); } } } return "\n\n" + sTlvName + ":\n\n" + PrettyPrint.ToParagraphForm(sTlvDescription) + "\n\n" + "String Format:\n" + sDisplayHint; }
From source file:org.apache.zookeeper.ZooKeeperMain.java
protected boolean processZKCmd(MyCommandOptions co) throws KeeperException, IOException, InterruptedException { String[] args = co.getArgArray(); String cmd = co.getCommand(); if (args.length < 1) { usage();//from w w w .j av a 2 s . c om return false; } if (!commandMap.containsKey(cmd)) { usage(); return false; } boolean watch = false; LOG.debug("Processing " + cmd); try { if (cmd.equals("quit")) { zk.close(); System.exit(0); } else if (cmd.equals("redo") && args.length >= 2) { Integer i = Integer.decode(args[1]); if (commandCount <= i) { // don't allow redoing this redo System.out.println("Command index out of range"); return false; } cl.parseCommand(history.get(i)); if (cl.getCommand().equals("redo")) { System.out.println("No redoing redos"); return false; } history.put(commandCount, history.get(i)); processCmd(cl); } else if (cmd.equals("history")) { for (int i = commandCount - 10; i <= commandCount; ++i) { if (i < 0) continue; System.out.println(i + " - " + history.get(i)); } } else if (cmd.equals("printwatches")) { if (args.length == 1) { System.out.println("printwatches is " + (printWatches ? "on" : "off")); } else { printWatches = args[1].equals("on"); } } else if (cmd.equals("connect")) { if (args.length >= 2) { connectToZK(args[1]); } else { connectToZK(host); } } // Below commands all need a live connection if (zk == null || !zk.getState().isAlive()) { System.out.println("Not connected"); return false; } // execute from commandMap CliCommand cliCmd = commandMapCli.get(cmd); if (cliCmd != null) { cliCmd.setZk(zk); watch = cliCmd.parse(args).exec(); } else if (!commandMap.containsKey(cmd)) { usage(); } } catch (ParseException ex) { System.err.println(ex.getMessage()); usage(); return false; } return watch; }
From source file:org.simplx.args.MainArgs.java
/** * Returns the argument of the given {@code int} option from the command * line. If the option is not specified, return {@code defaultValue}. The * number is parsed according to {@link Integer#parseInt(String)}, except * that a leading plus sign is accepted. * * @param option The name of the option. * @param defaultValue The value to return if the option is not specified. * @param doc Usage documentation for the option (@see {@link * #getString(String,String,String...) getString}). * * @return The value for the option, or {@code defaultValue}. * * @throws NumberFormatException The argument is not a valid number. * @throws CommandLineException No argument was present. *//*from w w w . j a v a 2 s .c o m*/ public int getInt(String option, int defaultValue, String... doc) throws CommandLineException, NumberFormatException { String str = getArgument(option, "int", doc); try { if (str == null) { return defaultValue; } // ignore leading plus if (str.length() > 0 && str.charAt(0) == '+') { str = str.substring(1); } return Integer.decode(str); } catch (NumberFormatException e) { throw numException(e, option); } }
From source file:org.dawnsci.marketplace.server.MarketplaceServerTest.java
@Test @Sql("/system-test-data.sql") public void testMvcCreateSolution() throws Exception { // log in as administrator user HttpSession session = this.mocMvc .perform(formLogin("/signin/authenticate").user("admin").password("s3cret!")) .andExpect(status().is(302)).andExpect(redirectedUrl("/")).andReturn().getRequest().getSession(); // bring up the new solution form session = this.mocMvc .perform(get("/edit-solution").session((MockHttpSession) session) .accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(status().is(200)).andReturn().getRequest().getSession(); // and post it, being redirected to show the details, most values will // be null.//from w ww . j a va 2 s . com String url = this.mocMvc .perform(post("/edit-solution").with(csrf()).session((MockHttpSession) session) .param("name", "test name").param("supporturl", "http://dawnsci.org") .param("updateurl", "http://dawnsci.org").accept(MediaType.APPLICATION_XHTML_XML)) .andExpect(status().is3xxRedirection()).andReturn().getResponse().getRedirectedUrl(); // test some key values in the new product Integer id = Integer.decode(url.substring(url.lastIndexOf("/") + 1)); ResponseEntity<String> entity = this.restTemplate .getForEntity("http://localhost:" + this.port + "/mpc/content/" + id + "/api/p", String.class); Marketplace m = loadSerializedMarketplace(entity.getBody()); // make sure the update site URL has not changed assertEquals("http://dawnsci.org", m.getNode().getUpdateurl()); }
From source file:org.kchine.r.server.http.RHttpProxy.java
public static void loadimage(String url, String sessionId) throws TunnelingException { GetMethod getInterrupt = null;//from w w w.ja v a2 s .c om try { Object result = null; mainHttpClient = new HttpClient(); if (System.getProperty("proxy_host") != null && !System.getProperty("proxy_host").equals("")) { mainHttpClient.getHostConfiguration().setProxy(System.getProperty("proxy_host"), Integer.decode(System.getProperty("proxy_port"))); } getInterrupt = new GetMethod(url + "?method=loadimage"); try { if (sessionId != null && !sessionId.equals("")) { getInterrupt.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); getInterrupt.setRequestHeader("Cookie", "JSESSIONID=" + sessionId); } mainHttpClient.executeMethod(getInterrupt); result = new ObjectInputStream(getInterrupt.getResponseBodyAsStream()).readObject(); } catch (ConnectException e) { throw new ConnectionFailedException(); } catch (Exception e) { throw new TunnelingException("", e); } if (result != null && result instanceof TunnelingException) { throw (TunnelingException) result; } } finally { if (getInterrupt != null) { getInterrupt.releaseConnection(); } if (mainHttpClient != null) { } } }
From source file:org.dashbuilder.dataprovider.backend.elasticsearch.rest.client.impl.ElasticSearchNativeRESTClient.java
protected int getResponseCode(ActionResponse response) { if (response == null) return RESPONSE_CODE_NOT_FOUND; String responseCode = response.getHeader(HEADER_RESPONSE_CODE); if (responseCode == null) return RESPONSE_CODE_OK; return Integer.decode(responseCode); }
From source file:com.aurel.track.exchange.docx.exporter.AssembleWordprocessingMLPackage.java
private static StringBuilder replaceIssueLinksWithDescription(StringBuilder src, List<Integer> itemIDs) { StringBuilder lsrc = new StringBuilder(src); int startIndex = 0; String paragraph = "<p>"; while ((startIndex = lsrc.toString().indexOf(ISSUE_TAG, startIndex)) != -1) { int endIndex = lsrc.toString().indexOf(CLOSE, startIndex); if (endIndex == -1 || (endIndex <= startIndex)) { lsrc = lsrc.replace(startIndex, startIndex + ISSUE_TAG.length(), EMPTY); } else {//from w w w .ja v a 2 s. com String key = lsrc.substring(startIndex + ISSUE_TAG.length(), endIndex).trim(); try { Integer itemID = Integer.decode(key); LOGGER.debug("ItemID " + itemID + " found"); itemIDs.add(itemID); TWorkItemBean itemBean = null; try { itemBean = ItemBL.loadWorkItem(itemID); } catch (ItemLoaderException e) { LOGGER.warn("Loading the workItemID " + itemID + " failed with " + e.getMessage()); } if (itemBean == null) { lsrc = lsrc.replace(startIndex, endIndex + CLOSE.length(), EMPTY); } else { String description = itemBean.getDescription(); if (description == null || description.length() == 0) { description = itemBean.getSynopsis(); } else { description = exportDescription(description, itemIDs); } if (description == null || description.length() == 0) { break; } //add itemNo before the inline description if (description.startsWith(paragraph)) { description = paragraph + AssembleWordprocessingMLPackage.getItemNo(itemBean) + description.substring(paragraph.length()); } else { description = AssembleWordprocessingMLPackage.getItemNo(itemBean) + description; } lsrc = lsrc.replace(startIndex, endIndex + CLOSE.length(), description); startIndex = startIndex + description.length(); } } catch (NumberFormatException e) { lsrc = lsrc.replace(startIndex, startIndex + ISSUE_TAG.length(), EMPTY); //recalculate end index endIndex = lsrc.toString().indexOf(CLOSE, startIndex); lsrc = lsrc.replace(endIndex, endIndex + CLOSE.length(), EMPTY); } } } return lsrc; }
From source file:gov.nih.nci.caintegrator.application.query.QueryManagementServiceImplTest.java
/** * Tests execution of genomic data queries. * * @throws InvalidCriterionException on invalid criteria */// w w w . j a v a 2s .c o m @Test public void testExecuteGenomicDataQuery() throws InvalidCriterionException { Platform platform = dao.getPlatform("platformName"); Study study = query.getSubscription().getStudy(); StudySubjectAssignment assignment = query.getSubscription().getStudy().getAssignmentCollection().iterator() .next(); SampleAcquisition acquisition = new SampleAcquisition(); Sample sample = new Sample(); acquisition.setAssignment(assignment); sample.getSampleAcquisitions().add(acquisition); GenomicDataSourceConfiguration genomicDataSourceConfiguration = new GenomicDataSourceConfiguration(); genomicDataSourceConfiguration.setExperimentIdentifier(EXP_ID); study.getStudyConfiguration().getGenomicDataSources().add(genomicDataSourceConfiguration); sample.setGenomicDataSource(genomicDataSourceConfiguration); Array array = new Array(); array.setPlatform(platform); ArrayData arrayData = new ArrayData(); arrayData.setStudy(study); arrayData.setArray(array); array.getArrayDataCollection().add(arrayData); arrayData.setSample(sample); sample.getArrayDataCollection().add(arrayData); segmentData.setSegmentValue(.1f); arrayData.getSegmentDatas().add(segmentData); segmentData.setArrayData(arrayData); sample.getArrayCollection().add(array); ArrayData arrayData2 = new ArrayData(); arrayData2.setStudy(study); arrayData2.setSample(sample); arrayData2.setArray(array); segmentData2.setSegmentValue(.4f); arrayData2.getSegmentDatas().add(segmentData2); segmentData2.setArrayData(arrayData2); array.getArrayDataCollection().add(arrayData2); sample.getArrayDataCollection().add(arrayData2); array.getSampleCollection().add(sample); acquisition.setSample(sample); acquisition.setAssignment(assignment); assignment.getSampleAcquisitionCollection().add(acquisition); study.getAssignmentCollection().add(assignment); try { authorizeStudyElements(study.getStudyConfiguration()); } catch (Exception e1) { e1.printStackTrace(); } ////////////////////////////////// // Gene Name Criterion Testing. // ////////////////////////////////// GeneNameCriterion geneNameCriterion = new GeneNameCriterion(); geneNameCriterion.setGenomicCriterionType(GenomicCriterionTypeEnum.GENE_EXPRESSION); Gene gene = new Gene(); gene.setSymbol("GENE"); reporter = new GeneExpressionReporter(); ReporterList reporterList = platform.addReporterList("reporterList", ReporterTypeEnum.GENE_EXPRESSION_PROBE_SET); reporter.setReporterList(reporterList); reporter.getGenes().add(gene); geneNameCriterion.setGeneSymbol("GENE"); query.getCompoundCriterion().getCriterionCollection().add(geneNameCriterion); reporterList.getArrayDatas().add(arrayData); reporterList.getArrayDatas().add(arrayData2); reporterList.getReporters().add(reporter); arrayData.getReporterLists().add(reporterList); reporterList.getArrayDatas().add(arrayData); ReporterList reporterList2 = platform.addReporterList("reporterList2", ReporterTypeEnum.GENE_EXPRESSION_GENE); arrayData2.getReporterLists().add(reporterList2); reporterList2.getArrayDatas().add(arrayData2); query.setReporterType(ReporterTypeEnum.GENE_EXPRESSION_PROBE_SET); geneNameCriterion.setPlatformName("platformName"); query.setResultType(ResultTypeEnum.GENE_EXPRESSION); GenomicDataQueryResult result = queryManagementService.executeGenomicDataQuery(query); assertEquals(1, result.getFilteredRowCollection().size()); assertEquals(1, result.getColumnCollection().size()); assertEquals(1, result.getFilteredRowCollection().iterator().next().getValues().size()); GenomicDataResultColumn column = result.getColumnCollection().iterator().next(); assertNotNull(column.getSampleAcquisition()); assertNotNull(column.getSampleAcquisition().getSample()); ///////////////////////////////////////// // Expression Level Criterion Testing. // ///////////////////////////////////////// ExpressionLevelCriterion expressionLevelCriterion = new ExpressionLevelCriterion(); expressionLevelCriterion.setPlatformName("platformName"); expressionLevelCriterion.setGeneSymbol("GENE"); expressionLevelCriterion.setRangeType(RangeTypeEnum.GREATER_OR_EQUAL); expressionLevelCriterion.setLowerLimit(1f); query.getCompoundCriterion().getCriterionCollection().clear(); query.getCompoundCriterion().getCriterionCollection().add(expressionLevelCriterion); query.getCompoundCriterion().setBooleanOperator(BooleanOperatorEnum.AND); result = queryManagementService.executeGenomicDataQuery(query); assertEquals(1, result.getFilteredRowCollection().size()); assertEquals(1, result.getColumnCollection().size()); assertEquals(1, result.getFilteredRowCollection().iterator().next().getValues().size()); column = result.getColumnCollection().iterator().next(); assertNotNull(column.getSampleAcquisition()); assertNotNull(column.getSampleAcquisition().getSample()); expressionLevelCriterion.setRangeType(RangeTypeEnum.LESS_OR_EQUAL); // No upper limit = always true. result = queryManagementService.executeGenomicDataQuery(query); assertEquals(1, result.getFilteredRowCollection().size()); assertEquals(1, result.getColumnCollection().size()); assertEquals(1, result.getFilteredRowCollection().iterator().next().getValues().size()); expressionLevelCriterion.setUpperLimit(1.1f); result = queryManagementService.executeGenomicDataQuery(query); assertEquals(0, result.getFilteredRowCollection().size()); assertEquals(0, result.getColumnCollection().size()); //////////////////////////////////// // Fold Change Criterion Testing. // //////////////////////////////////// FoldChangeCriterion foldChangeCriterion = new FoldChangeCriterion(); foldChangeCriterion.setFoldsUp(1.0f); foldChangeCriterion.setGeneSymbol("GENE"); foldChangeCriterion.setControlSampleSetName("controlSampleSet1"); foldChangeCriterion.setRegulationType(RegulationTypeEnum.UP); query.getCompoundCriterion().getCriterionCollection().clear(); query.getCompoundCriterion().getCriterionCollection().add(foldChangeCriterion); query.getCompoundCriterion().setBooleanOperator(BooleanOperatorEnum.AND); try { result = queryManagementService.executeGenomicDataQuery(query); fail("Should have caught invalid criterion exception because no control samples in study"); } catch (InvalidCriterionException e) { } SampleSet sampleSet1 = new SampleSet(); sampleSet1.setName("controlSampleSet1"); sampleSet1.getSamples().add(new Sample()); study.getStudyConfiguration().getGenomicDataSources().get(0).getControlSampleSetCollection() .add(sampleSet1); result = queryManagementService.executeGenomicDataQuery(query); assertEquals(1, result.getFilteredRowCollection().size()); foldChangeCriterion.setFoldsDown(1.0f); foldChangeCriterion.setRegulationType(RegulationTypeEnum.DOWN); result = queryManagementService.executeGenomicDataQuery(query); assertEquals(0, result.getFilteredRowCollection().size()); foldChangeCriterion.setRegulationType(RegulationTypeEnum.UP_OR_DOWN); result = queryManagementService.executeGenomicDataQuery(query); assertEquals(1, result.getFilteredRowCollection().size()); foldChangeCriterion.setRegulationType(RegulationTypeEnum.UNCHANGED); result = queryManagementService.executeGenomicDataQuery(query); assertEquals(0, result.getFilteredRowCollection().size()); try { foldChangeCriterion.setGeneSymbol("EGFR"); result = queryManagementService.executeGenomicDataQuery(query); fail("Should have caught invalid criterion exception because genes are not found."); } catch (InvalidCriterionException e) { } ReporterList reporterList3 = platform.addReporterList("reporterList3", ReporterTypeEnum.DNA_ANALYSIS_REPORTER); arrayData.getReporterLists().add(reporterList3); reporterList3.getArrayDatas().add(arrayData); arrayData2.getReporterLists().add(reporterList3); reporterList3.getArrayDatas().add(arrayData2); CopyNumberAlterationCriterion copyNumberCriterion = new CopyNumberAlterationCriterion(); query.setResultType(ResultTypeEnum.COPY_NUMBER); query.getCompoundCriterion().getCriterionCollection().clear(); query.getCompoundCriterion().getCriterionCollection().add(copyNumberCriterion); result = queryManagementService.executeGenomicDataQuery(query); assertEquals(1, result.getFilteredRowCollection().size()); ChromosomalLocation location = new ChromosomalLocation(); location.setStartPosition(1); location.setEndPosition(4); segmentData2.setLocation(location); result = queryManagementService.executeGenomicDataQuery(query); assertEquals(2, result.getFilteredRowCollection().size()); // test copy number - calls value query.getCompoundCriterion().getCriterionCollection().clear(); Set<Integer> callsValues = new HashSet<Integer>(); callsValues.add(Integer.decode("1")); copyNumberCriterion.setCallsValues(callsValues); query.getCompoundCriterion().getCriterionCollection().add(copyNumberCriterion); result = queryManagementService.executeGenomicDataQuery(query); assertEquals(2, result.getFilteredRowCollection().size()); }