Example usage for java.lang Math ceil

List of usage examples for java.lang Math ceil

Introduction

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

Prototype

public static double ceil(double a) 

Source Link

Document

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:bb.mcmc.analysis.ConvergeStatUtils.java

protected static int[] thinWindow(int[] array, int kthin) {

    if (kthin == 1) {
        return array;
    } else {/*from w  w w  .  j  a  v a2 s  .  c  o  m*/
        final int count = (int) Math.ceil(array.length / (double) kthin);
        final int[] newArray = new int[count];

        for (int i = 0; i < newArray.length; i++) {
            newArray[i] = array[kthin * i];
        }
        return newArray;
    }

}

From source file:com.app.inventario.logica.FamiliaLogicaImpl.java

@Transactional(readOnly = true)
public jqGridModel obtenerListaTodos(int numeroPagina, int numeroFilas, String ordenarPor, String ordenarAsc)
        throws Exception {
    modelo = new jqGridModel<Familia>();
    int primerResultado = numeroFilas * (numeroPagina - 1);
    List<Familia> familias = null;
    try {/*  w  w w.  j  a v  a 2 s.co m*/
        familias = familiaDAO.obtenerTodosAGrid(ordenarPor, ordenarAsc);
        modelo.setPage(numeroPagina);
        modelo.setTotal((int) Math.ceil((double) familias.size() / (double) numeroFilas));
        modelo.setRecords(familias.size());
        modelo.setRows(familias.subList(primerResultado,
                numeroFilas > familias.size() ? familias.size() : numeroFilas));
        return modelo;
    } catch (HibernateException he) {
        Logger.getLogger(UsuarioLogicaImpl.class.getName()).log(Level.SEVERE, null, he);
        throw he;
    }
}

From source file:com.tcc.servidor_tcc.api.SystematicReviewResource.java

@POST
@Consumes(MediaType.APPLICATION_JSON)/*from   w  ww  .j  a v  a  2  s .  c o  m*/
@Produces(MediaType.APPLICATION_JSON)
public Response createSR(SystematicReview sr, @HeaderParam("Authorization") String jwt) {
    try {
        String email = Token.getClientEmail(jwt);
        ReviewerDAO reviewerDAO = new ReviewerDAOjpa();
        Optional<Reviewer> rev = reviewerDAO.getOne(email);
        if (rev.isPresent()) {
            sr.setOwner(rev.get());
        } else {
            throw new RuntimeException("Trying to set as owner a reviewer that does not exist");
        }
        inviteReviewers(reviewerDAO, sr);
        for (ReviewerRole rr : sr.getParticipatingReviewers()) {
            Optional<Reviewer> participatingReviewer = reviewerDAO.getOne(rr.getReviewer().getEmail());
            if (participatingReviewer.isPresent()) {
                rr.setReviewer(participatingReviewer.get());
            }
        }
        PaperDivisionType divisionType = sr.getDivisionType();
        if (divisionType.equals(PaperDivisionType.SPLIT)) {
            List<ReviewerRole> selectionParticipants = sr.getParticipatingReviewers().stream()
                    .filter(rr -> rr.getRoles().contains(RoleType.SELECTION)).collect(Collectors.toList());
            int participantsCount = selectionParticipants.size() + 1;
            List<List<Study>> studies = com.google.common.collect.Lists.partition(sr.getBib().getStudies(),
                    (int) Math.ceil((double) sr.getBib().getStudies().size() / participantsCount));
            for (int x = 0; x < studies.size(); x++) {
                if (x == 0) {
                    studies.get(0).stream().forEach(study -> {
                        ReviewedStudy rs = new ReviewedStudy();
                        rs.setStudy(study);
                        rs.setReviewer(sr.getOwner());
                        study.addReviewedStudy(rs);
                    });
                } else {
                    final int pos = x - 1;
                    studies.get(x).stream().forEach(study -> {
                        ReviewedStudy rs = new ReviewedStudy();
                        rs.setStudy(study);
                        rs.setReviewer(selectionParticipants.get(pos).getReviewer());
                        study.addReviewedStudy(rs);
                    });
                }
            }
        } else {
            List<Study> studies = sr.getBib().getStudies();
            for (int x = 0; x < sr.getParticipatingReviewers().size(); x++) {
                if (x == 0) {
                    studies.stream().forEach(study -> {
                        ReviewedStudy rs = new ReviewedStudy();
                        rs.setStudy(study);
                        rs.setReviewer(sr.getOwner());
                        study.addReviewedStudy(rs);
                    });
                } else {
                    final int pos = x;
                    studies.stream().forEach(study -> {
                        ReviewedStudy rs = new ReviewedStudy();
                        rs.setStudy(study);
                        rs.setReviewer(sr.getParticipatingReviewers().get(pos - 1).getReviewer());
                        study.addReviewedStudy(rs);
                    });
                }
            }
        }
        SystematicReviewDAO srd = new SystematicReviewDAOjpa();
        srd.update(sr);
    } catch (Exception e) {
        e.printStackTrace();
        return Response.serverError().build();
    }
    return Response.ok().build();
}

