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:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java

private static void setCategoryRange(JFreeChart chart, Configuration config) {
    Double rangeLowerBound = config.getRangeLowerBound();
    Double rangeUpperBound = config.getRangeUpperBound();

    if (rangeUpperBound != null) {
        if (chart.getPlot() instanceof SpiderWebPlot) {
            ((SpiderWebPlot) chart.getPlot()).setMaxValue(rangeUpperBound.doubleValue());
            return;
        } else {/*from w w w.j  a v  a  2 s.  co  m*/
            ((CategoryPlot) chart.getPlot()).getRangeAxis().setUpperBound(rangeUpperBound.doubleValue());
        }
    }

    if (rangeLowerBound != null) {
        ((CategoryPlot) chart.getPlot()).getRangeAxis().setLowerBound(rangeLowerBound.doubleValue());
    }
}

From source file:gridool.util.system.SystemUtils.java

public static double getIoWait() {
    if (preferSigar) {
        final Double iowait;
        try {/*from ww w .j  a v  a 2 s . com*/
            iowait = (Double) sigarIoWaitMtd.invoke(sigarCpuPercMtd.invoke(sigarInstance));
        } catch (Exception e) {
            LogFactory.getLog(SystemUtils.class).error("Failed to obtain CPU iowait via Hyperic Sigar", e);
            return -1d;
        }
        return iowait.doubleValue();
    } else {
        return -1d;
    }
}

From source file:gridool.util.system.SystemUtils.java

public static double getCpuLoadAverage() {
    if (preferSigar) {
        final Double cpuload;
        try {//  ww  w .  ja va  2s  .  c  om
            cpuload = (Double) sigarCpuCombinedMtd.invoke(sigarCpuPercMtd.invoke(sigarInstance));
        } catch (Exception e) {
            LogFactory.getLog(SystemUtils.class).error("Failed to obtain CPU load via Hyperic Sigar", e);
            return -1d;
        }
        return cpuload.doubleValue();
    } else {
        OperatingSystemMXBean mx = ManagementFactory.getOperatingSystemMXBean();
        com.sun.management.OperatingSystemMXBean sunmx = (com.sun.management.OperatingSystemMXBean) mx;
        double d = sunmx.getSystemLoadAverage();
        if (d > 0) {
            return d / NPROCS;
        }
        return d;
    }
}

From source file:org.chiba.xml.xforms.xpath.XFormsExtensionFunctions.java

/**
 * The avg() Function [7.7.1]./*www. ja v  a 2s. co m*/
 * <p/>
 * Function avg returns the arithmetic average of the result of
 * converting the string-values of each node in the argument node-set
 * to a number. The sum is computed with sum(), and divided with div
 * by the value computed with count().
 *
 * @param context the expression context.
 * @param nodeset the node-set.
 * @return the computed node-set average.
 */
public static double avg(ExpressionContext context, List nodeset) {
    if ((nodeset == null) || (nodeset.size() == 0)) {
        return Double.NaN;
    }

    JXPathContext rootContext = context.getJXPathContext();
    rootContext.getVariables().declareVariable("nodeset", nodeset);

    Double value = (Double) rootContext.getValue("sum($nodeset) div count($nodeset)", Double.class);

    return value.doubleValue();
}

From source file:de.cosmocode.collections.utility.Convert.java

/**
 * Parses a value of a generic type//from  w  w  w.ja v a 2 s .  c  o m
 * into a double.
 * 
 * @param value the value being parsed
 * @param defaultValue the default value if value can't be parsed into a double
 * @return the parsed double or the defaultValue if value can't be parsed into a double
 */
public static double intoDouble(Object value, double defaultValue) {
    final Double d = doIntoDouble(value);
    return d == null ? defaultValue : d.doubleValue();
}

From source file:org.peerfact.impl.util.stats.distributions.LimitedNormalDistribution.java

/**
 * Returns a random value that is distributed as a Normal Distribution with
 * an upper and lower limit.//from  ww w  .j  av a 2 s  .  c  o  m
 * 
 * @param _mu
 *            average
 * @param _sigma
 *            standard deviation
 * @param _min
 *            lower limit, set to "null", if no limit
 * @param _max
 *            upper limit, set to "null", if no limit
 * @return as double
 */
