Example usage for java.lang Double valueOf

List of usage examples for java.lang Double valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Double valueOf(double d) 

Source Link

Document

Returns a Double instance representing the specified double value.

Usage

From source file:com.rackspacecloud.blueflood.io.serializers.astyanax.TimerSerializationTest.java

@Test
public void testV2RoundTrip() throws IOException {
    // build up a Timer
    BluefloodTimerRollup r0 = new BluefloodTimerRollup().withSum(Double.valueOf(42)).withCountPS(23.32d)
            .withAverage(56).withVariance(853.3245d).withMinValue(2).withMaxValue(987).withCount(345);
    r0.setPercentile("foo", 741.32d);
    r0.setPercentile("bar", 0.0323d);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(Base64.encodeBase64(Serializers.timerRollupInstance.toByteBuffer(r0).array()));
    baos.write("\n".getBytes());
    baos.close();/* w  w w.  j  a va2s  . c  om*/

    BufferedReader reader = new BufferedReader(
            new InputStreamReader(new ByteArrayInputStream(baos.toByteArray())));
    ByteBuffer bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes()));
    BluefloodTimerRollup r1 = Serializers.timerRollupInstance.fromByteBuffer(bb);
    Assert.assertEquals(r0, r1);
}

From source file:com.carlomicieli.jtrains.value.objects.Length.java

private static double round(double v) {
    DecimalFormat df = new DecimalFormat("#.##");
    return Double.valueOf(df.format(v));
}

From source file:controller.GetHotel.java

