Example usage for java.lang Double intValue

List of usage examples for java.lang Double intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Double as an int after a narrowing primitive conversion.

Usage

From source file:nl.b3p.gis.viewer.PrintAction.java

private Integer calcNewMapWidthFromPPI(Integer ppi, Double paperWidthInInches) {
    Double w = Math.ceil(ppi * paperWidthInInches);

    return w.intValue();
}

From source file:org.dasein.cloud.openstack.nova.os.compute.NovaServer.java

public static int roundUpToGB(Long size) {
    Double round = Math.ceil(size / Math.pow(2, 30));
    return round.intValue();
}

From source file:com.itemanalysis.psychometrics.rasch.Theta.java

public Theta(Double rawScore, Integer maximumPossibleScore) {
    this.rawScore = rawScore;
    this.ID = rawScore.intValue();
    this.maximumPossibleScore = maximumPossibleScore;
}

From source file:nl.b3p.gis.viewer.PrintAction.java

private Integer calcCurrentScale(CombineImageSettings settings) {
    Double newMapWidth = settings.getBbox().getMaxx() - settings.getBbox().getMinx();
    Double scale = newMapWidth / (settings.getWidth() * 0.00028);

    return scale.intValue();
}

From source file:com.jskj.assets.server.servcie.Stockpile.StockpileService.java

/**
 *
 * @param page/*from   www.j a v a2 s. c  om*/
 * @param conditionSql
 * @return ??? ?????ID??
 */
@Override
public StockpiletbFindEntity findsaleStockpile(Pager page, String conditionSql) {
    StockpiletbExample exam = new StockpiletbExample();
    StockpiletbFindEntity findEntity = new StockpiletbFindEntity();

    if (conditionSql != null && !conditionSql.trim().equals("")) {
        exam.createCriteria().addConditionSql(conditionSql);
    }

    //count?limtStart/limitEnd
    int count = stockpilemapper.countByExample(exam);
    page.setCount(count);
    exam.setLimitStart(page.getStartDataIndex());
    exam.setLimitEnd(page.getPageSize());
    //?
    exam.setOrderByClause("stockpile_id DESC");

    //?
    List<Stockpiletb> stockpiles = stockpilemapper.selectByExample(exam);

    List<StockpiletbAll> stockpilesAll = new ArrayList<StockpiletbAll>();
    List<Integer> saledate = new ArrayList();//????
    int saleint = 0;//???
    int jizhangdanju = 0;//??

    for (Stockpiletb stockpile : stockpiles) {
        StockpiletbAll stockpileAll = new StockpiletbAll();
        stockpile.setStockpileTotalprice(
                Arith.decimalPrice(Arith.mul(stockpile.getStockpileQuantity(), stockpile.getStockpilePrice())));
        copier.copy(stockpile, stockpileAll, null);
        log.debug("found stockpile:" + stockpile.getStockpileId());
        //?????
        YiMiaotb yimiao = yimiaomapper.selectByPrimaryKey(stockpile.getYimiaoId());
        if (stockpile.getYimiaoId() != null) {
            stockpileAll.setYimiao(yimiao);
        }

        //??ID??
        Double danjianshuliang = Arith.round(Arith.div(1, yimiao.getYimiaoHuansuanlv()), 0);//??
        int shuliang = danjianshuliang.intValue();
        Double kucunshuliang = Arith.round(Arith.mul(stockpile.getStockpileQuantity(), danjianshuliang), 0);//?
        int kcshuliang = kucunshuliang.intValue();
        Sale_detail_tbExample saledetailExample = new Sale_detail_tbExample();
        saledetailExample.createCriteria().andStockpileIdEqualTo(stockpile.getStockpileId())
                .andStatusEqualTo(0);
        List<Sale_detail_tb> Sale_detaillist = Sale_detail_tbMapper.selectByExample(saledetailExample);
        for (Sale_detail_tb sale_detail : Sale_detaillist) {
            //????????
            SplitNexustbExample splitExample = new SplitNexustbExample();
            splitExample.createCriteria().andSaledanidLike("%" + sale_detail.getSaleId() + "%")
                    .andYimiaoIdEqualTo(sale_detail.getYimiaoId())
                    .andStockpileIdEqualTo(stockpile.getStockpileId());
            List<SplitNexustb> split = SplitNexustbMapper.selectByExample(splitExample);
            if (!split.isEmpty()) {//????
                continue;
            }

            //?
            Double x = Arith.round(Arith.div(sale_detail.getQuantity(), yimiao.getYimiaoHuansuanlv()), 0);
            Double quantity = x % shuliang;//(?)
            if (quantity == 0) {
                continue;
            }
            saledate.add(quantity.intValue());
            saleint += quantity.intValue();//???
            jizhangdanju++;//??
        }
        //??

        if (saleint > shuliang) {//????
            if (saleint < kcshuliang) {//?????
                //???
                if (saledate.size() != 1) {//??????
                    saledate = NbArray.Nearest(saledate, danjianshuliang.intValue());
                }
                int sale = 0;
                for (int sales : saledate) {
                    sale += sales;
                }
                if (sale != danjianshuliang.intValue()) {
                    if (kcshuliang >= danjianshuliang.intValue()) {//???
                        saledate.add(danjianshuliang.intValue() - sale);
                    } else if (kcshuliang < danjianshuliang.intValue()) {//??
                        saledate.add(kcshuliang - sale);//??
                    }
                }
                stockpileAll.setSplit(saledate);
            }
        } else if (saleint <= danjianshuliang.intValue() && saleint > 0) {//????,
            saledate = NbArray.Nearest(saledate, danjianshuliang.intValue());
            int shulian = (kcshuliang > danjianshuliang.intValue()) ? danjianshuliang.intValue() : kcshuliang;
            if ((shulian - saleint) > 0)
                saledate.add(shulian - saleint);//??
            stockpileAll.setSplit(saledate);
        }

        stockpilesAll.add(stockpileAll);
    }

    findEntity.setCount(count);
    findEntity.setResult(stockpilesAll);

    return findEntity;
}

