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:es.ucm.fdi.dalgs.user.repository.UserRepository.java

public Integer numberOfPages() {

    Query query = em.createNativeQuery("select count(*) from user");
    logger.info(query.getSingleResult().toString());
    double dou = Double.parseDouble(query.getSingleResult().toString()) / ((double) noOfRecords);
    return (int) Math.ceil(dou);

}

From source file:com.cate.javatransmitter.FileHandler.java

public void setFile(Path inputPath) {
    //TODO add file selection
    this.inputPath = inputPath;
    try {//w w w  .j a  v  a  2s .c o  m
        this.sbc = Files.newByteChannel(inputPath, StandardOpenOption.READ);
        this.nofChunks = (int) Math.ceil((double) (sbc.size()) / packetSize);
        System.out.println("File Size = " + sbc.size() + " Bytes");
        System.out.println("File Size = " + sbc.size() + " Bytes");
    } catch (IOException ex) {
        Logger.getLogger(FileHandler.class.getName()).log(Level.SEVERE, null, ex);
        System.exit(0);
    }
    this.chunkCounter = 0;
    buf = ByteBuffer.allocate(packetSize);

    //catch (IOException x) {
    //    System.out.println("caught exception: " + x);        
    //        return null;
    //    }        
    //            
}

From source file:forge.deck.generation.DeckGeneratorBase.java

protected void addCreaturesAndSpells(int size, List<ImmutablePair<FilterCMC, Integer>> cmcLevels,
        boolean forAi) {
    tmpDeck.append("Building deck of ").append(size).append("cards\n");

    final Iterable<PaperCard> cards = selectCardsOfMatchingColorForPlayer(forAi);
    // build subsets based on type

    final Iterable<PaperCard> creatures = Iterables.filter(cards,
            Predicates.compose(CardRulesPredicates.Presets.IS_CREATURE, PaperCard.FN_GET_RULES));
    final int creatCnt = (int) Math.ceil(getCreatPercentage() * size);
    tmpDeck.append("Creatures to add:").append(creatCnt).append("\n");
    addCmcAdjusted(creatures, creatCnt, cmcLevels);

    Predicate<PaperCard> preSpells = Predicates
            .compose(CardRulesPredicates.Presets.IS_NONCREATURE_SPELL_FOR_GENERATOR, PaperCard.FN_GET_RULES);
    final Iterable<PaperCard> spells = Iterables.filter(cards, preSpells);
    final int spellCnt = (int) Math.ceil(getSpellPercentage() * size);
    tmpDeck.append("Spells to add:").append(spellCnt).append("\n");
    addCmcAdjusted(spells, spellCnt, cmcLevels);

    tmpDeck.append(String.format("Current deck size: %d... should be %f%n", tDeck.countAll(),
            size * (getCreatPercentage() + getSpellPercentage())));
}

From source file:com.htmlhifive.pitalium.image.model.RectangleArea.java

/**
 * ?????????//from w  w  w .  j a v  a  2s . c  o m
 * 
 * @return ?????
 */
public RectangleArea ceil() {
    return new RectangleArea(Math.ceil(x), Math.ceil(y), Math.ceil(width), Math.ceil(height));
}

From source file:com.gwac.action.OtObserveRecordAction.java

@SuppressWarnings("unchecked")
public String execute() {

    int to = (rows * page);
    int from = to - rows;

    List<Integer> tlist = obDao.hisOrCurExist(otName);
    if (!tlist.isEmpty()) {
        Integer his = tlist.get(0);
        queryHis = his == 1;/*  w ww  .  jav  a  2  s. c o  m*/
        gridModel = otorDao.getRecordByOtName(otName, from, rows, queryHis);
        records = otorDao.countRecordByOtName(otName, queryHis);
    } else {
        gridModel = new ArrayList();
    }

    if (totalrows != null) {
        records = totalrows;
    }
    if (to > records) {
        to = records;
    }
    total = (int) Math.ceil((double) records / (double) rows);

    return SUCCESS;
}

From source file:dr.math.distributions.NegativeBinomialDistribution.java

