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.stackify.metric.impl.MetricSender.java

/**
 * Sends aggregate metrics to Stackify// w  w  w. j  ava 2 s .c o  m
 * @param aggregates The aggregate metrics
 * @throws IOException 
 * @throws HttpException
 */
public void send(final List<MetricAggregate> aggregates) throws IOException, HttpException {

    // build the json objects

    List<JsonMetric> metrics = new ArrayList<JsonMetric>(aggregates.size());

    for (MetricAggregate aggregate : aggregates) {

        Integer monitorId = monitorService.getMonitorId(aggregate.getIdentity());

        if (monitorId != null) {
            JsonMetric.Builder builder = JsonMetric.newBuilder();
            builder.monitorId(monitorId);
            builder.value(Double.valueOf(aggregate.getValue()));
            builder.count(Integer.valueOf(aggregate.getCount()));
            builder.occurredUtc(new Date(aggregate.getOccurredMillis()));
            builder.monitorTypeId(Integer.valueOf(aggregate.getIdentity().getType().getId()));

            metrics.add(builder.build());
        } else {
            LOGGER.info("Unable to determine monitor id for aggregate metric {}", aggregate);
        }
    }

    if (metrics.isEmpty()) {
        return;
    }

    // convert to json bytes

    byte[] jsonBytes = objectMapper.writer().writeValueAsBytes(metrics);

    // post to stackify

    HttpClient httpClient = new HttpClient(apiConfig);
    httpClient.post("/Metrics/SubmitMetricsByID", jsonBytes);
}

From source file:com.asprise.imaging.core.util.JsonUtils.java

public static Long toLong(Object object, Long defaultValue) {
    if (object == null) {
        return defaultValue;
    }//from  w ww.  j  av  a 2  s .  c  om
    if (object instanceof Number) {
        return ((Number) object).longValue();
    }

    try {
        Double value = Double.valueOf(object.toString().trim());
        return value.longValue();
    } catch (NumberFormatException e) {
        return defaultValue;
    }
}

From source file:com.sube.daos.mysql.SubeCardDaoTest.java

@Test
public void subeCardDaoTest() throws NoSuchAlgorithmException, InvalidPhysicalPersonException,
        InvalidDataEntryException, DuplicatedSubeCardException, InvalidSubeCardException {
    DataEntry dataEntry = new DataEntry();
    dataEntry.setPassword(passwordEncoder.encodePassword("checreto"));
    PhysicalPerson physicalPerson = new PhysicalPerson();
    physicalPerson.setDocumentType(DocumentType.DNI);
    physicalPerson.setFirstName("Hetor");
    physicalPerson.setLastName("Lopez");
    physicalPerson.setIdNumber(12345678);
    physicalPerson.setId(physicalPersonDao.createPhysicalPerson(physicalPerson));
    dataEntry.setPhysicalPerson(physicalPerson);
    dataEntry.setId(dataEntryDao.createDataEntry(dataEntry));
    SubeCard subeCard = new SubeCard();
    subeCard.setBalance(Double.valueOf(0.0d));
    subeCard.setCreatedBy(dataEntry);/*www  .  j  a  v  a  2  s  .  c o m*/
    subeCard.setNumber(subeCardDao.createCard(subeCard, dataEntry));
    SubeCard sameSubeCard = subeCardDao.getSubeCard(subeCard.getNumber());
    assertNull("User must be null", sameSubeCard.getUser());
    assertNull("Data Entry must be null", sameSubeCard.getCreatedBy());
    assertEquals("Balance not the same", subeCard.getBalance(), sameSubeCard.getBalance());
    assertEquals("Number not the same", subeCard.getNumber(), sameSubeCard.getNumber());
    subeCardDao.addToBalance(subeCard, 3.98d);
    subeCardDao.addToBalance(subeCard, 0.02d);
    subeCard.setBalance(4.00d);
    sameSubeCard = subeCardDao.getSubeCard(subeCard.getNumber());
    assertNull("User must be null", sameSubeCard.getUser());
    assertNull("Data Entry must be null", sameSubeCard.getCreatedBy());
    assertEquals("Balance not the same", subeCard.getBalance(), sameSubeCard.getBalance());
    assertEquals("Number not the same", subeCard.getNumber(), sameSubeCard.getNumber());
    subeCardDao.deleteCard(subeCard);
    assertNull("Sube Card still exists", subeCardDao.getSubeCard(subeCard.getNumber()));
    dataEntryDao.deleteDataEntry(dataEntry.getId());
    physicalPersonDao.deletePhysicalPerson(physicalPerson.getId());
}

