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:com.oneops.ops.dao.PerfDataAccessor.java

public void writeSampleToHeaderAndBuckets(String key, long endTime, PerfHeader header, Map<String, Double> data,
        HashMap<String, PerfEvent> perfEventMap) throws IOException {

    StringBuilder pendingKeys = new StringBuilder("");
    Mutator<byte[]> mutator = createMutator(keyspace, bytesSerializer);

    phd.putHeader(key, header, mutator);
    // write the buckets / archives
    for (String dsRraTime : data.keySet()) {
        // only supporting avg due to volume
        if (!dsRraTime.contains("rra-average"))
            continue;

        String[] dsRraTimeParts = dsRraTime.split("::");
        String dsRra = dsRraTimeParts[0];
        String bucketKey = key + ":" + dsRra;
        long bucketEndTime = Long.parseLong(dsRraTimeParts[1]);

        Double cdpValue = Math.round(data.get(dsRraTime).doubleValue() * 1000.0) / 1000.0;
        if (dsRra.endsWith(LOGBUCKET)) {
            logger.info("write " + bucketKey + " : " + cdpValue);
        }//from  w  w  w.ja  v  a  2s .c om
        String shard = dsRra.substring(dsRra.length() - 3).replace("-", "");
        int ttl = getTTL(shard);
        HColumn<Long, Double> column = createDataColumn(bucketEndTime, cdpValue.doubleValue());
        column.setTtl(ttl);

        String dataCF = DATA_CF + "_" + shard;
        if (isTestMode)
            dataCF += "_test";

        mutator.addInsertion(bucketKey.getBytes(), dataCF, column);
        pendingKeys.append(" ," + bucketKey);

        // send the consolidated perf event to sensor
        PerfEvent pe = null;
        String[] rraParts = dsRra.split("-");
        String eventBucket = rraParts[rraParts.length - 1];
        if (perfEventMap.containsKey(eventBucket)) {
            pe = perfEventMap.get(eventBucket);
        } else {
            pe = setEventBucket(perfEventMap, eventBucket);
        }

        String ds = rraParts[0].replace(":rra", "");
        String rraType = rraParts[1];

        if (rraType.equalsIgnoreCase(AVERAGE)) {
            pe.getMetrics().addAvg(ds, cdpValue);
        } else if (rraType.equalsIgnoreCase(COUNT)) {
            pe.getMetrics().addCount(ds, cdpValue);
        } else if (rraType.equalsIgnoreCase(MAX)) {
            pe.getMetrics().addMax(ds, cdpValue);
        } else if (rraType.equalsIgnoreCase(MIN)) {
            pe.getMetrics().addMin(ds, cdpValue);
        } else if (rraType.equalsIgnoreCase(SUM)) {
            pe.getMetrics().addSum(ds, cdpValue);
        }

    }

    logger.debug("write keys:" + pendingKeys);

    // perform the insert/updates
    mutator.execute();
}

From source file:org.apache.pig.data.SchemaTuple.java

protected double unbox(Double v) {
    return v.doubleValue();
}

From source file:com.acc.controller.StoreFinderController.java

@RequestMapping(value = "/v1/{baseSiteId}/stores", method = RequestMethod.GET)
@ResponseBody//from ww  w . ja  v a2s.c o  m
public StoreFinderSearchPageData<PointOfServiceData> locationSearch(
        @RequestParam(required = false) final String query, final Double latitude, final Double longitude,
        @RequestParam(required = false, defaultValue = "0") final int currentPage,
        @RequestParam(required = false, defaultValue = "10") final int pageSize,
        @RequestParam(required = false, defaultValue = "asc") final String sort,
        @RequestParam(required = false, defaultValue = "BASIC") final String options,
        @RequestParam(required = false, defaultValue = DEFAULT_SEARCH_RADIUS_METRES) final double radius,
        @RequestParam(required = false, defaultValue = DEFAULT_ACCURACY) final double accuracy) {
    if (radius > EARTH_PERIMETER) {
        throw new IllegalArgumentException("Radius cannot be greater than Earth's perimeter");
    }

    final double radiusToSearch = getInKilometres(radius, accuracy);
    final PageableData pageableData = createPagaable(currentPage, pageSize, sort);
    StoreFinderSearchPageData<PointOfServiceData> result = null;
    if (StringUtils.isNotBlank(query)) {
        result = storeFinderFacade.locationSearch(query, pageableData, radiusToSearch);
    } else if (latitude != null && longitude != null) {
        final GeoPoint geoPoint = new GeoPoint();
        geoPoint.setLatitude(latitude.doubleValue());
        geoPoint.setLongitude(longitude.doubleValue());
        result = storeFinderFacade.positionSearch(geoPoint, pageableData, radiusToSearch);
    } else {
        result = storeFinderFacade.getAllPointOfServices(pageableData);
    }
    final List<PointOfServiceData> results = filterOptions(options, result);
    result.setResults(new ArrayList(results));

    return result;
}