public double quantile(double y) {
    // TB - I'm having trouble implementing this
    // LM - A first stab using simple minimisation to invert the function (under absolute loss)
    // Implementation based on the qnbinom.c function used in R
    final double stdev = Math.sqrt(mean + (mean * mean * alpha));
    final double r = -1 * (mean * mean) / (mean - stdev * stdev);
    final double p = mean / (stdev * stdev);
    final double prob = y;

    final double Q = 1.0 / p;
    final double P = (1.0 - p) * Q;
    final double gamma = (Q + P) / stdev;
    final double z = Math.sqrt(2.0) * ErrorFunction.inverseErf(2.0 * y - 1.0);
    final double crudeY = mean + stdev * (z + gamma * (z * z - 1) / 6);

    UnivariateFunction f = new UnivariateFunction() {
        double tent = Double.NaN;

        public double evaluate(final double argument) {
            try {
                tent = Beta.regularizedBeta(p, r, argument + 1);
            } catch (MathException e) {
                return Double.NaN;
            }/*from  www.  j  a  v  a  2s .  com*/
            double score = Math.abs(tent - prob);
            return score;
        }

        public int getNumArguments() {
            return 1;
        }

        public double getLowerBound() { // 20% window should cut it. Probably too large even...
            return Math.min(crudeY - .2 * crudeY, 0);
        }

        public double getUpperBound() {
            return crudeY + .2 * crudeY;
        }
    };
    UnivariateMinimum minimum = new UnivariateMinimum();
    double q = minimum.findMinimum(f);
    return Math.ceil(q);
}

From source file:io.hops.erasure_coding.BaseEncodingManager.java

static long numBlocks(FileStatus stat) {
    return (long) Math.ceil(stat.getLen() * 1.0 / stat.getBlockSize());
}

From source file:com.comphenix.xp.SampleRange.java

public int sampleInt(Random rnd) {

    /*/*w  w w. j  ava2 s .com*/
     * Imagine our range is 0.7 - 5.3:
     *
     * 0.7  1          2          3          4          5  5.3
      *   
     *  |---|----------|----------|----------|----------|---|
     *  |   |          |          |          |          |   |
     *  |   |          |          |          |          |   |
     *  |---|----------|----------|----------|----------|---|
     *
     * The integer part, 1 - 5, is easy. To get a random number between and
     * including 1 and 5, we simply get a random number between 0 and 4 
     * and add one.
      * 
     * The beginning, 0.7 - 1.0, covers 30% of an integer. One interpretation is
     * that this indicates the probability of getting that integer. 
     *
     * So, we end up with a 30% probability of getting 0 and 5.3 - 5 = 30% 
     * probability of getting 4.
     */

    int value = 0;

    // Convert the range to an integer equivalent. 
    // Notice that we round to shrink the range.
    int a = (int) Math.ceil(start);
    int b = (int) Math.floor(end);

    // Special case
    if ((int) start == (int) end) {
        return sampleIntReduced(rnd);
    }

    // The decimal leftover
    double dA = a - start;
    double dB = end - b;

    // Sample an integer from the range [a, b] (inclusive)
    if (b > a) {
        value = a + rnd.nextInt(b - a + 1); // Add one since nextInt is exclusive
    }

    // The remainder is the probability of choosing the previous value
    if (dA > 0 && rnd.nextDouble() < dA)
        value--;

    // And here it is the probability of choosing the next value
    if (dB > 0 && rnd.nextDouble() < dB)
        value++;

    return value;
}

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

protected static double quantileType7InR(double[] x, double q) {

    final double[] tempX = x.clone();
    Arrays.sort(tempX);//from  ww w  .  j  a v a2 s  .co m
    final int n = tempX.length;
    final double index = 1 + (n - 1) * q;
    final double lo = Math.floor(index);
    final double hi = Math.ceil(index);
    Arrays.sort(tempX);
    double qs = tempX[(int) lo - 1];
    final double h = index - lo;
    if (h != 0) {
        qs = (1 - h) * qs + h * tempX[(int) hi - 1];
    }
    return qs;

}

From source file:CRM.web.InteractionsController.java

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

    if (pageid != 1) {
        start = (pageid - 1) * total + 1;
    }//from  www .j a  v a2 s . co  m

    List<interactions> list = dao.getInteractionsByPage(start, total);
    logger.info(dao.getInteractionsByPage(start, total).toString());

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

    int count = dao.getInteractionsCount();
    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("viewinteractions", context);
}