List of usage examples for java.lang Double intValue
public int intValue()
From source file:com.twosigma.beakerx.kernel.magic.command.functionality.TimeMagicCommand.java
private int getBestNumber(String codeToExecute, boolean showResult, Message message) { for (int value = 0; value < 10;) { Double numberOfExecution = Math.pow(10, value); CompletableFuture<Boolean> keepLooking = new CompletableFuture<>(); Long startTime = System.nanoTime(); IntStream.range(0, numberOfExecution.intValue()).forEach(indexOfExecution -> { SimpleEvaluationObject simpleEvaluationObject = createSimpleEvaluationObject(codeToExecute, kernel, new Message(new Header(message.type(), message.getHeader().getSession())), 0); if (!showResult) { simpleEvaluationObject.noResult(); }/* w w w.jav a 2 s .com*/ kernel.executeCode(codeToExecute, simpleEvaluationObject); if (numberOfExecution.intValue() - 1 == indexOfExecution) { if (TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime) > 0.2) { keepLooking.complete(false); } else { keepLooking.complete(true); } } }); try { if (keepLooking.get()) { value++; } else { return numberOfExecution.intValue(); } } catch (ExecutionException | InterruptedException e) { throw new IllegalStateException("Cannot create best number of execution."); } } throw new IllegalStateException("Cannot create best number of execution."); }
From source file:edu.scripps.fl.pubchem.xml.PopulateArray.java
public List<Panel> getPanelValues(ExcelTableModel tableModel, Map<String, Integer> map, String[] properties) throws IllegalAccessException, InvocationTargetException { List<Panel> panelValues = new ArrayList<Panel>(); for (int row = 0; row < tableModel.getRowCount(); row++) { if (checkIfRowBlank(tableModel, row) == false) { Panel panelValue = new Panel(); List<PanelTarget> panelTargets = new ArrayList<PanelTarget>(); List<Object> panelTargetGis = new ArrayList<Object>(); List<Object> panelTargetTypes = new ArrayList<Object>(); List<Object> panelTargetNames = new ArrayList<Object>(); for (String property : properties) { if (null == map.get(property) && (property.equalsIgnoreCase("panelTargetName"))) continue; Object obj = tableModel.getValueAt(row, map.get(property)); if (obj != null && !"".equals(obj)) { String objSt = obj.toString(); if (!property.equals("panelName")) { if (objSt.contains("|")) { if (!property.equalsIgnoreCase("panelTargetName")) objSt = objSt.replace(" ", ""); String[] listObj = objSt.split("\\|"); if (property.equalsIgnoreCase("panelGene") || property.equalsIgnoreCase("panelTaxonomy")) { List<Integer> listO = new ArrayList<Integer>(); for (String ss : listObj) { Double objDoub = Double.parseDouble(ss); listO.add(objDoub.intValue()); }//from w w w. j a va 2 s . c om obj = listO; } else obj = new ArrayList<String>(Arrays.asList(listObj)); } else { if (property.equalsIgnoreCase("panelGene") || property.equalsIgnoreCase("panelTaxonomy")) { Double objDoub = Double.parseDouble(objSt); obj = new ArrayList<Integer>( Arrays.asList(new Integer[] { objDoub.intValue() })); } else obj = new ArrayList<Object>(Arrays.asList(new Object[] { objSt })); } } if (property.equalsIgnoreCase("panelTargetGi")) panelTargetGis = (List<Object>) obj; else if (property.equalsIgnoreCase("panelTargetType")) panelTargetTypes = (List<Object>) obj; else if (property.equals("panelTargetName")) panelTargetNames = (List<Object>) obj; else BeanUtils.setProperty(panelValue, property, obj); } } if (panelTargetGis.size() > 0 && panelTargetTypes.size() > 0) { for (int ii = 0; ii < panelTargetGis.size(); ii++) { PanelTarget target = new PanelTarget(); Object gi = panelTargetGis.get(ii); Double giD = Double.parseDouble((String) gi); target.setPanelTargetGi(giD.intValue()); if (panelTargetTypes.size() == panelTargetGis.size()) BeanUtils.setProperty(target, "panelTargetType", panelTargetTypes.get(ii)); else BeanUtils.setProperty(target, "panelTargetType", panelTargetTypes.get(0)); panelTargets.add(target); } panelValue.setPanelTarget(panelTargets); } panelValues.add(panelValue); } } return panelValues; }
From source file:org.dkpro.tc.ml.liblinear.serialization.LoadModelConnectorLiblinear.java
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { try {//from w w w .j av a 2 s .co m FeatureStore featureStore = (FeatureStore) Class.forName(featureStoreImpl).newInstance(); List<Instance> inst = TaskUtils.getMultipleInstancesUnitMode(featureExtractors, jcas, true, featureStore.supportsSparseFeatures()); for (Instance i : inst) { featureStore.addInstance(i); } FeatureNodeArrayEncoder encoder = new FeatureNodeArrayEncoder(); FeatureNode[][] nodes = encoder.featueStore2FeatureNode(featureStore); StringBuilder sb = new StringBuilder(); for (int i = 0; i < nodes.length; i++) { List<String> elements = new ArrayList<String>(); for (int j = 0; j < nodes[i].length; j++) { FeatureNode node = nodes[i][j]; int index = node.getIndex(); double value = node.getValue(); // write sparse values, i.e. skip zero values if (Math.abs(value) > 0.00000000001) { elements.add(index + ":" + value); } } sb.append("-1"); // DUMMY value for our outcome sb.append("\t"); sb.append(StringUtils.join(elements, "\t")); sb.append("\n"); } File inputData = File.createTempFile("libLinearePrediction", LiblinearAdapter.getInstance().getFrameworkFilename(AdapterNameEntries.featureVectorsFile)); FileUtils.writeStringToFile(inputData, sb.toString()); Problem predictionProblem = Problem.readFromFile(inputData, 1.0); List<TextClassificationOutcome> outcomes = new ArrayList<>( JCasUtil.select(jcas, TextClassificationOutcome.class)); Feature[][] testInstances = predictionProblem.x; for (int i = 0; i < testInstances.length; i++) { Feature[] instance = testInstances[i]; Double prediction = Linear.predict(liblinearModel, instance); if (learningMode.equals(Constants.LM_REGRESSION)) { outcomes.get(i).setOutcome(prediction.toString()); } else { String predictedLabel = outcomeMapping.get(prediction.intValue()); outcomes.get(i).setOutcome(predictedLabel); } } } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
From source file:massbank.api.ApiParameter.java
/** * searchSpectrum ?\bhp??[^`FbN/*from w w w . ja va 2 s. c om*/ */ private void checkSearchSpectrum() { //--------------------------------------- // tolerance //--------------------------------------- String unit = (String) mapParam.get("unit"); String tolerance = (String) mapParam.get("tolerance"); if (unit.toLowerCase().equals("unit") || unit.equals("")) { param += "&TOLUNIT=unit"; if (tolerance.equals("")) { param += "&TOLERANCE=0.3"; } else { param += "&TOLERANCE=" + tolerance; } } else if (unit.toLowerCase().equals("ppm")) { param += "&TOLUNIT=ppm"; if (tolerance.equals("")) { param += "&TOLERANCE=50"; } else { param += "&TOLERANCE=" + tolerance; } } else { // "unit", "ppm" OG?[ errDetails.add("unit=" + unit); } // ?l`FbN if (!tolerance.equals("") && !NumberUtils.isNumber(tolerance)) { errDetails.add("tolerance=" + tolerance); } //--------------------------------------- // cutoff //--------------------------------------- String cutoff = (String) mapParam.get("cutoff"); if (cutoff.equals("")) { cutoff = "50"; } else if (NumberUtils.isNumber(cutoff)) { int val = Integer.parseInt(cutoff); if (val < 0 || val > 999) { errDetails.add("cutoff=" + cutoff); } } else { errDetails.add("cutoff=" + cutoff); } param += "&CUTOFF=" + cutoff; //--------------------------------------- // m/z, intensity //--------------------------------------- String[] mzs = (String[]) mapParam.get("mzs"); String[] intensities = (String[]) mapParam.get("intensities"); // mzsintensities?`FbN if (mzs.length != intensities.length) { errDetails.add("number of \"mzs\" NOT EQUAL number of \"intensities\""); } else { // ?->x Double maxInte = 0.0; for (int i = 0; i < intensities.length; i++) { Double inte = Double.parseDouble(intensities[i]); if (inte > maxInte) { maxInte = inte; } } String[] relIntensities = new String[intensities.length]; for (int i = 0; i < intensities.length; i++) { if (maxInte != 999) { Double inte = Double.parseDouble(intensities[i]); Double dblRelInte = inte / maxInte * 999 + 0.5; relIntensities[i] = String.valueOf(dblRelInte.intValue()); } else { relIntensities[i] = String.valueOf(intensities[i]); } } String peak = ""; for (int i = 0; i < mzs.length; i++) { peak += mzs[i] + "," + relIntensities[i] + "@"; } param += "&VAL=" + peak; } }
From source file:eu.udig.style.advanced.utils.Utilities.java
/** * Checks if a string is a number (currently Double, Float, Integer). * //from w w w . j a v a 2 s. c o m * @param value the string to check. * @param adaptee the class to check against. If null, the more permissive {@link Double} will be used. * @return the number or null, if the parsing fails. */ @SuppressWarnings("unchecked") public static <T extends Number> T isNumber(String value, Class<T> adaptee) { if (value == null) { return null; } if (adaptee == null) { adaptee = (Class<T>) Double.class; } if (adaptee.isAssignableFrom(Double.class)) { try { Double parsed = Double.parseDouble(value); return adaptee.cast(parsed); } catch (Exception e) { return null; } } else if (adaptee.isAssignableFrom(Float.class)) { try { Float parsed = Float.parseFloat(value); return adaptee.cast(parsed); } catch (Exception e) { return null; } } else if (adaptee.isAssignableFrom(Integer.class)) { try { Integer parsed = Integer.parseInt(value); return adaptee.cast(parsed); } catch (Exception e) { // still try the double Double number = isNumber(value, Double.class); if (number != null) { return adaptee.cast(number.intValue()); } return null; } } else { throw new IllegalArgumentException(); } }
From source file:net.sbbi.upnp.services.UPNPService.java
private void parseSCPD() { try {//w w w . j ava2s . co m DocumentContainer.registerXMLParser(DocumentContainer.MODEL_DOM, new JXPathParser()); UPNPService = new DocumentContainer(SCPDURL, DocumentContainer.MODEL_DOM); JXPathContext context = JXPathContext.newContext(this); Pointer rootPtr = context.getPointer("UPNPService/scpd"); JXPathContext rootCtx = context.getRelativeContext(rootPtr); specVersionMajor = Integer.parseInt((String) rootCtx.getValue("specVersion/major")); specVersionMinor = Integer.parseInt((String) rootCtx.getValue("specVersion/minor")); parseServiceStateVariables(rootCtx); Pointer actionsListPtr = rootCtx.getPointer("actionList"); JXPathContext actionsListCtx = context.getRelativeContext(actionsListPtr); Double arraySize = (Double) actionsListCtx.getValue("count( action )"); UPNPServiceActions = new HashMap(); for (int i = 1; i <= arraySize.intValue(); i++) { ServiceAction action = new ServiceAction(); action.name = (String) actionsListCtx.getValue("action[" + i + "]/name"); action.parent = this; Pointer argumentListPtr = null; try { argumentListPtr = actionsListCtx.getPointer("action[" + i + "]/argumentList"); } catch (JXPathException ex) { // there is no arguments list. } if (argumentListPtr != null) { JXPathContext argumentListCtx = actionsListCtx.getRelativeContext(argumentListPtr); Double arraySizeArgs = (Double) argumentListCtx.getValue("count( argument )"); List orderedActionArguments = new ArrayList(); for (int z = 1; z <= arraySizeArgs.intValue(); z++) { ServiceActionArgument arg = new ServiceActionArgument(); arg.name = (String) argumentListCtx.getValue("argument[" + z + "]/name"); String direction = (String) argumentListCtx.getValue("argument[" + z + "]/direction"); arg.direction = direction.equals(ServiceActionArgument.DIRECTION_IN) ? ServiceActionArgument.DIRECTION_IN : ServiceActionArgument.DIRECTION_OUT; String stateVarName = (String) argumentListCtx .getValue("argument[" + z + "]/relatedStateVariable"); ServiceStateVariable stateVar = (ServiceStateVariable) UPNPServiceStateVariables .get(stateVarName); if (stateVar == null) { throw new IllegalArgumentException( "Unable to find any state variable named " + stateVarName + " for service " + getServiceId() + " action " + action.name + " argument " + arg.name); } arg.relatedStateVariable = stateVar; orderedActionArguments.add(arg); } if (arraySizeArgs.intValue() > 0) { action.setActionArguments(orderedActionArguments); } } UPNPServiceActions.put(action.getName(), action); } parsedSCPD = true; } catch (Throwable t) { throw new RuntimeException("Error during lazy SCDP file parsing at " + SCPDURL, t); } }
From source file:org.apache.zeppelin.lens.LensInterpreter.java
@Override public int getProgress(InterpreterContext context) { if (s_paraToQH.containsKey(context.getParagraphId())) { s_logger.info("number of items for which progress can be reported :" + s_paraToQH.size()); s_logger.info("number of open lensclient :" + s_clientMap.size()); Bootstrap bs = createBootstrap(); JLineShell shell = getJLineShell(bs); LensClient lensClient = null;/*w ww . j a v a2 s . c om*/ String qh = s_paraToQH.get(context.getParagraphId()).getQueryHandle(); try { s_logger.info("fetch query status for : (" + context.getParagraphId() + ") :" + qh); lensClient = createAndSetLensClient(bs); s_clientMap.put(lensClient, true); CommandResult res = shell.executeCommand("query status " + qh); s_logger.info(context.getParagraphId() + " --> " + res.getResult().toString()); //change to debug Pattern pattern = Pattern.compile(".*(Progress : (\\d\\.\\d)).*"); Matcher matcher = pattern.matcher(res.getResult().toString().replaceAll("\\n", " ")); if (matcher.find(2)) { Double d = Double.parseDouble(matcher.group(2)) * 100; if (d.intValue() == 100) { s_paraToQH.remove(context.getParagraphId()); } return d.intValue(); } else { return 1; } } catch (Exception e) { s_logger.error("unable to get progress for (" + context.getParagraphId() + ") :" + qh, e); s_paraToQH.remove(context.getParagraphId()); return 0; } finally { if (lensClient != null) { closeLensClient(lensClient); s_clientMap.remove(lensClient); } if (shell != null) { closeShell(shell); } } } return 0; }
From source file:net.sbbi.upnp.services.UPNPService.java
private void parseServiceStateVariables(JXPathContext rootContext) { Pointer serviceStateTablePtr = rootContext.getPointer("serviceStateTable"); JXPathContext serviceStateTableCtx = rootContext.getRelativeContext(serviceStateTablePtr); Double arraySize = (Double) serviceStateTableCtx.getValue("count( stateVariable )"); UPNPServiceStateVariables = new HashMap(); for (int i = 1; i <= arraySize.intValue(); i++) { ServiceStateVariable srvStateVar = new ServiceStateVariable(); String sendEventsLcl = null; try {//from w w w. j a va 2 s. co m sendEventsLcl = (String) serviceStateTableCtx.getValue("stateVariable[" + i + "]/@sendEvents"); } catch (JXPathException defEx) { // sendEvents not provided defaulting according to specs to "yes" sendEventsLcl = "yes"; } srvStateVar.parent = this; srvStateVar.sendEvents = sendEventsLcl.equalsIgnoreCase("no") ? false : true; srvStateVar.name = (String) serviceStateTableCtx.getValue("stateVariable[" + i + "]/name"); srvStateVar.dataType = (String) serviceStateTableCtx.getValue("stateVariable[" + i + "]/dataType"); try { srvStateVar.defaultValue = (String) serviceStateTableCtx .getValue("stateVariable[" + i + "]/defaultValue"); } catch (JXPathException defEx) { // can happend since default value is not } Pointer allowedValuesPtr = null; try { allowedValuesPtr = serviceStateTableCtx.getPointer("stateVariable[" + i + "]/allowedValueList"); } catch (JXPathException ex) { // there is no allowed values list. } if (allowedValuesPtr != null) { JXPathContext allowedValuesCtx = serviceStateTableCtx.getRelativeContext(allowedValuesPtr); Double arraySizeAllowed = (Double) allowedValuesCtx.getValue("count( allowedValue )"); srvStateVar.allowedvalues = new HashSet(); for (int z = 1; z <= arraySizeAllowed.intValue(); z++) { String allowedValue = (String) allowedValuesCtx.getValue("allowedValue[" + z + "]"); srvStateVar.allowedvalues.add(allowedValue); } } Pointer allowedValueRangePtr = null; try { allowedValueRangePtr = serviceStateTableCtx .getPointer("stateVariable[" + i + "]/allowedValueRange"); } catch (JXPathException ex) { // there is no allowed values list, can happen } if (allowedValueRangePtr != null) { srvStateVar.minimumRangeValue = (String) serviceStateTableCtx .getValue("stateVariable[" + i + "]/allowedValueRange/minimum"); srvStateVar.maximumRangeValue = (String) serviceStateTableCtx .getValue("stateVariable[" + i + "]/allowedValueRange/maximum"); try { srvStateVar.stepRangeValue = (String) serviceStateTableCtx .getValue("stateVariable[" + i + "]/allowedValueRange/step"); } catch (JXPathException stepEx) { // can happend since step is not mandatory } } UPNPServiceStateVariables.put(srvStateVar.getName(), srvStateVar); } }
From source file:com.compomics.util.experiment.identification.psm_scoring.psm_scores.HyperScore.java
/** * Returns the e-value corresponding to a list of scores in a map. If not * enough scores are present or if they are not spread the method returns * null.//from w ww . j av a 2 s .c om * * @param hyperScores the different scores * @param useCache if true the interpolation values will be stored in the * histograms in cache * * @return the e-values corresponding to the given scores */ public HashMap<Double, Double> getEValueMap(ArrayList<Double> hyperScores, boolean useCache) { HashMap<Integer, Integer> histogram = new HashMap<Integer, Integer>(); Double maxScore = 0.0; Double minScore = Double.MAX_VALUE; for (Double score : hyperScores) { Integer intValue = score.intValue(); if (intValue > 0) { Integer nScores = histogram.get(intValue); if (nScores == null) { nScores = 1; } else { nScores++; } histogram.put(intValue, nScores); if (score > maxScore) { maxScore = score; } if (score < minScore) { minScore = score; } } } Integer lowestBin = minScore.intValue(); Integer highestBin = maxScore.intValue(); Integer secondEmptybin = highestBin; Integer firstEmptybin = highestBin; boolean emptyBin = false; for (Integer bin = lowestBin; bin <= highestBin; bin++) { if (!histogram.containsKey(bin)) { if (!emptyBin) { emptyBin = true; firstEmptybin = bin; } else { secondEmptybin = bin; break; } } } ArrayList<Integer> bins = new ArrayList<Integer>(histogram.keySet()); for (Integer bin : bins) { if (bin > secondEmptybin) { histogram.remove(bin); } else if (bin > firstEmptybin) { histogram.put(bin, 1); } } double[] ab = getInterpolationValues(histogram, useCache); if (ab == null) { return null; } return getInterpolation(hyperScores, ab[0], ab[1]); }
From source file:com.demonwav.mcdev.creator.ForgeProjectSettingsWizard.java
private void setForgeVersion() { if (forgeVersion == null) { return;//from w w w. ja v a 2 s .c om } String version = getVersion(); if (version == null) { return; } forgeVersionBox.removeAllItems(); List<String> versions = forgeVersion.getForgeVersions(version); if (versions == null) { return; } versions.stream().sorted((one, two) -> one.compareTo(two) * -1).forEach(forgeVersionBox::addItem); Double promo = forgeVersion.getPromo(version); if (promo != null) { int index = 0; for (int i = 0; i < forgeVersionBox.getItemCount(); i++) { try { if (forgeVersionBox.getItemAt(i).endsWith(String.valueOf(promo.intValue()))) { index = i; } } catch (NumberFormatException ignored) { } } forgeVersionBox.setSelectedIndex(index); } }