From source file:no.met.jtimeseries.chart.ChartPlotter.java

/**
 * Adds the specified weather symbols to the chart. Symbols are excluded if
 * necessary to fit in the chart. Specify phenomenon to follow value curve.
 * Plot on top of chart if phenomenon is null.
 * //from w  w  w .j  a  va  2 s  .  co  m
 * @return
 */
public void addWeatherSymbol(SymbolPhenomenon symbols, NumberPhenomenon phenomenon) {

    boolean followPhenomenon = (phenomenon != null);
    NumberAxis na;
    if (!followPhenomenon) {
        na = new NumberAxis("");
        na.setVisible(false);
        weatherSymbolPlot = new XYPlot();
        weatherSymbolPlot.setDomainAxis(plot.getDomainAxis(0));
        weatherSymbolPlot.setRangeAxis(na);
        weatherSymbolPlot.setRangeGridlinesVisible(false);
        weatherSymbolPlot.setOutlineVisible(false);
        weatherSymbolPlot.setDomainGridlinesVisible(false);
    }

    XYImageAnnotation imageannotation;

    int imageSize = getWeatherSymbolImageSize();

    for (SymbolValueItem symbol : symbols) {
        Image image = Symbols.getSymbolImage(symbol.getValue());
        image = image.getScaledInstance(imageSize, imageSize, Image.SCALE_SMOOTH);
        if (followPhenomenon) { // plot over the phenomenon curve
            Double val = phenomenon.getValueByTime(symbol.getTimeFrom());
            if (val != null) {
                double padding = 0.08; // space between curve and symbol in
                                       // phenomenon units
                imageannotation = new XYImageAnnotation(symbol.getTimeFrom().getTime(),
                        val.doubleValue() + padding
                                * (plot.getRangeAxis().getUpperBound() - plot.getRangeAxis().getLowerBound()),
                        image, RectangleAnchor.CENTER);
                plot.addAnnotation(imageannotation);
            }
        } else { // plot symbols on top in separate weatherSymbolPlot
            imageannotation = new XYImageAnnotation(symbol.getTimeFrom().getTime(), 0.5, image);
            weatherSymbolPlot.addAnnotation(imageannotation);
        }
    }
}

From source file:org.boris.xlloop.util.XLoperObjectConverter.java

