Example usage for java.lang Math floorDiv

List of usage examples for java.lang Math floorDiv

Introduction

In this page you can find the example usage for java.lang Math floorDiv.

Prototype

public static long floorDiv(long x, long y) 

Source Link

Document

Returns the largest (closest to positive infinity) long value that is less than or equal to the algebraic quotient.

Usage

From source file:com.github.lynxdb.server.core.repository.EntryRepo.java

public static int getGroup(long _timestamp) {
    return (int) Math.floorDiv(_timestamp, GROUP_WIDTH);
}

From source file:com.github.lynxdb.server.api.http.mappers.QueryRequest.java

/**
 * //from  w w  w  . j a  va2 s  .co  m
 * Only supporting UTC timezone rightnow
 * 
 * @param _time (String|Integer|Long) the time to Object to parse
 * @return the time in s
 * @throws InvalidTimeException 
 */
public static long parseTime(Object _time) throws InvalidTimeException {
    if (_time instanceof Integer || _time instanceof Long) {
        if ((long) _time > Integer.MAX_VALUE) {
            return Math.floorDiv((long) _time, 1000);
        }
        return (long) _time;
    } else if (_time instanceof String) {
        String time = _time.toString();
        if (time.endsWith("-ago")) {
            long amount = parseDuration(time.substring(0, time.length() - 4));
            if (amount >= 1000) {
                return Math.floorDiv((System.currentTimeMillis() - amount), 1000);
            } else {
                throw new InvalidTimeException(
                        "Invalid time : " + _time + ". Must be greater than or equal to 1s");
            }
        } else {
            SimpleDateFormat fmt;
            switch (time.length()) {
            case 10:
                fmt = new SimpleDateFormat("yyyy/MM/dd");
                break;
            case 16:
                if (time.contains("-")) {
                    fmt = new SimpleDateFormat("yyyy/MM/dd-HH:mm");
                } else {
                    fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm");
                }
                break;
            case 19:
                if (time.contains("-")) {
                    fmt = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
                } else {
                    fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                }
                break;
            default:
                throw new InvalidTimeException("Invalid time date : " + _time);
            }
            fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
            try {
                return Math.floorDiv(fmt.parse(time).getTime(), 1000);
            } catch (ParseException ex) {
                throw new InvalidTimeException("Invalid time date : " + _time);
            }
        }
    } else {
        throw new InvalidTimeException("Unsupported time type : " + _time);
    }
}

From source file:sacm.Comparision.java

public void map(double[][] x, double[][] y) {
    double[][] predicted = x;
    double[][] groundTruth = y;
    int rel = 0;//from  ww  w  . j a  v  a2s. co m
    double map = 0.0;
    double AveP;
    double[] p_rev = new double[numAspects];
    int Q = Math.floorDiv(numDocs, 10);
    for (int ai = 0; ai < numAspects; ai++) {
        //Arrays.sort(predicted[ai]);
        //Arrays.sort(groundTruth[ai]);
        bubbleSort(predicted[ai]);
        bubbleSort(groundTruth[ai]);
        for (int di = 0; di < Q; di++) {
            for (int aii = 0; aii < numAspects; aii++) {
                double match = predicted[di][ai];
                for (int dii = 0; dii < Q; dii++) {
                    if (groundTruth[dii][aii] == match) {
                        rel++;
                    } else {
                        rel += 0;
                    }
                }
            }
            double pre = rel / Q;
            AveP = (pre * rel) / Q;
            map += AveP;
        }

    }

}

From source file:com.github.lynxdb.server.core.Aggregator.java