public static double returnValue(double _mu, double _sigma, Double _min, Double _max) {
    double lmax;
    double lmin;
    double lpmax = 1;
    double lpmin = 0;
    double lpfactor;

    NormalDistributionImpl llimitedNormal = new NormalDistributionImpl(_mu, _sigma);
    if (_min == null) {
        if (_max != null) {
            // only max is limted
            lmax = _max.doubleValue();
            try {
                lpmax = llimitedNormal.cumulativeProbability(lmax);
            } catch (MathException e) {
                e.printStackTrace();
            }
        }
    } else {
        if (_max == null) {
            // only min is limited.
            lmin = _min.doubleValue();
            try {
                lpmin = llimitedNormal.cumulativeProbability(lmin);
            } catch (MathException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            // both sides limited.

            // make sure min is really smaller than max.
            if (_max.doubleValue() > _min.doubleValue()) {
                lmin = _min.doubleValue();
                lmax = _max.doubleValue();
            } else {
                lmax = _min.doubleValue();
                lmin = _max.doubleValue();
            }

            // get min and max probabilites that are possible
            try {
                lpmin = llimitedNormal.cumulativeProbability(lmin);
                lpmax = llimitedNormal.cumulativeProbability(lmax);

                lpfactor = lpmax - lpmin;

            } catch (MathException e) {
                e.printStackTrace();
            }
        }
    }
    lpfactor = lpmax - lpmin;

    double lrandom = lpmin + Simulator.getRandom().nextDouble() * lpfactor;
    double lresult;

    try {
        lresult = llimitedNormal.inverseCumulativeProbability(lrandom);
    } catch (MathException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        lresult = 0;
    }

    return lresult;

}

From source file:de.cosmocode.collections.utility.Convert.java

/**
 * Parses a value of a generic type//from  w w w  . jav  a 2 s.  c o  m
 * into a double.
 * 
 * @param value the value being parsed
 * @return the parsed double
 * @throws IllegalArgumentException if conversion failed
 */
public static double intoDouble(Object value) {
    final Double d = doIntoDouble(value);
    if (d == null) {
        throw fail(value, double.class);
    } else {
        return d.doubleValue();
    }
}

From source file:de.betterform.xml.xforms.ui.state.UIElementStateUtil.java

/**
 * localize a string value depending on datatype and locale
 *
 * @param owner the BindingElement which is localized
 * @param type  the datatype of the bound Node
 * @param value the string value to convert
 * @return returns a localized representation of the input string
 *///from   w w w . j av  a  2s .c  o m
public static String localiseValue(BindingElement owner, Element state, String type, String value)
        throws XFormsException {
    if (value == null || value.equals("")) {
        return value;
    }
    String tmpType = type;
    if (tmpType != null && tmpType.contains(":")) {
        tmpType = tmpType.substring(tmpType.indexOf(":") + 1, tmpType.length());
    }
    if (Config.getInstance().getProperty(XFormsProcessorImpl.BETTERFORM_ENABLE_L10N, "true").equals("true")) {

        Locale locale = (Locale) owner.getModel().getContainer().getProcessor().getContext()
                .get(XFormsProcessorImpl.BETTERFORM_LOCALE);
        if (tmpType == null) {
            tmpType = owner.getModelItem().getDeclarationView().getDatatype();
        }
        if (tmpType == null) {
            LOGGER.debug(DOMUtil.getCanonicalPath(owner.getInstanceNode()) + " has no type, assuming 'string'");
            return value;
        }
        if (tmpType.equalsIgnoreCase("float") || tmpType.equalsIgnoreCase("decimal")
                || tmpType.equalsIgnoreCase("double")) {
            if (value.equals(""))
                return value;
            if (value.equals("NaN"))
                return value; //do not localize 'NaN' as it returns strange characters
            try {
                NumberFormat formatter = NumberFormat.getNumberInstance(locale);
                if (formatter instanceof DecimalFormat) {
                    //get original number format
                    int separatorPos = value.indexOf(".");
                    if (separatorPos == -1) {
                        formatter.setMaximumFractionDigits(0);
                    } else {
                        int fractionDigitCount = value.length() - separatorPos - 1;
                        formatter.setMinimumFractionDigits(fractionDigitCount);
                    }

                    Double num = Double.parseDouble(value);
                    return formatter.format(num.doubleValue());
                }
            } catch (NumberFormatException e) {
                LOGGER.warn("Value '" + value + "' is no valid " + tmpType);
                return value;
            }

        } else if (tmpType.equalsIgnoreCase("date")) {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date d = sf.parse(value);
                return DateFormat.getDateInstance(DateFormat.DEFAULT, locale).format(d);
            } catch (ParseException e) {
                LOGGER.warn("Value '" + value + "' is no valid " + tmpType);
                return value;
            }

        } else if (tmpType.equalsIgnoreCase("dateTime")) {

            //hackery due to lacking pattern for ISO 8601 Timezone representation in SimpleDateFormat
            String timezone = "";
            String dateTime = null;
            if (value.contains("GMT")) {
                timezone = " GMT" + value.substring(value.lastIndexOf(":") - 3, value.length());
                int devider = value.lastIndexOf(":");
                dateTime = value.substring(0, devider) + value.substring(devider + 1, value.length());
            } else if (value.contains("Z")) {
                timezone = "";
                dateTime = value.substring(0, value.indexOf("Z"));

            } else if (value.contains("+")) {
                timezone = value.substring(value.indexOf("+"), value.length());
                dateTime = value.substring(0, value.indexOf("+"));

            } else {
                dateTime = value;
            }
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

            try {
                Date d = sf.parse(dateTime);
                return DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale).format(d)
                        + timezone;
            } catch (ParseException e) {
                LOGGER.warn("Value '" + value + "' is no valid " + tmpType);
                return value;
            }

        } else {
            //not logging for type 'string'
            if (LOGGER.isTraceEnabled() && !(tmpType.equals("string"))) {
                LOGGER.trace("Type " + tmpType + " cannot be localized");
            }
        }
    }
    return value;
}

