List of usage examples for java.lang Double doubleValue
@HotSpotIntrinsicCandidate public double doubleValue()
From source file:rb.app.QNTransientRBSystem.java
/** * Evaluate theta_c (for the quadratic nonlinearity) at the current parameter. *///from w w w . j av a2 s . c o m public double eval_theta_c() { Method meth; try { Class partypes[] = new Class[1]; partypes[0] = double[].class; meth = mAffineFnsClass.getMethod("evaluateC", partypes); } catch (NoSuchMethodException nsme) { throw new RuntimeException("getMethod for evaluateC failed", nsme); } Double theta_val; try { Object arglist[] = new Object[1]; arglist[0] = current_parameters.getArray(); Object theta_obj = meth.invoke(mTheta, arglist); theta_val = (Double) theta_obj; } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } return theta_val.doubleValue(); }
From source file:de.hybris.platform.order.impl.DefaultCalculationService.java
protected void addAbsoluteEntryTaxValue(final long entryQuantity, final TaxValue taxValue, final Map<TaxValue, Map<Set<TaxValue>, Double>> taxValueMap) { Map<Set<TaxValue>, Double> taxGroupMap = taxValueMap.get(taxValue); Double quantitySum = null; final Set<TaxValue> absoluteTaxGroupKey = Collections.singleton(taxValue); if (taxGroupMap == null) { taxGroupMap = new LinkedHashMap<Set<TaxValue>, Double>(4); taxValueMap.put(taxValue, taxGroupMap); } else {//from w w w . j a v a2s . c om quantitySum = taxGroupMap.get(absoluteTaxGroupKey); } taxGroupMap.put(absoluteTaxGroupKey, Double.valueOf((quantitySum != null ? quantitySum.doubleValue() : 0) + entryQuantity)); }
From source file:edu.pitt.gis.uniapp.UniApp.java
/** * Get double property for activity.//from ww w . ja va 2 s. c om * * @param name * @param defaultValue * @return */ public double getDoubleProperty(String name, double defaultValue) { Bundle bundle = this.getIntent().getExtras(); if (bundle == null) { return defaultValue; } Double p; try { p = (Double) bundle.get(name); } catch (ClassCastException e) { p = Double.parseDouble(bundle.get(name).toString()); } if (p == null) { return defaultValue; } return p.doubleValue(); }
From source file:org.apache.carbondata.core.scan.filter.FilterUtil.java
/** * This method will compare double values for its equality and also it will preserve * the -0.0 and 0.0 equality as per == ,also preserve NaN equality check as per * java.lang.Double.equals()/*from ww w . jav a 2s.co m*/ * * @param d1 double value for equality check * @param d2 double value for equality check * @return boolean after comparing two double values. */ public static boolean nanSafeEqualsDoubles(Double d1, Double d2) { if ((d1.doubleValue() == d2.doubleValue()) || (Double.isNaN(d1) && Double.isNaN(d2))) { return true; } return false; }
From source file:com.phonegap.DroidGap.java
/** * Get double property for activity./*w ww.j a va 2 s . co m*/ * * @param name * @param defaultValue * @return */ public double getDoubleProperty(String name, double defaultValue) { Bundle bundle = this.getIntent().getExtras(); if (bundle == null) { return defaultValue; } Double p = (Double) bundle.get(name); if (p == null) { return defaultValue; } return p.doubleValue(); }
From source file:com.oneops.ops.dao.PerfDataAccessor.java
public void writeBucket(PerfEvent perfEvent) throws IOException { Mutator<byte[]> mutator = createMutator(keyspace, bytesSerializer); String columnKey = perfEvent.getCiId() + ":" + perfEvent.getGrouping(); String aggregate = translateBucket(perfEvent.getBucket()); String shard = aggregate.substring(aggregate.length() - 3).replace("-", ""); int ttl = getTTL(shard); String dataCF = DATA_CF + "_" + shard; if (isTestMode) dataCF += "_test"; if (perfEvent.getMetrics().getAvg() != null) { for (String key : perfEvent.getMetrics().getAvg().keySet()) { Double value = perfEvent.getMetrics().getAvg().get(key); String bucketKey = columnKey + ":" + key + ":" + aggregate; long bucketEndTime = perfEvent.getTimestamp(); logger.debug("write " + dataCF + ' ' + bucketKey + " " + bucketEndTime + ":" + value); HColumn<Long, Double> column = createDataColumn(bucketEndTime, value.doubleValue()); column.setTtl(ttl);// ww w .j a v a 2 s . c o m mutator.addInsertion(bucketKey.getBytes(), dataCF, column); } } if (perfEvent.getMetrics().getMin() != null) { for (String key : perfEvent.getMetrics().getMin().keySet()) { Double value = perfEvent.getMetrics().getMin().get(key); String bucketKey = columnKey + ":" + key + ":" + aggregate; long bucketEndTime = perfEvent.getTimestamp(); logger.debug("write " + dataCF + ' ' + bucketKey + " " + bucketEndTime + ":" + value); HColumn<Long, Double> column = createDataColumn(bucketEndTime, value.doubleValue()); column.setTtl(ttl); mutator.addInsertion(bucketKey.getBytes(), dataCF, column); } } if (perfEvent.getMetrics().getMax() != null) { for (String key : perfEvent.getMetrics().getMax().keySet()) { Double value = perfEvent.getMetrics().getMax().get(key); String bucketKey = columnKey + ":" + key + ":" + aggregate; long bucketEndTime = perfEvent.getTimestamp(); logger.debug("write " + dataCF + ' ' + bucketKey + " " + bucketEndTime + ":" + value); HColumn<Long, Double> column = createDataColumn(bucketEndTime, value.doubleValue()); column.setTtl(ttl); mutator.addInsertion(bucketKey.getBytes(), dataCF, column); } } // perform the insert/updates mutator.execute(); }
From source file:org.sakaiproject.tool.gradebook.test.GradebookServiceInternalTest.java
public void testStudentRebuff() throws Exception { setAuthnId(INSTRUCTOR_UID);// w ww .j a v a2 s.c o m // Score the unreleased assignment. gradebookService.setAssignmentScoreString(GRADEBOOK_UID, ASN_TITLE, STUDENT_IN_SECTION_UID, new String("39"), "Service Test"); // Try to get a list of assignments as the student. setAuthnId(STUDENT_IN_SECTION_UID); try { if (log.isInfoEnabled()) log.info("Ignore the upcoming authorization errors..."); gradebookService.getAssignments(GRADEBOOK_UID); fail(); } catch (SecurityException e) { } // And then try to get the score. Double score; try { score = new Double( gradebookService.getAssignmentScoreString(GRADEBOOK_UID, ASN_TITLE, STUDENT_IN_SECTION_UID)); fail(); } catch (SecurityException e) { } // Now release the assignment. setAuthnId(INSTRUCTOR_UID); org.sakaiproject.tool.gradebook.Assignment assignment = gradebookManager.getAssignment(asnId); assignment.setReleased(true); gradebookManager.updateAssignment(assignment); // Now see if the student gets lucky. setAuthnId(STUDENT_IN_SECTION_UID); score = new Double( gradebookService.getAssignmentScoreString(GRADEBOOK_UID, ASN_TITLE, STUDENT_IN_SECTION_UID)); Assert.assertTrue(score.doubleValue() == 39.0); }
From source file:omero.util.IceMapper.java
public RType toRType(Object o) throws omero.ApiUsageException { if (o == null) { return null; } else if (o instanceof RType) { return (RType) o; } else if (o instanceof Boolean) { Boolean b = (Boolean) o; omero.RBool bool = rbool(b.booleanValue()); return bool; } else if (o instanceof Date) { Date date = (Date) o; omero.RTime time = rtime(date.getTime()); return time; } else if (o instanceof Integer) { Integer i = (Integer) o; omero.RInt rint = rint(i);/*from w ww.ja v a2 s.co m*/ return rint; } else if (o instanceof Long) { Long lng = (Long) o; omero.RLong rlng = rlong(lng.longValue()); return rlng; } else if (o instanceof Float) { Float flt = (Float) o; omero.RFloat rflt = rfloat(flt); return rflt; } else if (o instanceof Double) { Double dbl = (Double) o; omero.RDouble rdbl = rdouble(dbl.doubleValue()); return rdbl; } else if (o instanceof String) { String str = (String) o; omero.RString rstr = rstring(str); return rstr; } else if (o instanceof IObject) { IObject obj = (IObject) o; omero.model.IObject om = (omero.model.IObject) map(obj); omero.RObject robj = robject(om); return robj; } else if (o instanceof Collection) { List<RType> l = new ArrayList<RType>(); for (Object i : (Collection) o) { l.add(toRType(i)); } return rlist(l); } else if (o instanceof Map) { Map<?, ?> mIn = (Map) o; Map<String, RType> mOut = new HashMap<String, RType>(); for (Object k : mIn.keySet()) { if (!(k instanceof String)) { throw new omero.ValidationException(null, null, "Map key not a string"); } mOut.put((String) k, toRType(mIn.get(k))); } return rmap(mOut); } else if (o instanceof omero.Internal) { return rinternal((omero.Internal) o); } else { throw new ApiUsageException(null, null, "Unsupported conversion to rtype from " + o.getClass().getName() + ":" + o); } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.StackedBarGroup.java
/** * Override this functions from BarCharts beacuse I manage a group of stacked bar! * /*from w ww .j a v a2 s. c o m*/ * @return the dataset * * @throws Exception the exception */ public DatasetMap calculateValue() throws Exception { logger.debug("IN"); String res = DataSetAccessFunctions.getDataSetResultFromId(profile, getData(), parametersObject); categories = new LinkedHashMap(); subCategories = new LinkedHashMap(); subCategoryNames = new ArrayList(); categoryNames = new ArrayList(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); SourceBean sbRows = SourceBean.fromXMLString(res); List listAtts = sbRows.getAttributeAsList("ROW"); // run all categories (one for each row) categoriesNumber = 0; seriesNames = new Vector(); //categories.put(new Integer(0), "All Categories"); boolean first = true; for (Iterator iterator = listAtts.iterator(); iterator.hasNext();) { SourceBean category = (SourceBean) iterator.next(); List atts = category.getContainedAttributes(); HashMap myseries = new LinkedHashMap(); HashMap additionalValues = new LinkedHashMap(); String catValue = ""; String nameP = ""; String value = ""; if (first) { if (name.indexOf("$F{") >= 0) { setTitleParameter(atts); } if (getSubName() != null && getSubName().indexOf("$F") >= 0) { setSubTitleParameter(atts); } first = false; } //run all the attributes, to define series! int contSer = 0; for (Iterator iterator2 = atts.iterator(); iterator2.hasNext();) { SourceBeanAttribute object = (SourceBeanAttribute) iterator2.next(); nameP = new String(object.getKey()); value = new String((String) object.getValue()); if (nameP.equalsIgnoreCase("x")) { catValue = value; categoriesNumber++; categories.put(new Integer(categoriesNumber), value); if (!categoryNames.contains(value)) { categoryNames.add(value); realCatNumber++; } } else if (nameP.equalsIgnoreCase("x2")) { subCategoriesNumber++; subCategories.put(new Integer(subCategoriesNumber), value); if (!subCategoryNames.contains(value)) { subCategoryNames.add(value); realSubCatNumber++; } } else { if (nameP.startsWith("add_") || nameP.startsWith("ADD_")) { if (additionalLabels) { String ind = nameP.substring(4); additionalValues.put(ind, value); } } else { if (this.getNumberSerVisualization() > 0 && contSer < this.getNumberSerVisualization()) { myseries.put(nameP, value); contSer++; } else if (this.getNumberSerVisualization() == 0) myseries.put(nameP, value); } // for now I make like if addition value is checked he seek for an attribute with name with value+name_serie } } for (Iterator iterator3 = myseries.keySet().iterator(); iterator3.hasNext();) { String nameS = (String) iterator3.next(); if (!hiddenSeries.contains(nameS)) { String valueS = (String) myseries.get(nameS); Double valueD = null; try { valueD = Double.valueOf(valueS); } catch (Exception e) { logger.warn("error in double conversion, put default to null"); valueD = null; } String subcat = (String) subCategoryNames.get(realSubCatNumber - 1); //dataset.addValue(Double.valueOf(valueS).doubleValue(), value, catValue); dataset.addValue(valueD != null ? valueD.doubleValue() : null, subcat, catValue); // System.out.println("dataset.addValue("+Double.valueOf(valueS).doubleValue()+ ", '"+subcat+"'"+",'"+catValue+"');"); if (!seriesNames.contains(nameS)) { seriesNames.add(nameS); } // if there is an additional label are if (additionalValues.get(nameS) != null) { String val = (String) additionalValues.get(nameS); String index = catValue + "-" + nameS; String totalVal = val; catSerLabels.put(index, totalVal); } } } } logger.debug("OUT"); DatasetMap datasets = new DatasetMap(); datasets.addDataset("1", dataset); return datasets; }
From source file:org.apache.asterix.test.aql.TestExecutor.java
private boolean equalStrings(String expected, String actual, boolean regexMatch) { String[] rowsExpected = expected.split("\n"); String[] rowsActual = actual.split("\n"); for (int i = 0; i < rowsExpected.length; i++) { String expectedRow = rowsExpected[i]; String actualRow = rowsActual[i]; if (regexMatch) { if (actualRow.matches(expectedRow)) { continue; }/* w w w.j a v a2 s. co m*/ } else if (actualRow.equals(expectedRow)) { continue; } String[] expectedFields = expectedRow.split(" "); String[] actualFields = actualRow.split(" "); boolean bagEncountered = false; Set<String> expectedBagElements = new HashSet<>(); Set<String> actualBagElements = new HashSet<>(); for (int j = 0; j < expectedFields.length; j++) { if (j >= actualFields.length) { return false; } else if (expectedFields[j].equals(actualFields[j])) { bagEncountered = expectedFields[j].equals("{{"); if (expectedFields[j].startsWith("}}")) { if (regexMatch) { if (expectedBagElements.size() != actualBagElements.size()) { return false; } int[] expectedHits = new int[expectedBagElements.size()]; int[] actualHits = new int[actualBagElements.size()]; int k = 0; for (String expectedElement : expectedBagElements) { int l = 0; for (String actualElement : actualBagElements) { if (actualElement.matches(expectedElement)) { expectedHits[k]++; actualHits[l]++; } l++; } k++; } for (int m = 0; m < expectedHits.length; m++) { if (expectedHits[m] == 0 || actualHits[m] == 0) { return false; } } } else if (!expectedBagElements.equals(actualBagElements)) { return false; } bagEncountered = false; expectedBagElements.clear(); actualBagElements.clear(); } } else if (expectedFields[j].indexOf('.') < 0) { if (bagEncountered) { expectedBagElements.add(expectedFields[j].replaceAll(",$", "")); actualBagElements.add(actualFields[j].replaceAll(",$", "")); continue; } return false; } else { // If the fields are floating-point numbers, test them // for equality safely expectedFields[j] = expectedFields[j].split(",")[0]; actualFields[j] = actualFields[j].split(",")[0]; try { Double double1 = Double.parseDouble(expectedFields[j]); Double double2 = Double.parseDouble(actualFields[j]); float float1 = (float) double1.doubleValue(); float float2 = (float) double2.doubleValue(); if (Math.abs(float1 - float2) == 0) { continue; } else { return false; } } catch (NumberFormatException ignored) { // Guess they weren't numbers - must simply not be equal return false; } } } } return true; }