From source file:com.impetus.client.redis.RedisQueryInterpreter.java

void setMin(String field, Object fieldValue) {
    this.min = new HashMap<String, Double>(1);
    this.min.put(field,
            !StringUtils.isNumeric(fieldValue.toString())
                    ? Double.valueOf(PropertyAccessorHelper.getString(fieldValue).hashCode())
                    : Double.valueOf(fieldValue.toString()));
}

From source file:examples.utils.CifarReader.java

public static BufferedImage getImageFromArray(double[] pixels, int width, int height) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    for (int i = 0; i < pixels.length / IMAGE_DEPTH; ++i) {
        int rgb = new Color(Double.valueOf(pixels[i]).intValue(), Double.valueOf(pixels[i + 1024]).intValue(),
                Double.valueOf(pixels[i + 2048]).intValue()).getRGB();
        image.setRGB(i % IMAGE_WIDTH, i / IMAGE_HIGHT, rgb);
    }/*from w  w w.  j  a  v  a2s .com*/
    return image;
}

From source file:net.sf.jasperreports.engine.xml.JRChartPlotFactory.java

/**
 *
 *///from   w w  w. j a  v  a2  s  . c o  m
public Object createObject(Attributes atts) {
    JRChartPlot plot = (JRChartPlot) digester.peek();

    Color color = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_backcolor), Color.black);
    if (color != null) {
        plot.setBackcolor(color);
    }

    String orientation = atts.getValue(JRXmlConstants.ATTRIBUTE_orientation);
    if (orientation != null && orientation.length() > 0)
        plot.setOrientation((PlotOrientation) JRXmlConstants.getPlotOrientationMap().get(orientation));

    String foregroundAlpha = atts.getValue(JRXmlConstants.ATTRIBUTE_foregroundAlpha);
    if (foregroundAlpha != null && foregroundAlpha.length() > 0)
        plot.setForegroundAlpha(Float.valueOf(foregroundAlpha));

    String backgroundAlpha = atts.getValue(JRXmlConstants.ATTRIBUTE_backgroundAlpha);
    if (backgroundAlpha != null && backgroundAlpha.length() > 0)
        plot.setBackgroundAlpha(Float.valueOf(backgroundAlpha));

    String labelRotation = atts.getValue(JRXmlConstants.ATTRIBUTE_labelRotation);
    if (labelRotation != null && labelRotation.length() > 0)
        plot.setLabelRotation(Double.valueOf(labelRotation));

    return plot;
}

From source file:org.hawkular.apm.api.model.Property.java

/**
 * @return the number/*from   w  w  w .  j  a  v  a  2 s  . c  o  m*/
 */
public Double getNumber() {
    if (number == null && value != null && type == PropertyType.Number) {
        try {
            return Double.valueOf(value);
        } catch (NumberFormatException e) {
            // Ignore
        }
    }
    return number;
}

From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java

