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:edu.ucsb.eucalyptus.cloud.ws.WalrusAvailabilityEventListener.java

@Override
public void fireEvent(final ClockTick event) {
    if (Bootstrap.isFinished() && Hosts.isCoordinator()) {
        try {//from   www .  j  av a  2s  . c  o m

            WalrusInfo wInfo = WalrusInfo.getWalrusInfo();
            long capacity = 0;
            if (wInfo != null)
                capacity = wInfo.getStorageMaxTotalCapacity();

            ListenerRegistry.getInstance()
                    .fireEvent(new ResourceAvailabilityEvent(StorageWalrus,
                            new Availability(capacity, Math.max(0, capacity - (long) Math
                                    .ceil((double) WalrusUtil.countTotalObjectSize() / FileUtils.ONE_GB)))));
        } catch (Exception ex) {
            logger.error(ex, ex);
        }
    }
}

From source file:edu.umn.cs.spatialHadoop.indexing.GridPartitioner.java

@Override
public void createFromPoints(Rectangle mbr, Point[] points, int capacity) throws IllegalArgumentException {
    if (points.length == 0)
        throw new IllegalArgumentException("Amount of points must be > 0");

    x = mbr.x1;//  w  w  w  . j a  va  2  s  .c  o  m
    y = mbr.y1;

    // Start with a rough estimate for number of cells assuming uniformity
    numTiles = (int) Math.ceil(points.length / capacity);
    GridInfo gridInfo = new GridInfo(mbr.x1, mbr.y1, mbr.x2, mbr.y2);

    int maxCellSize;
    int maxIterations = 1000;

    do {
        int cols = (int) Math.round(Math.sqrt(numTiles));

        this.numColumns = gridInfo.columns = Math.max(1, cols);
        this.numRows = gridInfo.rows = (int) Math.ceil(numTiles / gridInfo.columns);

        maxCellSize = 0;
        // TODO uncomment the following part to further breakdown big tiles
        //      int[] histogram = new int[gridInfo.columns * gridInfo.rows];
        //      for (Point point : points) {
        //        int cell = gridInfo.getOverlappingCell(point.x, point.y);
        //        if (++histogram[cell] > maxCellSize)
        //          maxCellSize = histogram[cell];
        //      }
        //      if (maxCellSize > capacity) {
        //        // Further break the largest grid cell
        //        numTiles = (int) (numTiles * Math.ceil((double)maxCellSize / capacity));
        //      }
    } while (maxCellSize > capacity && maxIterations-- > 0);
    LOG.info("Partitioning the space into a " + gridInfo.columns + "x" + gridInfo.rows + " grid");
    tileWidth = mbr.getWidth() / gridInfo.columns;
    tileHeight = mbr.getHeight() / gridInfo.rows;
}

From source file:nl.knaw.huygens.alexandria.endpoint.search.SearchResult.java

public int getTotalPages() {
    return (int) Math.ceil(getTotalResults() / (double) query.getPageSize());
}

From source file:statistic.ca.gui.DiagramContainer.java

public void remove(String diagramName) {
    if (contains(diagramName)) {
        JPanel p = getTupel(diagramName);
        if (p != null) {
            diagramList.remove(p);/*from  www  .  j  av a 2s  .  c o  m*/
            diagramMapping.clear();
            for (DiagramTupel dt : diagramList) {
                diagramMapping.put(dt.getTitle(), diagramList.indexOf(dt));
            }

            super.removeAll();

            setLayout(new GridLayout((int) (Math.ceil((double) diagramList.size() / 2)), 2));

            for (DiagramTupel dt : diagramList) {
                add(dt.getDiagram());
                (dt.getDiagram()).addMouseListener(parent.new diagramClick());
            }

            repaint();
            validate();
        }
    }
}

From source file:com.inmobi.conduit.distcp.tools.mapred.TestUniformSizeInputFormat.java

private static int createFile(String path, int fileSize) throws Exception {
    FileSystem fileSystem = null;
    DataOutputStream outputStream = null;
    try {/*  w  w  w.  java  2s.co  m*/
        fileSystem = cluster.getFileSystem();
        outputStream = fileSystem.create(new Path(path), true, 0);
        int size = (int) Math.ceil(fileSize + (1 - random.nextFloat()) * fileSize);
        outputStream.write(new byte[size]);
        return size;
    } finally {
        IOUtils.cleanup(null, fileSystem, outputStream);
    }
}

From source file:edu.asu.ca.kaushik.algorithms.randomized.lll.TwoStageSimpleMT.java

private int twoStageSimpleBound(int t, int k, int v) {
    double kChooset = CombinatoricsUtils.binomialCoefficientDouble(k, t);
    double vpowt = Math.pow(v, t);
    double denom = Math.log(vpowt / (vpowt - 1));
    double nume = Math.log(kChooset * vpowt * denom);
    return (int) Math.ceil(nume / denom);
}

From source file:ca.uqac.info.buffertannen.message.BitSequence.java

/**
 * Reads an array of bytes. Since//from  w  ww .  j a va  2 s  .  c om
 * the array of bytes may represent a sequence of bits that is
 * not a multiple of 8, the length of the bit sequence is also
 * provided.
 * @param array The array of bytes
 * @param length The length (in <em>bits</em> of the bit sequence
 *   contained in the array of bytes
 * @throws BitFormatException
 */
protected void readFromBytes(byte[] array, int length) throws BitFormatException {
    int num_bytes = (int) Math.ceil(((float) length) / 8f);
    int cur_length = 0;
    if (num_bytes > array.length) {
        // Error: length is longer than the length of the array
        throw new BitFormatException();
    }
    for (int i = 0; i < num_bytes && cur_length < length; i++) {
        byte b = array[i];
        for (int j = 7; j >= 0 && cur_length < length; j--) {
            int val = (b >> j) & 1;
            if (val == 1) {
                this.add(true);
            } else {
                this.add(false);
            }
            cur_length++;
        }
    }
}

From source file:gov.nih.nci.cabio.portal.portlet.Results.java

/**
 * Returns the total number of pages./*www  .  ja  v  a 2  s . co  m*/
 */
public int getNumPages() {
    return (int) Math.ceil((float) resultList.size() / (float) PAGE_SIZE);
}

From source file:de.unisb.cs.st.javalanche.mutation.run.task.MutationTaskCreator.java

public static void createMutationTasks() throws IOException {
    deleteTasks();//from  www  .j a  v a2  s  .c  om
    int numberOfTasks = DEFAULT_NUMBER_OF_TASKS;
    int mutationsPerTask = DEFAULT_MUTATIONS_PER_TASK;
    String mutationsPerTaskProperty = System.getProperty(MUTATION_PER_TASK_KEY);
    if (mutationsPerTaskProperty != null) {
        mutationsPerTask = Integer.parseInt(mutationsPerTaskProperty);
    }
    String mutationTargetTasks = System.getProperty(MUTATION_FIXED_NUMBER_OF_TASKS_KEY);

    if (mutationTargetTasks != null) {
        numberOfTasks = Integer.parseInt(mutationTargetTasks);
        Set<Long> coveredMutations = MutationCoverageFile.getCoveredMutations();

        List<Long> mutationIds = QueryManager.getMutationsWithoutResult(coveredMutations, 0);
        int size = mutationIds.size();
        mutationsPerTask = (int) Math.ceil(size * 1. / numberOfTasks);
    }
    createMutationTasks(numberOfTasks, mutationsPerTask);
}

From source file:com.choicemaker.cm.modelmaker.gui.panels.StatisticsHistogramPanel.java

private int getNumBins() {
    return (int) Math.ceil(100 / binWidth);
}