protected TimeSerie doDownsampling(TimeSerie _serie, long _period, Reducer _reducer) {
    return new TimeSerie(_serie.getName(), _serie.getTags(), new ChainableIterator<Entry>() {

        int lower;
        Entry last = null;/*from w  w w .  jav  a  2  s. c  o m*/

        @Override
        public boolean hasNext() {
            return _serie.hasNext() || last != null;
        }

        @Override
        public Entry next() {
            _reducer.reset();
            if (last == null) {
                Entry e = _serie.next();
                lower = (int) (_period * Math.floorDiv(e.getTime(), _period));
                _reducer.update(e);
            } else {
                lower = (int) (_period * Math.floorDiv(last.getTime(), _period));
                _reducer.update(last);
                last = null;
            }
            while (_serie.hasNext()) {
                last = _serie.next();
                if (last.getTime() > lower) {
                    _reducer.update(last);
                } else {
                    break;
                }
            }
            return new Entry(lower, _reducer.result());
        }
    });
}

From source file:model.SensorData.java

public static List<SensorData> getSensorData(Integer start, Integer limit) {

    int page = Math.floorDiv(start, limit);

    List<SensorData> sensorList = new ArrayList<SensorData>();
    if (start != null && limit != null) {
        sensorList = find.where().orderBy("dateTime desc").findPagingList(limit).setFetchAhead(false)
                .getPage(page).getList();
    } else {/*w w  w.  ja  v  a2 s.c  o  m*/
        sensorList = find.where().orderBy("dateTime desc").findList();
    }
    return sensorList;
}

From source file:com.neu.edu.hw5p5.controller.CsvController.java