public static Map<Double, List<DynModeTrip>> splitTripsIntoBins(Collection<DynModeTrip> trips, int startTime,
        int endTime, int binSize_s) {
    LinkedList<DynModeTrip> alltrips = new LinkedList<>();
    alltrips.addAll(trips);/*from  w  w  w  .  j  a v a2  s  . c  om*/
    Collections.sort(alltrips);
    DynModeTrip currentTrip = alltrips.pollFirst();
    if (currentTrip.getDepartureTime() > endTime) {
        Logger.getLogger(DynModeTripsAnalyser.class).error("wrong end / start Times for analysis");
    }
    Map<Double, List<DynModeTrip>> splitTrips = new TreeMap<>();
    for (int time = startTime; time < endTime; time = time + binSize_s) {
        List<DynModeTrip> currentList = new ArrayList<>();
        splitTrips.put(Double.valueOf(time), currentList);
        while (currentTrip.getDepartureTime() < time + binSize_s) {
            currentList.add(currentTrip);
            currentTrip = alltrips.pollFirst();
            if (currentTrip == null) {
                return splitTrips;
            }
        }

    }

    return splitTrips;

}

From source file:com.brightcove.com.zartan.verifier.rendition.RenditionDurationVerifier.java

@ZartanCheck(value = "All renditions have same duration as uploaded file")
public ResultEnum assertRenditionDurationCorrect(UploadData upData) throws Throwable {
    List<Throwable> throwables = new ArrayList<Throwable>();
    for (JsonNode rend : upData.getHttpResponseJson().get("renditions")) {
        int expected = upData.getmIngestFile().getFileInfo().getVideoDuration();
        int actual = rend.get("videoDuration").getIntValue();
        try {//from   w  w  w. j  a  v  a  2  s  . c  o  m
            assertEquals("Duration not within expected bounds", expected, actual,
                    (toleranceFactor * Double.valueOf(expected)));
        } catch (AssertionError e) {
            throwables.add(e);
        }
    }
    MultipleFailureException.assertEmpty(throwables);
    return ResultEnum.PASS;
}

From source file:com.marvelution.jira.plugins.hudson.charts.BuildResultsRatioChartGenerator.java

/**
 * {@inheritDoc}//from   w  w  w.  ja v  a2s. c o m
 */
@Override
public ChartHelper generateChart() {
    final Map<Integer, Build> buildMap = new HashMap<Integer, Build>();
    final CategoryTableXYDataset dataSet = new CategoryTableXYDataset();
    for (Build build : builds) {
        buildMap.put(Integer.valueOf(build.getBuildNumber()), build);
        dataSet.add(Double.valueOf(build.getBuildNumber()), Double.valueOf(build.getDuration()),
                getI18n().getText("hudson.charts.duration"));
    }
    final JFreeChart chart = ChartFactory.createXYBarChart("", "", false,
            getI18n().getText("hudson.charts.duration"), dataSet, PlotOrientation.VERTICAL, false, false,
            false);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderVisible(false);
    final BuildResultRenderer renderer = new BuildResultRenderer(server, buildMap);
    renderer.setBaseItemLabelFont(ChartDefaults.defaultFont);
    renderer.setBaseItemLabelsVisible(false);
    renderer.setMargin(0.0D);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer.setBaseToolTipGenerator(renderer);
    renderer.setURLGenerator(renderer);
    final XYPlot xyPlot = chart.getXYPlot();
    xyPlot.setAxisOffset(new RectangleInsets(1.0D, 1.0D, 1.0D, 1.0D));
    xyPlot.setRenderer(renderer);
    final NumberAxis domainAxis = new NumberAxis();
    domainAxis.setLowerBound(Collections.min(buildMap.keySet()));
    domainAxis.setUpperBound(Collections.max(buildMap.keySet()));
    final TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    domainAxis.setStandardTickUnits(ticks);
    xyPlot.setDomainAxis(domainAxis);
    final DateAxis rangeAxis = new DateAxis();
    final DurationFormat durationFormat = new DurationFormat();
    rangeAxis.setDateFormatOverride(durationFormat);
    rangeAxis.setLabel(getI18n().getText("hudson.charts.duration"));
    xyPlot.setRangeAxis(rangeAxis);
    ChartUtil.setupPlot(xyPlot);
    return new ChartHelper(chart);
}