private Object convertVector(XLArray arr, Class hint, SessionContext sessionContext) {
    Object val = null;

    if (Integer.class.equals(hint)) {
        Integer l = arr.length > 0 ? arr.getInteger(0) : null;
        return l == null ? null : new Integer(l.intValue());
    } else if (int.class.equals(hint)) {
        Integer l = arr.length > 0 ? arr.getInteger(0) : null;
        return l == null ? IZERO : new Integer(l.intValue());
    } else if (Double.class.equals(hint)) {
        return arr.length > 0 ? arr.getDouble(0) : null;
    } else if (double.class.equals(hint)) {
        Double d = arr.length > 0 ? arr.getDouble(0) : null;
        return d == null ? DZERO : d;
    } else if (String.class.equals(hint)) {
        return arr.length > 0 ? arr.getString(0) : null;
    } else if (double[].class.equals(hint)) {
        double[] darr = new double[arr.rows];

        for (int i = 0; i < darr.length; i++) {
            Double d = arr.getDouble(i);
            if (d != null) {
                darr[i] = d.doubleValue();
            }//  w w  w  . j av a  2 s  . c  o  m
        }

        val = darr;
    } else if (double[][].class.equals(hint)) {
        double[][] darr = new double[arr.rows][1];

        for (int i = 0; i < arr.rows; i++) {
            Double d = arr.getDouble(i);
            if (d != null) {
                darr[i][0] = d.doubleValue();
            }
        }

        val = darr;
    } else if (Double[].class.equals(hint)) {
        Double[] darr = new Double[arr.rows];

        for (int i = 0; i < darr.length; i++) {
            darr[i] = arr.getDouble(i);
        }

        val = darr;
    } else if (Double[][].class.equals(hint)) {
        Double[][] darr = new Double[arr.rows][1];

        for (int i = 0; i < arr.rows; i++) {
            darr[i][0] = arr.getDouble(i);
        }

        val = darr;
    } else if (int[].class.equals(hint)) {
        int[] darr = new int[arr.rows];

        for (int i = 0; i < darr.length; i++) {
            Integer l = arr.getInteger(i);
            if (l != null) {
                darr[i] = l.intValue();
            }
        }

        val = darr;
    } else if (int[][].class.equals(hint)) {
        int[][] darr = new int[arr.rows][1];

        for (int i = 0; i < arr.rows; i++) {
            Integer l = arr.getInteger(i);
            if (l != null) {
                darr[i][0] = l.intValue();
            }
        }

        val = darr;
    } else if (Integer[].class.equals(hint)) {
        Integer[] darr = new Integer[arr.rows];

        for (int i = 0; i < darr.length; i++) {
            darr[i] = arr.getInteger(i);
        }

        val = darr;
    } else if (Integer[][].class.equals(hint)) {
        Integer[][] darr = new Integer[arr.rows][1];

        for (int i = 0; i < arr.rows; i++) {
            darr[i][0] = arr.getInteger(i);
        }

        val = darr;
    } else if (boolean[].class.equals(hint)) {
        boolean[] darr = new boolean[arr.rows];

        for (int i = 0; i < darr.length; i++) {
            Integer l = arr.getInteger(i);
            if (l != null) {
                darr[i] = l.intValue() == 1;
            }
        }

        val = darr;
    } else if (boolean[][].class.equals(hint)) {
        boolean[][] darr = new boolean[arr.rows][1];

        for (int i = 0; i < arr.rows; i++) {
            Integer l = arr.getInteger(i);
            if (l != null) {
                darr[i][0] = l.intValue() == 1;
            }
        }

        val = darr;
    } else if (Boolean[].class.equals(hint)) {
        Boolean[] darr = new Boolean[arr.rows];

        for (int i = 0; i < darr.length; i++) {
            Integer l = arr.getInteger(i);
            if (l != null) {
                darr[i] = new Boolean(l.intValue() == 1);
            }
        }

        val = darr;
    } else if (Boolean[][].class.equals(hint)) {
        Boolean[][] darr = new Boolean[arr.rows][1];

        for (int i = 0; i < arr.rows; i++) {
            Integer l = arr.getInteger(i);
            if (l != null) {
                darr[i][0] = new Boolean(l.intValue() == 1);
            }
        }

        val = darr;
    } else if (String[].class.equals(hint)) {
        String[] darr = new String[arr.rows];

        for (int i = 0; i < darr.length; i++) {
            darr[i] = arr.getString(i);
        }

        val = darr;
    } else if (String[][].class.equals(hint)) {
        String[][] darr = new String[arr.rows][1];

        for (int i = 0; i < arr.rows; i++) {
            darr[i][0] = arr.getString(i);
        }

        val = darr;
    } else if (Object[].class.equals(hint)) {
        Object[] darr = new Object[arr.rows];

        for (int i = 0; i < darr.length; i++) {
            darr[i] = createFrom(arr.get(i), Object.class, sessionContext);
        }

        val = darr;
    } else if (Collection.class.equals(hint)) {
        Object[] darr = new Object[arr.rows];

        for (int i = 0; i < darr.length; i++) {
            darr[i] = createFrom(arr.get(i), Object.class, sessionContext);
        }

        val = Arrays.asList(darr);
    } else if (Object[][].class.equals(hint)) {
        Object[][] darr = new Object[arr.rows][1];

        for (int i = 0; i < arr.rows; i++) {
            darr[i][0] = createFrom(arr.get(i), Object.class, sessionContext);
        }

        val = darr;
    } else {
        String str = arr.getString(0);
        val = registry.get(str, sessionContext);
    }

    return val;
}

From source file:org.exfio.weave.storage.StorageContext.java