@Override
public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    HttpSession session = hsr.getSession();
    String action = hsr.getParameter("action");
    String fileName;/*from   www . j ava2 s .c  om*/

    int k = 1;
    int rows = 0;
    ModelAndView mv = new ModelAndView();
    int content;
    int pageNumberDisplay;
    if (action.equals("showDetails")) {

        int paginationButtons;

        if (hsr.getParameter("entryPage").equals("true")) {
            fileName = hsr.getParameter("fileName");
            session.setAttribute("fileName", fileName);

            try {
                Class.forName("org.relique.jdbc.csv.CsvDriver");
                Connection conn = DriverManager.getConnection("jdbc:relique:csv:C:");
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery("SELECT * FROM " + fileName);

                int totalRows = 0;
                while (rs.next()) {
                    totalRows += 1;
                }
                content = Integer.parseInt(hsr.getParameter("defaultContent"));

                pageNumberDisplay = content * 100;
                rs = stmt.executeQuery("SELECT * FROM " + fileName + " LIMIT 100 OFFSET " + pageNumberDisplay);
                ArrayList<SalesOrder> salesOrderArrayList = new ArrayList<>();

                while (rs.next()) {
                    SalesOrder s = new SalesOrder();
                    s.setAccountnumber(rs.getString("accountnumber"));
                    s.setBilltoaddressid(rs.getString("billtoaddressid"));
                    s.setComment(rs.getString("comment"));
                    s.setCreditcardapprovalcode(rs.getString("creditcardapprovalcode"));
                    s.setCreditcardid(rs.getString("creditcardid"));
                    s.setCurrencyrateid(rs.getString("currencyrateid"));
                    s.setCustomerid(rs.getString("customerid"));
                    s.setDuedate(rs.getString("duedate"));
                    s.setFreight(rs.getString("freight"));
                    s.setModifieddate(rs.getString("modifieddate"));
                    s.setOnlineorderflag(rs.getString("onlineorderflag"));
                    s.setOrderdate(rs.getString("orderdate"));
                    s.setPurchaseordernumber(rs.getString("purchaseordernumber"));
                    s.setRevisionnumber(rs.getString("revisionnumber"));
                    s.setSalesorderid(rs.getString("salesorderid"));
                    s.setSalesordernumber(rs.getString("salesordernumber"));
                    s.setSalespersonid(rs.getString("salespersonid"));
                    s.setShipdate(rs.getString("shipdate"));
                    s.setShipmethodid(rs.getString("shipmethodid"));
                    s.setShiptoaddressid(rs.getString("shiptoaddressid"));
                    s.setStatus(rs.getString("status"));
                    s.setSubtotal(rs.getString("subtotal"));
                    s.setTaxamt(rs.getString("taxamt"));
                    s.setTerritoryid(rs.getString("territoryid"));
                    s.setTotaldue(rs.getString("totaldue"));
                    salesOrderArrayList.add(s);
                    rows = rows + 1;

                }

                session.setAttribute("salesOrderList", salesOrderArrayList);
                session.setAttribute("rowsDisplayed", 100);
                session.setAttribute("defaultContent", content + 1);
                String pageNumber = "a";
                hsr.setAttribute("pageNumber", pageNumber);
                mv.setViewName("index");
                conn.close();

                if (totalRows % 100 == 0) {
                    paginationButtons = totalRows / 100;
                    session.setAttribute("paginationButtons", paginationButtons);
                } else {
                    paginationButtons = Math.floorDiv(totalRows, 100) + 1;
                    session.setAttribute("paginationButtons", paginationButtons);

                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        } else {

            fileName = (String) session.getAttribute("fileName");

            content = (Integer) session.getAttribute("defaultContent");
            //content=Integer.parseInt(hsr.getParameter("content"));
            pageNumberDisplay = content * 100;
            try {

                Class.forName("org.relique.jdbc.csv.CsvDriver");

                Connection conn = DriverManager.getConnection("jdbc:relique:csv:C:");

                Statement stmt = conn.createStatement();

                ResultSet rs = stmt
                        .executeQuery("SELECT * FROM " + fileName + " LIMIT 100 OFFSET " + pageNumberDisplay);

                ArrayList<SalesOrder> salesOrderArrayList = new ArrayList<>();

                while (rs.next()) {
                    SalesOrder s = new SalesOrder();
                    s.setAccountnumber(rs.getString("accountnumber"));
                    s.setBilltoaddressid(rs.getString("billtoaddressid"));
                    s.setComment(rs.getString("comment"));
                    s.setCreditcardapprovalcode(rs.getString("creditcardapprovalcode"));
                    s.setCreditcardid(rs.getString("creditcardid"));
                    s.setCurrencyrateid(rs.getString("currencyrateid"));
                    s.setCustomerid(rs.getString("customerid"));
                    s.setDuedate(rs.getString("duedate"));
                    s.setFreight(rs.getString("freight"));
                    s.setModifieddate(rs.getString("modifieddate"));
                    s.setOnlineorderflag(rs.getString("onlineorderflag"));
                    s.setOrderdate(rs.getString("orderdate"));
                    s.setPurchaseordernumber(rs.getString("purchaseordernumber"));
                    s.setRevisionnumber(rs.getString("revisionnumber"));
                    s.setSalesorderid(rs.getString("salesorderid"));
                    s.setSalesordernumber(rs.getString("salesordernumber"));
                    s.setSalespersonid(rs.getString("salespersonid"));
                    s.setShipdate(rs.getString("shipdate"));
                    s.setShipmethodid(rs.getString("shipmethodid"));
                    s.setShiptoaddressid(rs.getString("shiptoaddressid"));
                    s.setStatus(rs.getString("status"));
                    s.setSubtotal(rs.getString("subtotal"));
                    s.setTaxamt(rs.getString("taxamt"));
                    s.setTerritoryid(rs.getString("territoryid"));
                    s.setTotaldue(rs.getString("totaldue"));
                    salesOrderArrayList.add(s);
                    rows = rows + 1;

                }

                int rowsDisplayed = pageNumberDisplay + 100;
                System.out.println(content + "default Content");
                session.setAttribute("defaultContent", content + 1);
                session.setAttribute("rowsDisplayed", rowsDisplayed);
                JSONObject obj = new JSONObject();
                obj.put("salesOrderList", salesOrderArrayList);
                obj.put("countForMoreRows", pageNumberDisplay);
                PrintWriter out = hsr1.getWriter();
                out.print(obj);
                String pageNumber = "a";
                session.setAttribute("paginationHelp", content);
                hsr.setAttribute("pageNumber", pageNumber);
                mv.setViewName("index");
                conn.close();
                return null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
    SalesOrder s = new SalesOrder();
    if (action.equals("addToDB")) {
        String pageNumber = "b";
        hsr.setAttribute("pageNumber", pageNumber);

        System.out.println("account number " + hsr.getParameter("accountnumber"));
        s.setAccountnumber(hsr.getParameter("accountnumber"));
        System.out.println("Account number from bean=" + s.getAccountnumber());
        s.setBilltoaddressid(hsr.getParameter("billtoaddressid"));
        s.setComment(hsr.getParameter("comment"));
        s.setCreditcardapprovalcode(hsr.getParameter("creditcardapprovalcode"));
        s.setCreditcardid(hsr.getParameter("creditcardid"));
        s.setCurrencyrateid(hsr.getParameter("currencyrateid"));
        s.setCustomerid(hsr.getParameter("customerid"));
        s.setDuedate(hsr.getParameter("duedate"));
        s.setFreight(hsr.getParameter("freight"));
        s.setModifieddate(hsr.getParameter("modifieddate"));
        s.setOnlineorderflag(hsr.getParameter("onlineorderflag"));
        s.setOrderdate(hsr.getParameter("orderdate"));
        s.setPurchaseordernumber(hsr.getParameter("purchaseordernumber"));
        s.setRevisionnumber(hsr.getParameter("revisionnumber"));
        s.setSalesorderid(hsr.getParameter("salesorderid"));
        s.setSalesordernumber(hsr.getParameter("salesordernumber"));
        s.setSalespersonid(hsr.getParameter("salespersonid"));
        s.setShipdate(hsr.getParameter("shipdate"));
        s.setShipmethodid(hsr.getParameter("shipmethodid"));
        s.setShiptoaddressid(hsr.getParameter("shiptoaddressid"));
        s.setStatus(hsr.getParameter("status"));
        s.setSubtotal(hsr.getParameter("subtotal"));
        s.setTaxamt(hsr.getParameter("taxamt"));
        s.setTerritoryid(hsr.getParameter("territoryid"));
        s.setTotaldue(hsr.getParameter("totaldue"));
        uploadDAO.uploadDatatoDB(s);

        // }
        // hsr.setAttribute("rowsAdded", salesOrderArrayList.size());
        mv.setViewName("index");//dbUpdated
    }
    return mv;
}

From source file:com.neu.edu.hw5p4.controller.CsvController.java

@Override
public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    HttpSession session = hsr.getSession();
    String action = hsr.getParameter("action");
    String fileName;//  ww  w  .  j ava 2s  . c om

    int k = 1;
    int rows = 0;
    ModelAndView mv = new ModelAndView();
    int content;
    int pageNumberDisplay;
    if (action.equals("showDetails")) {

        int paginationButtons;

        if (hsr.getParameter("entryPage").equals("true")) {
            fileName = hsr.getParameter("fileName");

            session.setAttribute("fileName", fileName);

            System.out.println("session out file name" + session.getAttribute("fileName"));

            try {
                Class.forName("org.relique.jdbc.csv.CsvDriver");
                Connection conn = DriverManager.getConnection("jdbc:relique:csv:D:");
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery("SELECT * FROM " + fileName);

                int totalRows = 0;
                while (rs.next()) {
                    totalRows += 1;
                }
                content = Integer.parseInt(hsr.getParameter("defaultContent"));
                System.out.println("---------------" + hsr.getParameter("defaultContent"));
                pageNumberDisplay = content * 100;
                rs = stmt.executeQuery("SELECT * FROM " + fileName + " LIMIT 100 OFFSET " + pageNumberDisplay);
                ArrayList<SalesOrder> salesOrderArrayList = new ArrayList<>();

                while (rs.next()) {
                    SalesOrder s = new SalesOrder();
                    s.setAccountnumber(rs.getString("accountnumber"));
                    s.setBilltoaddressid(rs.getString("billtoaddressid"));
                    s.setComment(rs.getString("comment"));
                    s.setCreditcardapprovalcode(rs.getString("creditcardapprovalcode"));
                    s.setCreditcardid(rs.getString("creditcardid"));
                    s.setCurrencyrateid(rs.getString("currencyrateid"));
                    s.setCustomerid(rs.getString("customerid"));
                    s.setDuedate(rs.getString("duedate"));
                    s.setFreight(rs.getString("freight"));
                    s.setModifieddate(rs.getString("modifieddate"));
                    s.setOnlineorderflag(rs.getString("onlineorderflag"));
                    s.setOrderdate(rs.getString("orderdate"));
                    s.setPurchaseordernumber(rs.getString("purchaseordernumber"));
                    s.setRevisionnumber(rs.getString("revisionnumber"));
                    s.setSalesorderid(rs.getString("salesorderid"));
                    s.setSalesordernumber(rs.getString("salesordernumber"));
                    s.setSalespersonid(rs.getString("salespersonid"));
                    s.setShipdate(rs.getString("shipdate"));
                    s.setShipmethodid(rs.getString("shipmethodid"));
                    s.setShiptoaddressid(rs.getString("shiptoaddressid"));
                    s.setStatus(rs.getString("status"));
                    s.setSubtotal(rs.getString("subtotal"));
                    s.setTaxamt(rs.getString("taxamt"));
                    s.setTerritoryid(rs.getString("territoryid"));
                    s.setTotaldue(rs.getString("totaldue"));
                    salesOrderArrayList.add(s);
                    rows = rows + 1;

                }

                session.setAttribute("salesOrderList", salesOrderArrayList);
                String pageNumber = "a";
                session.setAttribute("paginationHelp", content);
                hsr.setAttribute("pageNumber", pageNumber);
                mv.setViewName("index");//viewDetails
                conn.close();
                System.out.println("RowsCount" + totalRows);

                if (totalRows % 100 == 0) {
                    paginationButtons = totalRows / 100;
                    session.setAttribute("paginationButtons", paginationButtons);
                } else {
                    paginationButtons = Math.floorDiv(totalRows, 100) + 1;
                    session.setAttribute("paginationButtons", paginationButtons);

                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        } else {

            fileName = (String) session.getAttribute("fileName");
            System.out.println("file name " + fileName);
            System.out.println("---------------" + hsr.getParameter("defaultContent"));
            content = Integer.parseInt(hsr.getParameter("defaultContent"));
            System.out.println("---------------" + hsr.getParameter("defaultContent"));
            //content=Integer.parseInt(hsr.getParameter("content"));
            pageNumberDisplay = content * 100;
            try {

                Class.forName("org.relique.jdbc.csv.CsvDriver");

                Connection conn = DriverManager.getConnection("jdbc:relique:csv:D:");

                Statement stmt = conn.createStatement();

                ResultSet rs = stmt
                        .executeQuery("SELECT * FROM " + fileName + " LIMIT 100 OFFSET " + pageNumberDisplay);

                ResultSetMetaData rsmd = rs.getMetaData();
                int colums = rsmd.getColumnCount();

                ArrayList<SalesOrder> salesOrderArrayList = new ArrayList<>();

                while (rs.next()) {
                    SalesOrder s = new SalesOrder();
                    s.setAccountnumber(rs.getString("accountnumber"));
                    s.setBilltoaddressid(rs.getString("billtoaddressid"));
                    s.setComment(rs.getString("comment"));
                    s.setCreditcardapprovalcode(rs.getString("creditcardapprovalcode"));
                    s.setCreditcardid(rs.getString("creditcardid"));
                    s.setCurrencyrateid(rs.getString("currencyrateid"));
                    s.setCustomerid(rs.getString("customerid"));
                    s.setDuedate(rs.getString("duedate"));
                    s.setFreight(rs.getString("freight"));
                    s.setModifieddate(rs.getString("modifieddate"));
                    s.setOnlineorderflag(rs.getString("onlineorderflag"));
                    s.setOrderdate(rs.getString("orderdate"));
                    s.setPurchaseordernumber(rs.getString("purchaseordernumber"));
                    s.setRevisionnumber(rs.getString("revisionnumber"));
                    s.setSalesorderid(rs.getString("salesorderid"));
                    s.setSalesordernumber(rs.getString("salesordernumber"));
                    s.setSalespersonid(rs.getString("salespersonid"));
                    s.setShipdate(rs.getString("shipdate"));
                    s.setShipmethodid(rs.getString("shipmethodid"));
                    s.setShiptoaddressid(rs.getString("shiptoaddressid"));
                    s.setStatus(rs.getString("status"));
                    s.setSubtotal(rs.getString("subtotal"));
                    s.setTaxamt(rs.getString("taxamt"));
                    s.setTerritoryid(rs.getString("territoryid"));
                    s.setTotaldue(rs.getString("totaldue"));
                    salesOrderArrayList.add(s);
                    rows = rows + 1;

                }

                session.setAttribute("salesOrderList", salesOrderArrayList);
                session.setAttribute("columCount", colums);

                String pageNumber = "a";
                session.setAttribute("paginationHelp", content);
                hsr.setAttribute("pageNumber", pageNumber);
                mv.setViewName("index");//viewDetails
                conn.close();

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
    SalesOrder s = new SalesOrder();
    if (action.equals("addToDB")) {
        String pageNumber = "b";
        hsr.setAttribute("pageNumber", pageNumber);

        System.out.println("account number " + hsr.getParameter("accountnumber"));
        s.setAccountnumber(hsr.getParameter("accountnumber"));
        System.out.println("Account number from bean=" + s.getAccountnumber());
        s.setBilltoaddressid(hsr.getParameter("billtoaddressid"));
        s.setComment(hsr.getParameter("comment"));
        s.setCreditcardapprovalcode(hsr.getParameter("creditcardapprovalcode"));
        s.setCreditcardid(hsr.getParameter("creditcardid"));
        s.setCurrencyrateid(hsr.getParameter("currencyrateid"));
        s.setCustomerid(hsr.getParameter("customerid"));
        s.setDuedate(hsr.getParameter("duedate"));
        s.setFreight(hsr.getParameter("freight"));
        s.setModifieddate(hsr.getParameter("modifieddate"));
        s.setOnlineorderflag(hsr.getParameter("onlineorderflag"));
        s.setOrderdate(hsr.getParameter("orderdate"));
        s.setPurchaseordernumber(hsr.getParameter("purchaseordernumber"));
        s.setRevisionnumber(hsr.getParameter("revisionnumber"));
        s.setSalesorderid(hsr.getParameter("salesorderid"));
        s.setSalesordernumber(hsr.getParameter("salesordernumber"));
        s.setSalespersonid(hsr.getParameter("salespersonid"));
        s.setShipdate(hsr.getParameter("shipdate"));
        s.setShipmethodid(hsr.getParameter("shipmethodid"));
        s.setShiptoaddressid(hsr.getParameter("shiptoaddressid"));
        s.setStatus(hsr.getParameter("status"));
        s.setSubtotal(hsr.getParameter("subtotal"));
        s.setTaxamt(hsr.getParameter("taxamt"));
        s.setTerritoryid(hsr.getParameter("territoryid"));
        s.setTotaldue(hsr.getParameter("totaldue"));
        uploadDAO.uploadDatatoDB(s);

        // }
        // hsr.setAttribute("rowsAdded", salesOrderArrayList.size());
        mv.setViewName("index");//dbUpdated
    }
    return mv;
}

From source file:com.github.lynxdb.server.api.http.handlers.EpQuery.java

private List<Query> parseQuery(Vhost _vhost, QueryRequest _request) throws ParsingQueryException {
    List<Query> queries = new ArrayList<>();
    for (QueryRequest.Query q : _request.queries) {
        Builder b = Query.newBuilder();

        b.setAction(Query.Action.GET);
        b.setName(q.metric);/*from w  w  w. j a  v  a  2  s. c o  m*/
        if (q.tags != null) {
            b.setTags(q.tags);
        }
        b.setVhost(_vhost);
        b.setRate(q.rate);
        if (q.rateOptions != null) {
            Query.RateOptions.Builder rob = Query.RateOptions.newBuilder();

            rob.setCounter(q.rateOptions.counter);
            rob.setCounterMax(q.rateOptions.counterMax);
            rob.setResetValue(q.rateOptions.resetValue);

            b.setRateOptions(rob.build());
        }

        Aggregator agg = aggregators.get().get(q.aggregator);

        if (agg == null) {
            throw new ParsingQueryException("Aggregator " + q.aggregator + " does not exist.");
        }

        b.setAggregator(agg);

        try {
            b.setStart(QueryRequest.parseTime(_request.start));
        } catch (InvalidTimeException ex) {
            throw new ParsingQueryException(ex.getMessage());
        }

        if (_request.end == null) {
            b.setEnd(Math.floorDiv(System.currentTimeMillis(), 1000));
        } else {
            try {
                b.setEnd(QueryRequest.parseTime(_request.end));
            } catch (InvalidTimeException ex) {
                throw new ParsingQueryException(ex.getMessage());
            }
        }

        if (q.downsample != null && !q.downsample.isEmpty()) {
            Query.Downsampling.Builder dsb = Query.Downsampling.newBuilder();

            try {
                long time = QueryRequest.parseDuration(q.downsample.split("-")[0]);
                if (time >= 1000) {
                    dsb.setPeriod((int) Math.floorDiv(time, 1000));
                } else {
                    throw new ParsingQueryException(
                            "Downsampling period too short. Must be greater than or equal to 1s");
                }
            } catch (InvalidTimeException ex) {
                throw new ParsingQueryException(ex.getMessage());
            }
            Aggregator dsagg = aggregators.get().get(q.downsample.split("-")[1]);

            if (dsagg == null) {
                throw new ParsingQueryException(
                        "Aggregator " + q.downsample.split("-")[1] + " does not exist.");
            }
            dsb.setAggregator(dsagg);

            b.setDownsampling(dsb.build());
        }

        queries.add(b.build());

    }

    return queries;
}

From source file:org.opennms.netmgt.bsm.service.internal.DefaultBusinessServiceStateMachine.java

/**
 * Apply the edges weights to the associated statuses set in the map,
 * ignoring the actual status stored in the edge. Can be used for simulations
 * without needing to change the actual edge's status.
 *
 * @param edgesWithStatus//  ww w .j a  v  a2 s . c  om
 * @return
 */
public static List<Status> weighStatuses(Map<GraphEdge, Status> edgesWithStatus) {
    // Find the greatest common divisor of all the weights
    int gcd = edgesWithStatus.keySet().stream().map(e -> e.getWeight())
            .reduce((a, b) -> BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue()).orElse(1);

    // Multiply the statuses based on their relative weight
    List<Status> statuses = Lists.newArrayList();
    for (Entry<GraphEdge, Status> entry : edgesWithStatus.entrySet()) {
        int relativeWeight = Math.floorDiv(entry.getKey().getWeight(), gcd);
        for (int i = 0; i < relativeWeight; i++) {
            statuses.add(entry.getValue());
        }
    }

    return statuses;
}

From source file:com.joyent.manta.benchmark.Benchmark.java

/**
 * Calculates the number of iterations to run per thread.
 *
 * @param iterations number of iterations to run
 * @param concurrency number of threads to run
 * @return iterations / concurrency properly rounded
 *///from   w  w w .  j  av  a2 s  .  c o  m
private static long perThreadCount(final int iterations, final int concurrency) {
    return (long) Math.floorDiv(iterations, concurrency);
}