List of usage examples for java.lang Double isNaN
public boolean isNaN()
From source file:com.jskaleel.xml.JSONObject.java
/** * Try to convert a string into a number, boolean, or null. If the string * can't be converted, return the string. * * @param string//from w ww . ja v a2 s . c om * A String. * @return A simple JSON value. */ public static Object stringToValue(String string) { Double d; if (string.equals("")) { return string; } if (string.equalsIgnoreCase("true")) { return Boolean.TRUE; } if (string.equalsIgnoreCase("false")) { return Boolean.FALSE; } if (string.equalsIgnoreCase("null")) { return JSONObject.NULL; } /* * If it might be a number, try converting it. If a number cannot be * produced, then the value will just be a string. */ char b = string.charAt(0); if ((b >= '0' && b <= '9') || b == '-') { try { if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) { d = Double.valueOf(string); if (!d.isInfinite() && !d.isNaN()) { return d; } } else { Long myLong = new Long(string); if (string.equals(myLong.toString())) { if (myLong == myLong.intValue()) { return myLong.intValue(); } else { return myLong; } } } } catch (Exception ignore) { } } return string; }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
private double[] boxPlotValues(CoolMapObject object, VNode rowNode, VNode columnNode) { if (rowNode == null || columnNode == null || rowNode.isSingleNode() && columnNode.isSingleNode()) { return null; } else {//ww w. j a v a2s . c o m Integer[] rowIndices; Integer[] colIndices; if (rowNode.isGroupNode()) { rowIndices = rowNode.getBaseIndicesFromCOntology((CMatrix) object.getBaseCMatrices().get(0), COntology.ROW); } else { rowIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)).getIndexOfRowName(rowNode.getName()) }; } if (columnNode.isGroupNode()) { colIndices = columnNode.getBaseIndicesFromCOntology((CMatrix) object.getBaseCMatrices().get(0), COntology.COLUMN); } else { colIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)).getIndexOfColName(columnNode.getName()) }; } //A box plot across all matrices List<CMatrix> matrices = object.getBaseCMatrices(); Double value; ArrayList<Double> values = new ArrayList<Double>(); //add values for (Integer i : rowIndices) { if (i == null || i < 0) { continue; } for (Integer j : colIndices) { if (j == null || j < 0) { continue; } //Double value = (Double) getCoolMapObject().getViewValue(i, j); //This is wrong. it should eb the base matrix value, not the view values for (CMatrix<Double> matrix : matrices) { value = matrix.getValue(i, j); if (value == null || value.isNaN()) { continue; } else { //System.out.println(i + " " + j + " " + v); values.add(value); } } } } if (values.isEmpty()) { return null; } Collections.sort(values); int size = values.size(); double min = values.get(0); double max = values.get(values.size() - 1); double median; if (size % 2 == 0) { median = (values.get(size / 2) + values.get(size / 2 - 1)) / 2; } else { median = (values.get(size / 2)); } double[] valueArray = new double[values.size()]; int c = 0; for (Double d : values) { valueArray[c++] = d.doubleValue(); } Arrays.sort(valueArray); Percentile percentile = new Percentile(); double q1 = percentile.evaluate(valueArray, 25); double q3 = percentile.evaluate(valueArray, 75); // double median = percentile.evaluate(valueArray, 50); return new double[] { min, q1, median, q3, max }; } }
From source file:io.hummer.util.test.GenericTestResult.java
public String getPlottableAverages3D(List<Integer> levels, String[] keyTemplates, ResultType type, String... additionalCommands) { StringBuilder b = new StringBuilder(); NumberFormat f = NumberFormat.getInstance(Locale.US); f.setMinimumFractionDigits(3);//from w ww . j ava 2 s .co m f.setMaximumFractionDigits(3); f.setGroupingUsed(false); for (int l : levels) { for (String t : keyTemplates) { String key = t.replaceAll("<level>", "" + l); Double val = 0.0; if (type == ResultType.THROUGHPUT) val = getThroughput(key); else if (type == ResultType.MEAN) val = getMean(key); if (val.isNaN()) val = 0.0; b.append(f.format(val)); b.append("\n"); } b.append("\n"); } return b.toString(); }
From source file:com.google.acre.script.HostEnv.java
@JSFunction public void async_wait(Double timeout_ms) { long timeout = (LIMIT_EXECUTION_TIME) ? req._deadline - System.currentTimeMillis() - NETWORK_DEADLINE_ADVANCE : ACRE_URLFETCH_TIMEOUT; // XXX consider throwing, or at least warning if this condition fails if (!timeout_ms.isNaN() && timeout_ms.longValue() < timeout) { timeout = timeout_ms.longValue(); }/*from www . j a v a 2s . c o m*/ _async_fetch.wait_on_result(timeout, TimeUnit.MILLISECONDS); }
From source file:com.google.acre.script.HostEnv.java
@SuppressWarnings("unused") @JSFunction//from w w w . j a v a2 s . c om public void urlOpenAsync(String url, String method, Object content, Scriptable headers, Double timeout_ms, boolean system, boolean log_to_user, String response_encoding, boolean no_redirect, Function callback) { //System.out.println((system ? "[system] " : "") + "async: " + url.split("\\?")[0] + " [reentries: " + req._reentries + "]"); if (_async_fetch == null) { throw new JSConvertableException("Async Urlfetch not supported in this enviornment") .newJSException(this); } if (req._reentries > 1) { throw new JSConvertableException("Urlfetch is allowed to re-enter only once").newJSException(this); } if (LIMIT_EXECUTION_TIME && System.currentTimeMillis() > req._deadline) { throw new RuntimeException("Cannot call urlfetch, the script ran out of time"); } // if execution is limited, give the subrequest a shorter deadline so this request can // handle any failure long timeout = (LIMIT_EXECUTION_TIME) ? req._deadline - NETWORK_DEADLINE_ADVANCE : System.currentTimeMillis() + ACRE_URLFETCH_TIMEOUT; if (!timeout_ms.isNaN() && timeout_ms.longValue() < timeout) { timeout = timeout_ms.longValue(); } if (response_encoding == null) response_encoding = "ISO-8859-1"; Map<String, String> header_map = new HashMap<String, String>(); if (headers != null) { Object[] ids = headers.getIds(); for (int i = 0; i < ids.length; i++) { String id = ids[i].toString(); header_map.put(id, headers.get(id, headers).toString()); } } try { new URL(url); } catch (MalformedURLException e) { throw new JSURLError("Malformed URL: " + url).newJSException(this); } long sub_deadline = (LIMIT_EXECUTION_TIME) ? req._deadline - HostEnv.SUBREQUEST_DEADLINE_ADVANCE : ACRE_URLFETCH_TIMEOUT; int reentrances = req._reentries + 1; header_map.put(HostEnv.ACRE_QUOTAS_HEADER, "td=" + sub_deadline + ",r=" + reentrances); try { _async_fetch.make_request(url, method, timeout, header_map, content, system, log_to_user, response_encoding, no_redirect, callback); } catch (Exception e) { throw new JSConvertableException(e.getMessage()).newJSException(this); } }
From source file:net.cbtltd.rest.nextpax.A_Handler.java
/** * Returns if the property is available for the reservation. * /* w w w. j a v a 2 s . co m*/ * @param sqlSession the current SQL session. * @param reservation the reservation for collisions * @return list of collisions */ @Override public boolean isAvailable(SqlSession sqlSession, Reservation reservation) { StringBuilder sb = new StringBuilder(); Date now = new Date(); long time = now.getTime(); String SenderSessionID = time + "bookingnetS"; String ReceiverSessionID = time + "bookingnetR"; String rq; String rs = null; boolean available = false; if (reservation.notActive()) { throw new ServiceException(Error.reservation_state, reservation.getId() + " state " + reservation.getState()); } Product product = sqlSession.getMapper(ProductMapper.class).read(reservation.getProductid()); if (product == null) { throw new ServiceException(Error.product_id, reservation.getProductid()); } if (reservation.noAgentid()) { throw new ServiceException(Error.reservation_agentid); } Party agent = sqlSession.getMapper(PartyMapper.class).read(reservation.getAgentid()); if (agent == null) { throw new ServiceException(Error.party_id, reservation.getAgentid()); } if (reservation.noCustomerid()) { reservation.setCustomerid(Party.NO_ACTOR); } Party customer = sqlSession.getMapper(PartyMapper.class).read(reservation.getCustomerid()); if (customer == null) { throw new ServiceException(Error.reservation_customerid, reservation.getCustomerid()); } try { sb.append("<?xml version='1.0' ?>"); sb.append("<TravelMessage VersionID='1.8N'>"); sb.append(" <Control Language='NL' Test='nee'>"); sb.append(" <SenderSessionID>" + SenderSessionID + "</SenderSessionID>"); sb.append(" <ReceiverSessionID>" + ReceiverSessionID + "</ReceiverSessionID>"); sb.append(" <Date>" + DF.format(new Date()) + "</Date>"); sb.append(" <Time Reliability='zeker'>" + TF.format(new Date()) + "</Time>"); sb.append(" <MessageSequence>1</MessageSequence>"); sb.append(" <SenderID>" + SENDERID + "</SenderID>"); sb.append(" <ReceiverID>NPS001</ReceiverID>"); sb.append(" <RequestID>AvailabilitybookingnetRequest</RequestID>"); sb.append(" <ResponseID>AvailabilitybookingnetResponse</ResponseID>"); sb.append(" </Control>"); sb.append(" <TRequest>"); sb.append(" <AvailabilitybookingnetRequest>"); sb.append(" <PackageDetails WaitListCheck='ja'>"); sb.append(" <AccommodationID>" + "A" + product.getAltid() + "</AccommodationID>"); sb.append(" <ArrivalDate>" + DF.format(reservation.getFromdate()) + "</ArrivalDate>"); sb.append(" <Duration DurationType='dagen'>" + reservation.getDuration(Time.DAY).intValue() + "</Duration>"); sb.append(" </PackageDetails>"); sb.append(" </AvailabilitybookingnetRequest>"); sb.append(" </TRequest>"); sb.append("</TravelMessage>"); rq = sb.toString(); LOG.debug("isAvailable rq: \n" + rq + "\n"); rs = getConnection(rq); LOG.debug("isAvailable rs: \n" + rs + "\n"); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); InputSource inputSource = new InputSource(new StringReader(rs.toString())); Double bookID = (Double) xpath.evaluate("//PackageID", inputSource, XPathConstants.NUMBER); available = !bookID.isNaN(); } catch (Throwable e) { LOG.error(e.getMessage()); } return available; }
From source file:au.gov.ansto.bragg.kakadu.ui.plot.FitPlotPropertiesComposite.java
private void updateParameterGroup(Map<String, Double> parameters, Double quality) { inverseButton.setSelection(fitter.isInverse()); inverseButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent arg0) { }/*from w ww . j a va 2s .co m*/ public void widgetSelected(SelectionEvent arg0) { if (fitter.isInverseAllowed()) inverseButton.setEnabled(isEnabled()); if (inverseButton.getSelection() != fitter.isInverse()) setInverseValue(inverseButton.getSelection()); } }); parameterList.clear(); GridData data; parameterGroup.dispose(); if (removeButton != null) removeButton.dispose(); parameterGroup = new Group(this, SWT.NONE); parameterGroup.setText("Parameters"); GridLayout propertiesGridLayout = new GridLayout(); propertiesGridLayout.numColumns = 2; propertiesGridLayout.marginHeight = 3; propertiesGridLayout.marginWidth = 3; propertiesGridLayout.horizontalSpacing = 3; propertiesGridLayout.verticalSpacing = 3; parameterGroup.setLayout(propertiesGridLayout); data = new GridData(); data.horizontalAlignment = GridData.FILL; data.horizontalSpan = 2; data.grabExcessHorizontalSpace = true; parameterGroup.setLayoutData(data); Label functionLabel = new Label(parameterGroup, SWT.NONE); functionLabel.setText("Function"); data = new GridData(); data.verticalAlignment = GridData.BEGINNING; data.verticalIndent = 3; functionLabel.setLayoutData(data); Text functionText = new Text(parameterGroup, SWT.NONE); functionText.setText(fitter.getFunctionText()); data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; functionText.setLayoutData(data); functionText.setEditable(false); for (Entry<String, Double> entry : parameters.entrySet()) { Label label = new Label(parameterGroup, SWT.NONE); label.setText(entry.getKey()); data = new GridData(); data.verticalAlignment = GridData.BEGINNING; data.verticalIndent = 3; label.setLayoutData(data); Text text = new Text(parameterGroup, SWT.BORDER); text.setData(entry.getKey()); text.setText(String.valueOf(entry.getValue())); data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; text.setLayoutData(data); parameterList.add(text); } Label resolutionlabel = new Label(parameterGroup, SWT.NONE); resolutionlabel.setText("resolution"); data = new GridData(); data.verticalAlignment = GridData.BEGINNING; data.verticalIndent = 3; resolutionlabel.setLayoutData(data); resolutionText = new Text(parameterGroup, SWT.BORDER); resolutionText.setText(String.valueOf(fitter.getResolutionMultiple())); // resolutionText. data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; resolutionText.setLayoutData(data); if (!quality.isNaN()) { Label label = new Label(parameterGroup, SWT.NONE); label.setText("Quality(" + fitter.getFitterType().getValue() + ")"); data = new GridData(); data.verticalAlignment = GridData.BEGINNING; data.verticalIndent = 3; label.setLayoutData(data); Text text = new Text(parameterGroup, SWT.BORDER); text.setText(String.valueOf(quality)); data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; text.setLayoutData(data); } if (fitter.getFunctionType() == FunctionType.AddFunction) { removeButton = new Button(this, SWT.PUSH); removeButton .setText("Remove Function " + fitFunctionCombo.getItem(fitFunctionCombo.getSelectionIndex())); data = new GridData(); data.horizontalAlignment = GridData.FILL; data.verticalAlignment = GridData.FILL; data.horizontalSpan = 2; data.grabExcessHorizontalSpace = true; data.grabExcessVerticalSpace = true; removeButton.setLayoutData(data); removeButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent arg0) { } public void widgetSelected(SelectionEvent arg0) { try { removeFunction(fitFunctionCombo.getItem(fitFunctionCombo.getSelectionIndex())); } catch (Exception e) { plot.handleException(e); } } }); } // parameterGroup.redraw(); // this.redraw(); // parent.redraw(); // redraw(); layout(); if (expandItem != null) { expandItem.setHeight(this.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); } parent.update(); parent.redraw(); // parent.layout(); }