From source file:web.ClientsController.java

@RequestMapping("/clients/viewclients/{pageid}")
public ModelAndView viewclients(@PathVariable int pageid, HttpServletRequest request) {
    int total = 25;
    int start = 1;

    if (pageid != 1) {
        start = (pageid - 1) * total + 1;
    }/*  w ww .  j a v  a2  s.com*/

    List<Clients> list = dao.getClientsByPage(start, total);

    HashMap<String, Object> context = new HashMap<String, Object>();
    context.put("list", list);

    int count = dao.getClientsCount();
    context.put("pages", Math.ceil((float) count / (float) total));

    context.put("page", pageid);

    Message msg = (Message) request.getSession().getAttribute("message");

    if (msg != null) {
        context.put("message", msg);
        request.getSession().removeAttribute("message");
    }

    return new ModelAndView("viewclients", context);
}

From source file:com.cooliris.media.UriTexture.java

private static int computeSampleSize(InputStream stream, int maxResolutionX, int maxResolutionY) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*  ww  w  .java 2  s.co m*/
    BitmapFactory.decodeStream(stream, null, options);

    double w = options.outWidth;
    double h = options.outHeight;

    int sampleSize = (int) Math.ceil(Math.max(w / maxResolutionX, h / maxResolutionY));
    return sampleSize;
}

From source file:com.jgeppert.struts2.jquery.grid.showcase.action.JsonOrderdetailsAction.java

public String execute() {
    log.debug("Details for Order : " + id);

    // Calcalate until rows ware selected
    int to = (rows * page);

    // Criteria to Build SQL

    if (id != null)
        gridModel = orderdetailsDao.findByOrder(id);

    Double priceeach = 0.0;//from  ww w .ja  v  a 2s. c o  m
    for (Orderdetails od : gridModel) {
        priceeach += od.getPriceeach();
    }
    userdata.put("priceeach", priceeach);
    userdata.put("productname", "Total :");

    records = gridModel.size();

    // Set to = max rows
    if (to > records)
        to = records;

    // Calculate total Pages
    total = (int) Math.ceil((double) records / (double) rows);

    return SUCCESS;
}

From source file:com.googlecode.jtiger.modules.ecside.view.html.FormBuilder.java

public void hiddenTotalField() {
    int currentRowsDisplayed = getTableModel().getLimit().getCurrentRowsDisplayed();
    int totalPages = 0;
    int totalRows = getTableModel().getLimit().getTotalRows();
    if (currentRowsDisplayed > 0) {
        totalPages = (int) Math.ceil((double) totalRows / currentRowsDisplayed);
    } else {/*w  ww  .  jav  a2 s.  c om*/
        totalPages = 1;
    }
    html.newline();
    html.input("hidden").name(model.getTableHandler().prefixWithTableId() + TableConstants.HIDDEN_TOTAL_PAGES)
            .value("" + totalPages).xclose();
    html.newline();
    html.input("hidden").name(model.getTableHandler().prefixWithTableId() + TableConstants.HIDDEN_TOTAL_ROWS)
            .value("" + totalRows).xclose();

}