private URI buildCollectionUri(String collection, String[] ids, Double older, Double newer, Integer index_above,
        Integer index_below, Integer limit, Integer offset, String sort, String format, boolean full)
        throws WeaveException {

    URI location = this.storageURL.resolve(URIUtils.sanitize(String.format("storage/%s", collection)));

    //Build list of URL querystring parameters
    List<NameValuePair> params = new LinkedList<NameValuePair>();

    if (ids != null && ids.length > 0) {
        String value = "";
        String delim = "";
        for (int i = 0; i < ids.length; i++) {
            value = value + delim + ids[i];
            delim = ",";
        }//from  w w  w.j a va 2s .  c  o  m
        params.add(new BasicNameValuePair("ids", value));
    }
    if (older != null) {
        params.add(new BasicNameValuePair("older", String.format("%.2f", older.doubleValue())));
    }
    if (newer != null) {
        params.add(new BasicNameValuePair("newer", String.format("%.2f", newer.doubleValue())));
    }
    if (index_above != null) {
        params.add(new BasicNameValuePair("index_above", index_above.toString()));
    }
    if (index_below != null) {
        params.add(new BasicNameValuePair("index_below", index_below.toString()));
    }
    if (limit != null) {
        params.add(new BasicNameValuePair("limit", limit.toString()));
    }
    if (offset != null) {
        params.add(new BasicNameValuePair("offset", offset.toString()));
    }
    if (sort != null) {
        sort = sort.toLowerCase();
        if (sort.matches("oldest|newest|index")) {
            params.add(new BasicNameValuePair("sort", sort.toString()));
        } else {
            throw new WeaveException(
                    String.format("getCollection() sort parameter value of '%s' not recognised", sort));
        }
    }
    if (format != null) {
        //Only default format supported
        throw new WeaveException(
                String.format("getCollection() format parameter value of '%s' not supported", format));
    }
    if (full) {
        //returns entire WBO
        params.add(new BasicNameValuePair("full", "1"));
    }

    try {
        //FIXME - use URI builder for all uri handling

        //Use URIBuilder to encode query string parameters. java.util.URI DOES NOT correctly handle commas
        URIBuilder uri = new URIBuilder(location);
        if (params.size() > 0) {
            uri.setParameters(params);
        }
        location = new URI(uri.toString());
    } catch (URISyntaxException e) {
        throw new WeaveException(e);
    }

    return location;
}

From source file:nl.b3p.ogc.utils.OGCRequest.java

public double calcScale() {
    String projection = (String) parameters.get(WMS_PARAM_SRS);
    if (projection == null) {
        return 0.0;
    }/*from w  ww  . ja  v a2  s. c  o  m*/
    Double scaleCalibration = (Double) scaleCalibrations.get(projection);
    if (scaleCalibration != null) {
        return calcScale(scaleCalibration.doubleValue());
    }
    return 0.0;
}

From source file:Main.java

/**
 * <p>Turns a string value into a java.lang.Number.</p>
 *
 * <p>First, the value is examined for a type qualifier on the end
 * (<code>'f','F','d','D','l','L'</code>).  If it is found, it starts 
 * trying to create successively larger types from the type specified
 * until one is found that can hold the value.</p>
 *
 * <p>If a type specifier is not found, it will check for a decimal point
 * and then try successively larger types from <code>Integer</code> to
 * <code>BigInteger</code> and from <code>Float</code> to
 * <code>BigDecimal</code>.</p>
 *
 * <p>If the string starts with <code>0x</code> or <code>-0x</code>, it
 * will be interpreted as a hexadecimal integer.  Values with leading
 * <code>0</code>'s will not be interpreted as octal.</p>
 *
 * @param val String containing a number
 * @return Number created from the string
 * @throws NumberFormatException if the value cannot be converted
 *///www . j  a  va 2  s. c  om
public static Number createNumber(String val) throws NumberFormatException {
    if (val == null) {
        return null;
    }
    if (val.length() == 0) {
        throw new NumberFormatException("\"\" is not a valid number.");
    }
    if (val.startsWith("--")) {
        // this is protection for poorness in java.lang.BigDecimal.
        // it accepts this as a legal value, but it does not appear 
        // to be in specification of class. OS X Java parses it to 
        // a wrong value.
        return null;
    }
    if (val.startsWith("0x") || val.startsWith("-0x")) {
        return createInteger(val);
    }
    char lastChar = val.charAt(val.length() - 1);
    String mant;
    String dec;
    String exp;
    int decPos = val.indexOf('.');
    int expPos = val.indexOf('e') + val.indexOf('E') + 1;

    if (decPos > -1) {

        if (expPos > -1) {
            if (expPos < decPos) {
                throw new NumberFormatException(val + " is not a valid number.");
            }
            dec = val.substring(decPos + 1, expPos);
        } else {
            dec = val.substring(decPos + 1);
        }
        mant = val.substring(0, decPos);
    } else {
        if (expPos > -1) {
            mant = val.substring(0, expPos);
        } else {
            mant = val;
        }
        dec = null;
    }
    if (!Character.isDigit(lastChar)) {
        if (expPos > -1 && expPos < val.length() - 1) {
            exp = val.substring(expPos + 1, val.length() - 1);
        } else {
            exp = null;
        }
        //Requesting a specific type..
        String numeric = val.substring(0, val.length() - 1);
        boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
        switch (lastChar) {
        case 'l':
        case 'L':
            if (dec == null && exp == null
                    && (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
                try {
                    return createLong(numeric);
                } catch (NumberFormatException nfe) {
                    //Too big for a long
                }
                return createBigInteger(numeric);

            }
            throw new NumberFormatException(val + " is not a valid number.");
        case 'f':
        case 'F':
            try {
                Float f = createFloat(numeric);
                if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
                    //If it's too big for a float or the float value = 0 and the string
                    //has non-zeros in it, then float does not have the precision we want
                    return f;
                }

            } catch (NumberFormatException e) {
                // ignore the bad number
            }
            //Fall through
        case 'd':
        case 'D':
            try {
                Double d = createDouble(numeric);
                if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
                    return d;
                }
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                return createBigDecimal(numeric);
            } catch (NumberFormatException e) {
                // empty catch
            }
            //Fall through
        default:
            throw new NumberFormatException(val + " is not a valid number.");

        }
    } else {
        //User doesn't have a preference on the return type, so let's start
        //small and go from there...
        if (expPos > -1 && expPos < val.length() - 1) {
            exp = val.substring(expPos + 1, val.length());
        } else {
            exp = null;
        }
        if (dec == null && exp == null) {
            //Must be an int,long,bigint
            try {
                return createInteger(val);
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                return createLong(val);
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            return createBigInteger(val);

        } else {
            //Must be a float,double,BigDec
            boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
            try {
                Float f = createFloat(val);
                if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
                    return f;
                }
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                Double d = createDouble(val);
                if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) {
                    return d;
                }
            } catch (NumberFormatException nfe) {
                // empty catch
            }

            return createBigDecimal(val);

        }

    }
}