From source file:cn.taop.utils.GSONUtils.java

/**
 * ????? {@code JSON} ?/*from www  .  j a  v  a  2s . co  m*/
 * <p />
 * <strong>???? <code>"{}"</code> ? <code>"[]"</code>
 * </strong>
 * 
 * @param target 
 * @param targetType 
 * @param isSerializeNulls ?? {@code null} 
 * @param version ?
 * @param datePattern ??
 * @param excludesFieldsWithoutExpose ? {@literal @Expose} 
 * @return  {@code JSON} ?
 * @since 1.0
 */
public static String toJson(Object target, Type targetType, boolean isSerializeNulls, Double version,
        String datePattern, boolean excludesFieldsWithoutExpose) {
    if (target == null)
        return EMPTY_JSON;
    GsonBuilder builder = new GsonBuilder();
    if (isSerializeNulls)
        builder.serializeNulls();
    if (version != null)
        builder.setVersion(version.doubleValue());
    if (StringUtils.isBlank(datePattern))
        datePattern = DEFAULT_DATE_PATTERN;
    builder.setDateFormat(datePattern);
    if (excludesFieldsWithoutExpose)
        builder.excludeFieldsWithoutExposeAnnotation();
    return toJson(target, targetType, builder);
}

From source file:edu.uci.ics.asterix.test.aql.TestsUtils.java

private static boolean equalStrings(String s1, String s2) {
    String[] rowsOne = s1.split("\n");
    String[] rowsTwo = s2.split("\n");

    for (int i = 0; i < rowsOne.length; i++) {
        String row1 = rowsOne[i];
        String row2 = rowsTwo[i];

        if (row1.equals(row2))
            continue;

        String[] fields1 = row1.split(" ");
        String[] fields2 = row2.split(" ");

        boolean bagEncountered = false;
        Set<String> bagElements1 = new HashSet<String>();
        Set<String> bagElements2 = new HashSet<String>();

        for (int j = 0; j < fields1.length; j++) {
            if (j >= fields2.length) {
                return false;
            } else if (fields1[j].equals(fields2[j])) {
                if (fields1[j].equals("{{"))
                    bagEncountered = true;
                if (fields1[j].startsWith("}}")) {
                    if (!bagElements1.equals(bagElements2))
                        return false;
                    bagEncountered = false;
                    bagElements1.clear();
                    bagElements2.clear();
                }// w  w  w  . ja v a  2s  .c om
                continue;
            } else if (fields1[j].indexOf('.') < 0) {
                if (bagEncountered) {
                    bagElements1.add(fields1[j].replaceAll(",$", ""));
                    bagElements2.add(fields2[j].replaceAll(",$", ""));
                    continue;
                }
                return false;
            } else {
                // If the fields are floating-point numbers, test them
                // for equality safely
                fields1[j] = fields1[j].split(",")[0];
                fields2[j] = fields2[j].split(",")[0];
                try {
                    Double double1 = Double.parseDouble(fields1[j]);
                    Double double2 = Double.parseDouble(fields2[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;
}