public List<Hotel> getHotel(String cityName, double[] geocoding) {
    GetResource gr = new GetResource();
    GetCity gc = new GetCity();
    HashMap cityInfo = new HashMap();
    cityInfo = gc.getCity();//from  www .ja va  2s .  co m
    String cityID = (String) cityInfo.get(cityName);
    String hotelURL = "http://apis.haoservice.com/lifeservice/travel/HotelList?key=de8a238525314a99a55515983592374a&cityid="
            + cityID;
    String data = gr.getData(hotelURL);
    try {
        List<Hotel> lh = new ArrayList<Hotel>();
        JSONObject dataJson;
        dataJson = new JSONObject(data);
        //            JSONArray errorCode = dataJson.getJSONArray("error_code");
        //            JSONObject errorInfo = errorCode.getJSONObject(0);
        // boolean test = dataJson.isNull("result");
        JSONArray result = dataJson.getJSONArray("result");
        for (int i = 0; i < result.length(); i++) {
            JSONObject info = result.getJSONObject(i);
            Hotel h = new Hotel();
            h.setHotelID(info.getString("id"));
            h.setName(info.getString("name"));
            h.setClassName(info.getString("className"));
            h.setIntro(info.getString("intro"));
            h.setDpNum(info.getString("dpNum"));
            h.setLat(info.getString("Lat"));
            h.setLon(info.getString("Lon"));
            h.setAddress(info.getString("address"));
            h.setLargePic(info.getString("largePic"));
            h.setCityID(info.getString("cityId"));
            h.setUrl(info.getString("url"));
            h.setSatisfaction(info.getString("manyidu"));
            double lon = Double.valueOf(info.getString("Lon"));
            double lat = Double.valueOf(info.getString("Lat"));
            if ((Math.abs(lon - geocoding[0]) < 0.11) && (Math.abs(lat - geocoding[1]) < 0.11)) {
                lh.add(h);
            }
        }
        List<Hotel> alh = new ArrayList<Hotel>();
        for (int j = 0; j < result.length(); j++) {
            JSONObject infoAll = result.getJSONObject(j);
            Hotel ah = new Hotel();
            ah.setHotelID(infoAll.getString("id"));
            ah.setName(infoAll.getString("name"));
            ah.setClassName(infoAll.getString("className"));
            ah.setIntro(infoAll.getString("intro"));
            ah.setDpNum(infoAll.getString("dpNum"));
            ah.setLat(infoAll.getString("Lat"));
            ah.setLon(infoAll.getString("Lon"));
            ah.setAddress(infoAll.getString("address"));
            ah.setLargePic(infoAll.getString("largePic"));
            ah.setCityID(infoAll.getString("cityId"));
            ah.setUrl(infoAll.getString("url"));
            ah.setSatisfaction(infoAll.getString("manyidu"));
            alh.add(ah);
        }
        if (lh.isEmpty()) {
            return alh;
        } else {
            return lh;
        }
    } catch (JSONException ex) {
        Logger.getLogger(GetHotel.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}

From source file:gov.nih.nci.caintegrator.domain.annotation.PermissibleValue.java

/**
 * {@inheritDoc}/*from   ww w . j ava 2  s  .c o  m*/
 */
public int compareTo(PermissibleValue o) {
    if (NumberUtils.isNumber(getValue())) {
        return Double.valueOf(getValue()).compareTo(Double.valueOf(o.getValue()));
    } else {
        return getValue().compareTo(o.getValue());
    }
}

From source file:gda.data.DetectorDataWrapper.java

Double convertDetectorDataToDouble(Object data) {
    try {//  ww w  .j a v  a 2s . c  o m
        if (data instanceof String) {
            return Double.parseDouble((String) data);
        } else if (data instanceof Number) {
            return ((Number) data).doubleValue();
        } else if (data instanceof PyObject) {
            try {
                Double val = (Double) ((PyObject) data).__tojava__(Double.class);
                //only return if a valid Double
                if (val != null)
                    return val;

                if (data instanceof PyString) {
                    val = Double.valueOf((String) ((PyString) data).__tojava__(String.class));
                    if (val != null)
                        return val;
                }
                return val;
            } catch (Exception e) {
                //do nothing
            }

        }
        // try the ScannableUtils method which converts anythign it can into an array of Doubles
        Double[] dataArray = ScannableUtils.objectToArray(data);
        if (dataArray != null) {
            return dataArray[0];
        }
    } catch (Throwable ex) {
        //do nothing - maybe warn - the value will be set as null
    }
    return null;
}

From source file:moefou4j.internal.util.Moefou4JInternalParseUtil.java

public static double getDouble(final String name, final JSONObject json) {
    final String str2 = getRawString(name, json);
    if (null == str2 || "".equals(str2) || "null".equals(str2))
        return -1;
    else// w w w .j a v  a2  s  . c  om
        return Double.valueOf(str2);
}

From source file:com.garethahealy.quotalimitsgenerator.cli.parsers.CLIOptions.java

public QuotaLimitModel calculate() {
    Pair<Integer, Integer> instanceTypeLine = lines.get(instanceType);

    Integer instanceCoreInMillis = instanceTypeLine.getLeft() * 1000;
    Integer instanceMemoryInMb = instanceTypeLine.getRight() * 1000;

    QuotaLimitModel quotaLimitModel = new QuotaLimitModel();

    quotaLimitModel.setInstanceType(instanceType);
    quotaLimitModel.setQualityOfService(qualityOfService);
    quotaLimitModel.setAllocatableNodeCores(instanceCoreInMillis);
    quotaLimitModel.setAllocatableNodeMemory(instanceMemoryInMb);
    quotaLimitModel// w  w  w .  j av a 2 s . co m
            .setMaxPods(Double.valueOf(Math.floor((instanceMemoryInMb / 500) * nodeWorkerCount)).intValue());

    quotaLimitModel.setTerminatingPodCPU(Double.valueOf(Math.floor(instanceCoreInMillis * 0.5)).intValue());
    quotaLimitModel.setTerminatingPodMemory(Double.valueOf(Math.floor(instanceMemoryInMb * 0.5)).intValue());

    quotaLimitModel.setMaxOrNotTerminatingPodLimitCPU(instanceCoreInMillis * requestRatio);
    quotaLimitModel.setMaxOrNotTerminatingPodLimitMemory(instanceMemoryInMb * requestRatio);
    quotaLimitModel.setMaxOrNotTerminatingPodRequestCPU(instanceCoreInMillis);
    quotaLimitModel.setMaxOrNotTerminatingPodRequestMemory(instanceMemoryInMb);

    quotaLimitModel.setIsTeamNamespace(isTeamNamespace);
    quotaLimitModel.setCpuRequestRatio(requestRatio);
    quotaLimitModel.setMemoryRequestRatio(requestRatio);
    quotaLimitModel.setOutputPath(outputPath);

    return quotaLimitModel;
}

From source file:com.ottogroup.bi.streaming.operator.json.aggregate.functions.DoubleContentAggregateFunctionTest.java

/**
 * Test case for {@link DoubleContentAggregateFunction#sum(Double, Double)} being
 * provided valid input to both parameter
 *//*from w w w.j a  v a 2 s . c o m*/
@Test
public void testSum_withValidInput() throws Exception {
    Assert.assertEquals(Double.valueOf(1.26),
            new DoubleContentAggregateFunction().sum(Double.valueOf(1.23), Double.valueOf(0.03)));
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.json.TemperatureQuery.java

@SuppressWarnings("unchecked")
public String execute(IServletConfig config, String[] parameters) {

    JSONArray obj = new JSONArray();

    for (IVirtualVehicle vehicle : vehicleMap.values()) {
        if (vehicle.isFrozen()) {
            continue;
        }/*  w ww .  ja  v a 2s .co  m*/

        List<ITask> cmdList = vehicle.getTaskList();

        for (ITask cmd : cmdList) {
            for (IAction action : cmd.getActionList()) {
                if (action instanceof Temperature && action.isComplete()) {
                    Temperature actionTemp = (Temperature) action;
                    JSONObject o = new JSONObject();
                    o.put("lat", Double.valueOf(cmd.getPosition().getLatitude()));
                    o.put("lon", Double.valueOf(cmd.getPosition().getLongitude()));
                    //                  o.put("alt", Double.valueOf(cmd.getPosition().getAltitude()));
                    o.put("temp", Double.valueOf(actionTemp.getTemperature()));
                    obj.add(o);
                }
            }
        }
    }

    return JSONValue.toJSONString(obj);
}

From source file:com.epam.ipodromproject.service.CompetitionService.java

@Transactional
public boolean addCompetition(Date dateOfCompetition, Horse[] horsesToAdd, String[] horseCoefs) {
    if ((dateOfCompetition == null) || (horsesToAdd.length != horseCoefs.length)
            || (dateOfCompetition.compareTo(new Date()) <= 0)) {
        return false;
    }/* ww  w.j  av a2  s  .  c  om*/

    Map<Horse, HorseInfo> horses = new HashMap<>();
    for (int i = 0; i < horseCoefs.length; i++) {
        HorseInfo horseInfo = null;
        try {
            horseInfo = new HorseInfo(Double.valueOf(horseCoefs[i]));
        } catch (NumberFormatException e) {
        }
        if ((horseInfo != null) && (horsesToAdd[i] != null) && (horseInfo.getCoefficient() >= 1)) {
            if (horses.keySet().contains(horsesToAdd[i])) {
                return false;
            }
            horses.put(horsesToAdd[i], horseInfo);
        }
    }
    if (horses.size() <= 1) {
        return false;
    } else {
        Competition competition = new Competition();
        competition.setState(CompetitionState.NOT_REGISTERED);
        competition.setDateOfStart(dateOfCompetition);
        competition.setHorses(horses);
        competitionRepository.save(competition);
        return true;
    }
}