From source file:com.nagarro.core.v1.controller.StoreFinderController.java

@RequestMapping(value = "/{baseSiteId}/stores", method = RequestMethod.GET)
@ResponseBody//w w w.  j  a v  a2  s . co m
public StoreFinderSearchPageData<PointOfServiceData> locationSearch(
        @RequestParam(required = false) final String query, final Double latitude, final Double longitude,
        @RequestParam(required = false, defaultValue = "0") final int currentPage,
        @RequestParam(required = false, defaultValue = "10") final int pageSize,
        @RequestParam(required = false, defaultValue = "asc") final String sort,
        @RequestParam(required = false, defaultValue = "BASIC") final String options,
        @RequestParam(required = false, defaultValue = DEFAULT_SEARCH_RADIUS_METRES) final double radius,
        @RequestParam(required = false, defaultValue = DEFAULT_ACCURACY) final double accuracy)
        throws RequestParameterException {
    if (radius > EARTH_PERIMETER) {
        throw new RequestParameterException("Radius cannot be greater than Earth's perimeter",
                RequestParameterException.INVALID, "radius");
    }

    final double radiusToSearch = getInKilometres(radius, accuracy);
    final PageableData pageableData = createPagaable(currentPage, pageSize, sort);
    StoreFinderSearchPageData<PointOfServiceData> result = null;
    if (StringUtils.isNotBlank(query)) {
        result = storeFinderFacade.locationSearch(query, pageableData, radiusToSearch);
    } else if (latitude != null && longitude != null) {
        final GeoPoint geoPoint = new GeoPoint();
        geoPoint.setLatitude(latitude.doubleValue());
        geoPoint.setLongitude(longitude.doubleValue());
        result = storeFinderFacade.positionSearch(geoPoint, pageableData, radiusToSearch);
    } else {
        result = storeFinderFacade.getAllPointOfServices(pageableData);
    }
    final List<PointOfServiceData> results = filterOptions(options, result);
    result.setResults(new ArrayList(results));

    return result;
}

From source file:de.hybris.platform.order.impl.DefaultCalculationService.java

protected void addRelativeEntryTaxValue(final double entryTotal, final TaxValue taxValue,
        final Set<TaxValue> relativeEntryTaxValues,
        final Map<TaxValue, Map<Set<TaxValue>, Double>> taxValueMap) {
    Double relativeTaxTotalSum = null;
    // A. is tax value already registered ?
    Map<Set<TaxValue>, Double> taxTotalsMap = taxValueMap.get(taxValue);
    if (taxTotalsMap != null) // tax value exists
    {//from   w ww.  j  a  v a  2 s  .  com
        // A.1 is set of tax un-applied values already registered by set of all relative tax values ?
        relativeTaxTotalSum = taxTotalsMap.get(relativeEntryTaxValues);
    }
    // B tax value did not exist before
    else {
        taxTotalsMap = new LinkedHashMap<Set<TaxValue>, Double>();
        taxValueMap.put(taxValue, taxTotalsMap);
    }
    taxTotalsMap.put(relativeEntryTaxValues, Double
            .valueOf((relativeTaxTotalSum != null ? relativeTaxTotalSum.doubleValue() : 0d) + entryTotal));

}