From source file:CRM.web.ClientController.java

@RequestMapping("/clients/viewclients/{pageid}")
public ModelAndView viewclient(@PathVariable int pageid, HttpServletRequest request) {
    int total = 25;
    int start = 1;

    if (pageid != 1) {
        start = (pageid - 1) * total + 1;
    }/*from   w  ww.  java  2  s.  co m*/

    List<clients> list = dao.getClientsByPage(start, total);

    HashMap<String, Object> context = new HashMap<String, Object>();
    context.put("list", list);

    int count = dao.getClientCount();
    context.put("pages", Math.ceil((float) count / (float) total));

    context.put("page", pageid);

    Message msg = (Message) request.getSession().getAttribute("message");

    if (msg != null) {
        context.put("message", msg);
        request.getSession().removeAttribute("message");
    }

    return new ModelAndView("viewclients", context);
}

From source file:com.alibaba.wasp.master.balancer.BaseLoadBalancer.java

protected boolean needsBalance(ClusterLoadState cs) {
    // Check if we even need to do any load balancing
    float average = cs.getLoadAverage(); // for logging
    // HBASE-3681 check sloppiness first
    int floor = (int) Math.floor(average * (1 - slop));
    int ceiling = (int) Math.ceil(average * (1 + slop));

    return cs.getMinLoad() > ceiling || cs.getMaxLoad() < floor;
}

From source file:dk.netarkivet.wayback.LRUCache.java

/**
 * Creates a new LRU cache. Using filename as the key, and the cached file as the value.
 *
 * @param dir The directory where the file is stored.
 * @param cacheSize the maximum number of entries that will be kept in this cache.
 *///  w w w  . j  av a  2s . c o  m
public LRUCache(File dir, int cacheSize) {
    // Validate args
    ArgumentNotValid.checkPositive(cacheSize, "int cacheSize");
    ArgumentNotValid.checkNotNull(dir, "File dir");
    dir.mkdirs();
    ArgumentNotValid.checkTrue(dir.exists(), "Cachedir '" + dir.getAbsolutePath() + "' does not exist");

    this.cacheSize = cacheSize;
    this.cacheDir = dir;

    int hashTableCapacity = (int) Math.ceil(cacheSize / hashTableLoadFactor) + 1;
    map = new LinkedHashMap<String, File>(hashTableCapacity, hashTableLoadFactor, true) {
        // (an anonymous inner class)
        private static final long serialVersionUID = 1;

        @Override
        protected boolean removeEldestEntry(Map.Entry<String, File> eldest) {
            boolean removeEldest = size() > LRUCache.this.cacheSize;
            if (removeEldest) {
                logger.info("Deleting file '" + eldest.getValue().getAbsolutePath() + "' from cache.");
                boolean deleted = eldest.getValue().delete();
                if (!deleted) {
                    logger.warn("Unable to deleted LRU file from cache: " + eldest.getValue());
                }
            }
            return removeEldest;
        }
    };

    // fill up the map with the contents in cachedir
    // if the contents in cachedir exceeds the given cachesize,
    // change the size of the cache
    String[] cachedirFiles = cacheDir.list();
    logger.info(
            "Initializing the cache with the contents of the cachedir '" + cacheDir.getAbsolutePath() + "'");
    if (cachedirFiles.length > this.cacheSize) {
        logger.warn("Changed the cachesize from " + cacheSize + " to " + cachedirFiles.length);
        this.cacheSize = cachedirFiles.length;
    }
    for (String cachefile : cachedirFiles) {
        map.put(cachefile, new File(cacheDir, cachefile));
    }
    logger.info("The contents of the cache is now " + map.size() + " files");
}