From source file:org.eclipse.smarthome.ui.internal.chart.ChartServlet.java

@SuppressWarnings({ "null" })
@Override//  w  w  w.j  a v  a 2s  .  c o  m
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    logger.debug("Received incoming chart request: {}", req);

    int width = defaultWidth;
    String w = req.getParameter("w");
    if (w != null) {
        try {
            width = Integer.parseInt(w);
        } catch (NumberFormatException e) {
            logger.debug("Ignoring invalid value '{}' for HTTP request parameter 'w'", w);
        }
    }
    int height = defaultHeight;
    String h = req.getParameter("h");
    if (h != null) {
        try {
            Double d = Double.parseDouble(h) * scale;
            height = d.intValue();
        } catch (NumberFormatException e) {
            logger.debug("Ignoring invalid value '{}' for HTTP request parameter 'h'", h);
        }
    }

    // To avoid ambiguity you are not allowed to specify period, begin and end time at the same time.
    if (req.getParameter("period") != null && req.getParameter("begin") != null
            && req.getParameter("end") != null) {
        res.sendError(HttpServletResponse.SC_BAD_REQUEST,
                "Do not specify the three parameters period, begin and end at the same time.");
        return;
    }

    // Read out the parameter period, begin and end and save them.
    Date timeBegin = null;
    Date timeEnd = null;

    Long period = PERIODS.get(req.getParameter("period"));
    if (period == null) {
        // use a day as the default period
        period = PERIODS.get("D");
    }

    if (req.getParameter("begin") != null) {
        try {
            timeBegin = new SimpleDateFormat(DATE_FORMAT).parse(req.getParameter("begin"));
        } catch (ParseException e) {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST,
                    "Begin and end must have this format: " + DATE_FORMAT + ".");
            return;
        }
    }

    if (req.getParameter("end") != null) {
        try {
            timeEnd = new SimpleDateFormat(DATE_FORMAT).parse(req.getParameter("end"));
        } catch (ParseException e) {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST,
                    "Begin and end must have this format: " + DATE_FORMAT + ".");
            return;
        }
    }

    // Set begin and end time and check legality.
    if (timeBegin == null && timeEnd == null) {
        timeEnd = new Date();
        timeBegin = new Date(timeEnd.getTime() - period);
        logger.debug("No begin or end is specified, use now as end and now-period as begin.");
    } else if (timeEnd == null) {
        timeEnd = new Date(timeBegin.getTime() + period);
        logger.debug("No end is specified, use begin + period as end.");
    } else if (timeBegin == null) {
        timeBegin = new Date(timeEnd.getTime() - period);
        logger.debug("No begin is specified, use end-period as begin");
    } else if (timeEnd.before(timeBegin)) {
        throw new ServletException("The end is before the begin.");
    }

    // If a persistence service is specified, find the provider
    String serviceName = req.getParameter("service");

    ChartProvider provider = getChartProviders().get(providerName);
    if (provider == null) {
        res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not get chart provider.");
        return;
    }

    // Read out the parameter 'dpi'
    Integer dpi = null;
    if (req.getParameter("dpi") != null) {
        try {
            dpi = Integer.valueOf(req.getParameter("dpi"));
        } catch (NumberFormatException e) {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST, "dpi parameter is invalid");
            return;
        }
        if (dpi <= 0) {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST, "dpi parameter is <= 0");
            return;
        }
    }

    // Read out parameter 'legend'
    Boolean legend = null;
    if (req.getParameter("legend") != null) {
        legend = BooleanUtils.toBoolean(req.getParameter("legend"));
    }

    if (maxWidth > 0 && width > maxWidth) {
        height = Math.round((float) height / (float) width * maxWidth);
        if (dpi != null) {
            dpi = Math.round((float) dpi / (float) width * maxWidth);
        }
        width = maxWidth;
    }

    // Set the content type to that provided by the chart provider
    res.setContentType("image/" + provider.getChartType());
    logger.debug("chart building with width {} height {} dpi {}", width, height, dpi);
    try (ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(res.getOutputStream())) {
        BufferedImage chart = provider.createChart(serviceName, req.getParameter("theme"), timeBegin, timeEnd,
                height, width, req.getParameter("items"), req.getParameter("groups"), dpi, legend);
        ImageIO.write(chart, provider.getChartType().toString(), imageOutputStream);
        logger.debug("Chart successfully generated and written to the response.");
    } catch (ItemNotFoundException e) {
        logger.debug("{}", e.getMessage());
        res.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
    } catch (IllegalArgumentException e) {
        logger.warn("Illegal argument in chart: {}", e.getMessage());
        res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument in chart: " + e.getMessage());
    } catch (IIOException | EOFException e) {
        // this can happen if the request is terminated while the image is streamed, see
        // https://github.com/openhab/openhab-distro/issues/684
        logger.debug("Failed writing image to response stream", e);
    } catch (RuntimeException e) {
        if (logger.isDebugEnabled()) {
            // we also attach the stack trace
            logger.warn("Chart generation failed: {}", e.getMessage(), e);
        } else {
            logger.warn("Chart generation failed: {}", e.getMessage());
        }
        res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}

