Example usage for java.lang Double doubleValue

List of usage examples for java.lang Double doubleValue

Introduction

In this page you can find the example usage for java.lang Double doubleValue.

Prototype

@HotSpotIntrinsicCandidate
public double doubleValue() 

Source Link

Document

Returns the double value of this Double object.

Usage

From source file:de.walware.statet.r.core.rsource.ast.RAst.java

public static Float toJavaFloat(RAstNode node) {
    while (node != null) {
        switch (node.getNodeType()) {
        case NUM_CONST:
            switch (node.getOperator(0)) {
            case NUM_NUM: {
                final Double num = parseNum(node.getText());
                if (num != null && Math.abs(num.doubleValue()) <= Float.MAX_VALUE) {
                    return num.floatValue();
                }//  w w  w  . j av a  2  s . c  om
                break;
            }
            case NUM_INT: {
                final Integer num = parseInt(node.getText());
                if (num != null) {
                    return num.floatValue();
                }
                break;
            }
            case TRUE:
                return 1f;
            case FALSE:
                return 0f;
            default:
                break;
            }
            return null;
        case F_CALL_ARG:
            node = ((FCall.Arg) node).getValueChild();
            continue;
        default:
            return null;
        }
    }
    return null;
}

From source file:de.walware.statet.r.core.rsource.ast.RAst.java

public static Double toJavaDouble(RAstNode node) {
    while (node != null) {
        switch (node.getNodeType()) {
        case NUM_CONST:
            switch (node.getOperator(0)) {
            case NUM_NUM: {
                final Double num = parseNum(node.getText());
                if (num != null) {
                    return num.doubleValue();
                }/*w  ww. j  av a 2  s . c o  m*/
                break;
            }
            case NUM_INT: {
                final Integer num = parseInt(node.getText());
                if (num != null) {
                    return num.doubleValue();
                }
                break;
            }
            case TRUE:
                return 1.0;
            case FALSE:
                return 0.0;
            default:
                break;
            }
            return null;
        case F_CALL_ARG:
            node = ((FCall.Arg) node).getValueChild();
            continue;
        default:
            return null;
        }
    }
    return null;
}

From source file:org.kalypso.ogc.sensor.diagview.grafik.GrafikLauncher.java

/**
 * Converts a diagram template file to a grafik tpl.
 * <p>//from  w  w  w.  java  2  s.  c o m
 * Important note: the XML-Schema for the diag template file says that if no curve element or specified for a given observation, then all curves of that observation should be displayed. This is not
 * possible here using the grafik tool. As a conclusion: when a template file is meant to be used with the grafik tool, then curves need to be explicitely specified in the xml.
 */