From source file:fr.cs.examples.bodies.DEFile.java

private void processHeader() throws IOException, OrekitException {

    first = readFirstRecord();/*from  www .j  ava  2s.  c  om*/
    second = new byte[recordSize];
    readInRecord(second, 0);

    label1 = extractString(first, HEADER_LABEL_1_OFFSET, HEADER_LABEL_SIZE);
    label2 = extractString(first, HEADER_LABEL_2_OFFSET, HEADER_LABEL_SIZE);
    label3 = extractString(first, HEADER_LABEL_3_OFFSET, HEADER_LABEL_SIZE);

    // constants defined in the file
    for (int i = 0; i < CONSTANTS_MAX_NUMBER; ++i) {
        // Note: for extracting the strings from the binary file, it makes no difference
        //       if the file is stored in big-endian or little-endian notation
        final String constantName = extractString(first, HEADER_CONSTANTS_NAMES_OFFSET + i * 6, 6);
        if (constantName.length() == 0) {
            // no more constants to read
            break;
        }
        final double constantValue = extractDouble(second, HEADER_CONSTANTS_VALUES_OFFSET + 8 * i, bigEndian);
        headerConstants.put(constantName, constantValue);
    }

    final Double timesc = headerConstants.get("TIMESC");
    if (timesc != null && !Double.isNaN(timesc) && timesc.intValue() == 1) {
        timeScale = TimeScalesFactory.getTCB();
    } else {
        timeScale = TimeScalesFactory.getTDB();
    }

    headerStartEpoch = extractDate(first, HEADER_START_EPOCH_OFFSET, bigEndian);
    headerFinalEpoch = extractDate(first, HEADER_END_EPOCH_OFFSET, bigEndian);

}

From source file:org.mapfish.print.config.Config.java

/**
 * @return The first scale that is bigger or equal than the target.
 *//*ww  w.  j ava 2  s .  c om*/
public int getBestScale(double target) {
    if (this.disableScaleLocking) {
        Double forcedScale = target;
        return forcedScale.intValue();
    } else {
        target *= BEST_SCALE_TOLERANCE;
        for (Integer scale : scales) {
            if (scale >= target) {
                return scale;
            }
        }
        return scales.last();
    }

}

From source file:nl.b3p.gis.viewer.PrintAction.java

/**
 * Calculate new scale given a ppi, map width and paper size
 *
 * @see//www.  j a v  a  2 s . c  o m
 * http://www.britishideas.com/2009/09/22/map-scales-and-printing-with-mapnik/
 *
 */
private Integer calcScaleForHigherPPI(Integer ppi, Integer mapWidthInMeters, Double paperWidthInInches) {

    float pixelSize = calcPixelSizeForResolution(ppi);
    Integer newMapWidth = calcNewMapWidthFromPPI(ppi, paperWidthInInches);

    Double schaal = Math.ceil(mapWidthInMeters / (newMapWidth * pixelSize));

    return schaal.intValue();
}

From source file:org.ietr.preesm.mapper.ui.MyGanttRenderer.java

/**
 * Given a color c, returns a random color close to c
 *//*from   ww  w  .j  a  v a  2  s .  co m*/
private Color getRandomColor(Double r, Double g, Double b, int liberty) {

    r = Math.random() * liberty + r;
    g = Math.random() * liberty + g;
    b = Math.random() * liberty + b;

    r = Math.max(0, Math.min(r, 255));
    g = Math.max(0, Math.min(g, 255));
    b = Math.max(0, Math.min(b, 255));

    Color c = new Color(r.intValue(), g.intValue(), b.intValue());

    return c;
}