private static RememberForSync[] odt2tpl(final Obsdiagview odt, final IFolder dest, final Writer writer,
        final IProgressMonitor monitor) throws CoreException, IOException {
    final List<RememberForSync> sync = new ArrayList<>();

    final UrlResolver urlRes = new UrlResolver();
    final URL context = ResourceUtilities.createURL(dest.getParent());

    final GrafikAchsen gAchsen = new GrafikAchsen(odt.getAxis());
    final GrafikKurven gKurven = new GrafikKurven(gAchsen);

    Date xLower = null;
    Date xUpper = null;
    Number yLower = new Double(Double.MAX_VALUE);
    Number yUpper = new Double(-Double.MAX_VALUE);
    final Set<XLine> xLines = new TreeSet<>();
    final Map<Double, ValueAndColor> yLines = new HashMap<>();

    // set the timezone of the dateformat
    if (odt.getTimezone() != null && odt.getTimezone().length() > 0) {
        // FIXME: changing static data here....
        final TimeZone timeZone = TimeZone.getTimeZone(odt.getTimezone());
        GRAFIK_DF.setTimeZone(timeZone);
    }

    final Logger logger = Logger.getLogger(GrafikLauncher.class.getName());

    final IStatusCollector stati = new StatusCollector(KalypsoGisPlugin.getId());

    int cc = 1;
    final TypeObservation[] tobs = odt.getObservation().toArray(new TypeObservation[0]);
    for (final TypeObservation element : tobs) {
        // now try to locate observation file
        final URL url = urlRes.resolveURL(context, element.getHref());
        final IFile zmlFile = ResourceUtilities.findFileFromURL(url);

        // if file cannot be found, that probably means it is not local...
        // maybe make a better test later?
        if (zmlFile == null) {
            final String msg = Messages.getString("org.kalypso.ogc.sensor.diagview.grafik.GrafikLauncher.18") //$NON-NLS-1$
                    + url.toExternalForm();
            logger.warning(msg);
            stati.add(IStatus.WARNING, msg);
            continue;
        }

        final IObservation obs;
        final ITupleModel values;
        try {
            obs = ZmlFactory.parseXML(zmlFile.getLocationURI().toURL());
            values = obs.getValues(null);
        } catch (final Exception e) {
            final String msg = Messages.getString("org.kalypso.ogc.sensor.diagview.grafik.GrafikLauncher.19") //$NON-NLS-1$
                    + zmlFile.getName()
                    + Messages.getString("org.kalypso.ogc.sensor.diagview.grafik.GrafikLauncher.20") //$NON-NLS-1$
                    + e.getLocalizedMessage();
            logger.warning(msg);
            stati.add(IStatus.WARNING, msg, e);
            continue;
        }

        // find out which axes to use
        final IAxis[] axes = obs.getAxes();
        final IAxis dateAxis = ObservationUtilities.findAxisByClass(axes, Date.class);
        // REMARK: we use the version with many classes, so no exception is thrown if now number-axis was found.
        final IAxis[] numberAxes = KalypsoStatusUtils.findAxesByClasses(axes, new Class[] { Number.class },
                true);
        // Just ignore this obs, if it has no number axises
        if (numberAxes.length == 0)
            continue;

        final List<IAxis> displayedAxes = new ArrayList<>(numberAxes.length);

        final List<TypeCurve> curves = element.getCurve();
        for (final TypeCurve tc : curves) {
            // create a corresponding dat-File for the current observation file
            final String datFileProtoName = FileUtilities.nameWithoutExtension(zmlFile.getName()) + "-" + cc //$NON-NLS-1$
                    + ".dat"; //$NON-NLS-1$
            final String datFileName = datFileProtoName.replace(' ', '_');
            final IFile datFile = dest.getFile(datFileName);

            final IAxis axis = gKurven.addCurve(datFile, tc, numberAxes);

            if (axis != null) {
                displayedAxes.add(axis);

                // convert to dat-file, ready to be read by the grafik tool
                zml2dat(values, datFile, dateAxis, axis, monitor);

                final RememberForSync rfs = new RememberForSync(zmlFile, datFile, axis);
                sync.add(rfs);

                cc++;

                try {
                    // fetch Y axis range for placing possible scenario text item
                    final IAxisRange range = values.getRange(axis);

                    if (range != null) {
                        final DoubleComparator dc = new DoubleComparator(0.001);
                        final Number lower = (Number) range.getLower();
                        final Number upper = (Number) range.getUpper();
                        if (dc.compare(lower, yLower) < 0)
                            yLower = lower;
                        if (dc.compare(upper, yUpper) > 0)
                            yUpper = upper;
                    }
                } catch (final SensorException e) {
                    e.printStackTrace();
                }
            } else
                Logger.getLogger(GrafikLauncher.class.getName())
                        .warning(Messages.getString("org.kalypso.ogc.sensor.diagview.grafik.GrafikLauncher.23") //$NON-NLS-1$
                                + tc.getName() + Messages
                                        .getString("org.kalypso.ogc.sensor.diagview.grafik.GrafikLauncher.24")); //$NON-NLS-1$
        }

        try {
            // fetch X axis range for placing possible scenario text item
            final IAxisRange range = values.getRange(dateAxis);
            if (range != null) {
                final Date d1 = (Date) range.getLower();
                final Date d2 = (Date) range.getUpper();

                if (xLower == null || d1.before(xLower))
                    xLower = d1;
                if (xUpper == null || d2.after(xUpper))
                    xUpper = d2;
            }
        } catch (final SensorException e) {
            e.printStackTrace();
        }

        // is this obs a forecast?
        // TODO: check if odt wants forecast to be shown
        final DateRange fr = TimeseriesUtils.isTargetForecast(obs);
        if (fr != null) {
            final String strDate = GRAFIK_DF.format(fr.getFrom());
            xLines.add(new XLine(
                    Messages.getString("org.kalypso.ogc.sensor.diagview.grafik.GrafikLauncher.25") + strDate, //$NON-NLS-1$
                    strDate));
        }

        // does is have Alarmstufen? only check if we are displaying at least a
        // W-axis
        try {
            ObservationUtilities.findAxisByType(displayedAxes.toArray(new IAxis[displayedAxes.size()]),
                    ITimeseriesConstants.TYPE_WATERLEVEL);

            final MetadataList mdl = obs.getMetadataList();
            final String[] mds = TimeseriesUtils.findOutMDAlarmLevel(obs);
            for (final String element2 : mds) {
                final String alarmLevel = mdl.getProperty(element2);
                final Double value = NumberUtils.parseQuietDouble(alarmLevel);
                yLines.put(value, new ValueAndColor(element2 + " (" + GRAFIK_NF_W.format(value) + ")", //$NON-NLS-1$//$NON-NLS-2$
                        value.doubleValue()));
            }
        } catch (final NoSuchElementException e) {
            // ignored
        }

        displayedAxes.clear();
    }

    writer.write(gKurven.toVorlagentext());
    writer.write("\n"); //$NON-NLS-1$
    writer.write("HTitel:\t" + odt.getTitle() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
    writer.write("xTitel:\t" + gAchsen.getBottomLabel() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
    writer.write("yTitel1:\t" + gAchsen.getLeftLabel() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
    writer.write("yTitel2:\t" + gAchsen.getRightLabel() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$

    // constant vertical lines...
    for (final Object element : xLines) {
        final String strDate = element.toString();
        writer.write("Senkrechte:" + strDate + '\n'); //$NON-NLS-1$
    }

    // constant horizontal lines...
    for (final Object element : yLines.keySet()) {
        final ValueAndColor vac = yLines.get(element);
        writer.write("yKonst:" + GRAFIK_NF_W.format(vac.value) + " " + vac.label + '\n'); //$NON-NLS-1$ //$NON-NLS-2$
    }

    final IStatus status = stati
            .asMultiStatusOrOK(Messages.getString("org.kalypso.ogc.sensor.diagview.grafik.GrafikLauncher.17")); //$NON-NLS-1$
    if (!status.isOK())
        throw new CoreException(status);

    final RememberForSync[] syncs = sync.toArray(new RememberForSync[sync.size()]);
    return syncs;
}

From source file:msi.gaml.operators.Maths.java

@operator(value = IKeyword.DIVIDE, can_be_const = true, category = { IOperatorCategory.ARITHMETIC })
@doc(value = "Returns a float, equal to the division of the left-hand operand by the rigth-hand operand.", see = "*")
public static Double opDivide(final Integer a, final Double b) throws GamaRuntimeException {
    if (b.equals(0.0)) {
        throw GamaRuntimeException.error("Division by zero");
    }//from   ww  w.  ja  v a  2s  . c  o m
    return a.doubleValue() / b.doubleValue();
}

From source file:org.fenixedu.academic.ui.renderers.student.enrollment.bolonha.EnrolmentLayout.java

static public void addCreditsDistributionMessage(final CurriculumGroup group, final ExecutionSemester semester,
        final StringBuilder result) {

    final Double approved = group.getAprovedEctsCredits();
    final Double concluded = CurriculumModuleServices.getCreditsConcluded(group, semester.getExecutionYear())
            .doubleValue();//from  w w w .j a  v  a2 s.c o  m

    if (approved.doubleValue() != concluded.doubleValue()) {
        result.append(" <span class=\"wrongCreditsDistributionError\" title=\"");
        result.append(BundleUtil.getString(Bundle.APPLICATION, "label.curriculumGroup.wrongCreditsDistribution",
                approved.toString(), concluded.toString()));
        result.append(" \"> ! </span>");
    }
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.importer.ExcelImportUtilities.java

private static String getNumericCellContentAsString(Cell cell, ProcessingLog processingLog) {
    // for numeric cells / dates we have to look at the cell format to tell if it's a date cell
    // If so, we retrieve the value as a date and convert it to ISO String notation

    if (HSSFDateUtil.isCellDateFormatted(cell)) {
        // is it a date-formatted number? then return the ISO-formatted date instead of the number
        Date cellDate = contentAsDate(cell);
        final SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return dateformatter.format(cellDate);
    }/*from ww w  .  j av a 2  s  .co  m*/

    Double d = null;
    try {
        d = contentAsDouble(cell);
    } catch (NumberFormatException ex) {
        processingLog.warn("Cell [{0}] {1}; ignoring the value", getCellRef(cell), ex.getMessage());
    } catch (IllegalStateException e) {
        processingLog.warn("Cell [{0}] {1}; ignoring the value", getCellRef(cell), e.getMessage());
    }

    if (d != null) {
        // cut off *.0
        double i = d.doubleValue() - d.intValue();

        if (i == 0) {
            Integer j = Integer.valueOf(d.intValue());
            return j.toString();
        } else {
            return d.toString();
        }
    }
    return "";
}

From source file:edu.byu.nlp.stats.SymmetricDirichletMLEFPOptimizable.java

/** {@inheritDoc} */
@Override/*from   w  w  w .  j  a va  2s .  c  om*/
public ValueAndObject<Double> computeNext(Double alphaD) {
    double alpha = alphaD.doubleValue();
    double s = K * alpha;
    double denom = (K - 1) / s - Gamma.digamma(s) + Gamma.digamma(s / K);
    double nextS = (K - 1) / denom;
    double nextAlpha = nextS / K;
    if (nextAlpha <= 0.0) {
        throw new IllegalStateException("Fixed-point update failed; alpha = " + nextAlpha);
    }

    double value = N * (Gamma.logGamma(nextS) + nextAlpha * DoubleArrays.sum(meanLogTheta)
            - K * Gamma.logGamma(nextAlpha));
    return new ValueAndObject<Double>(value, nextAlpha);
}

From source file:com.nzion.util.UtilMisc.java

/** Converts an <code>Object</code> to a <code>double</code>. Returns
 * zero if conversion is not possible./*from   ww w . ja  v  a 2 s . co  m*/
 * @param obj Object to convert
 * @return double value
 */
public static double toDouble(Object obj) {
    Double result = toDoubleObject(obj);
    return result == null ? 0.0 : result.doubleValue();
}

From source file:org.fhcrc.honeycomb.metapop.RandomNumberUser.java

public int getNextBinomial(int n, Double p) {
    return rng.nextBinomial(n, p.doubleValue());
}

From source file:org.jcurl.model.PathSet.java

public PathSegment getCurve(double t0) {
    Map.Entry prev = null;//ww  w . j a  va2s.  co m
    for (Iterator it = pieces.entrySet().iterator(); it.hasNext();) {
        final Map.Entry e = (Map.Entry) it.next();
        final Double t = (Double) e.getKey();
        if (t.doubleValue() > t0) {
            if (prev == null)
                prev = e;
            break;
        }
        prev = e;
    }
    if (prev == null)
        return null;
    return (PathSegment) prev.getValue();
}