Example usage for java.lang Math floor

List of usage examples for java.lang Math floor

Introduction

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

Prototype

public static double floor(double a) 

Source Link

Document

Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:com.feilong.core.util.RandomUtil.java

/**
 * 0-<b>(maxValue)</b>?.// w ww. ja va2 s  .  com
 * 
 * <h3>:</h3>
 * <blockquote>
 * 
 * <pre class="code">
 * RandomUtil.createRandom(8)
 * ?8?
 * 
 * ?? 3
 * </pre>
 * 
 * </blockquote>
 * 
 * @param maxValue
 *            ?
 * @return  <code>maxValue</code> null, {@link NullPointerException}
 * @throws NullPointerException
 *              <code>maxValue</code> null
 */
public static long createRandom(Number maxValue) {
    Validate.notNull(maxValue, "maxValue can't be null!");
    //  0.0 ? 1.0 ? double 
    double random = JVM_RANDOM.nextDouble();
    return (long) Math.floor(random * maxValue.longValue());//double ???
}

From source file:edu.cuhk.hccl.hadoop.YelpMapper.java

@Override
public DataRecord parseDataRecord(Text value) {
    Review review = gson.fromJson(value.toString(), Review.class);

    if (review.getText().isEmpty() || itemSet.contains(review.getBusinessId())) {

        DataRecord record = new DataRecord();

        record.setUserID(review.getUserID());
        record.setItemID(review.getBusinessID());
        record.setReview(review.getText());
        record.setRating((int) Math.floor(Double.parseDouble(review.getStars())));

        return record;

    } else {//from  w w w  . ja  v a  2s  .  co  m
        return null;
    }
}

From source file:me.math.kdtree.KDTree.java

/**
 * /*from w w  w . ja  va  2s . c  om*/
 * @param aList
 * @param direction
 * @param parent
 * @param depth
 * @return
 */
private INode insertNode(List<AbstractSpatialGridPoint> aList, INode.Direction direction, INode parent,
        int depth, INodeCreator creator) {

    if (aList.isEmpty()) {
        return null;
    }

    int midpoint = (int) Math.floor((aList.size() / 2) + 0.5f);

    AbstractSpatialGridPoint pt = aList.get(midpoint);
    INode node = creator.create(pt, direction, parent, depth);

    INode.Direction change = direction;
    if (direction == INode.Direction.XLAT) {
        change = INode.Direction.YLON;
    } else {
        change = INode.Direction.XLAT;
    }

    List<AbstractSpatialGridPoint> leftList = new ArrayList<AbstractSpatialGridPoint>();

    for (int n = 0; n < midpoint; n++) {
        leftList.add(aList.get(n));
    }

    comparator_.setDirection(change);
    Collections.sort(leftList, comparator_);
    node.setLeft(insertNode(leftList, change, node, depth + 1, creator));
    if (node.getLeft() != null) {
        node.getMBR().extend(node.getLeft().getMBR());
    }

    List<AbstractSpatialGridPoint> rightList = new ArrayList<AbstractSpatialGridPoint>();

    for (int n = midpoint + 1; n < aList.size(); n++) {
        rightList.add(aList.get(n));
    }

    comparator_.setDirection(change);
    Collections.sort(rightList, comparator_);
    node.setRight(insertNode(rightList, change, node, depth + 1, creator));
    if (node.getRight() != null) {
        node.getMBR().extend(node.getRight().getMBR());
    }

    return node;
}

From source file:com.almende.eve.goldemo.Cell.java

/**
 * @param agentNo/*w w w.java  2s  . c  o  m*/
 * @param totalSize
 */
private void calcNeighbours(String odd, String even, int agentNo, int totalSize) {
    int N = (int) Math.floor(Math.sqrt(totalSize));
    int M = N;
    int cN = 0;
    int cM = 0;
    if (agentNo != 0) {
        cM = agentNo % M;
        cN = (int) Math.floor(agentNo / N);
    }
    neighbors = new ArrayList<String>(8);

    for (int id = 0; id < 8; id++) {
        int neighborNo = getNeighborNo(id, cN, cM, N, M);
        neighbors.add(addPath(odd, even, Goldemo.AGENTPREFIX + neighborNo, neighborNo));
    }
    getState().put("neighbors", neighbors);
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java

/**
 * Returns a point based on (x, y) but constrained to be within the bounds
 * of the given rectangle.  This method could be moved to JCommon.
 *
 * @param x  the x-coordinate./*from w  w  w .j av  a  2 s.  c  om*/
 * @param y  the y-coordinate.
 * @param area  the rectangle (<code>null</code> not permitted).
 *
 * @return A point within the rectangle.
 */
protected Point getPointInRectangle(int x, int y, Rectangle2D area) {
    x = (int) Math.max(Math.ceil(area.getMinX()), Math.min(x, Math.floor(area.getMaxX())));
    y = (int) Math.max(Math.ceil(area.getMinY()), Math.min(y, Math.floor(area.getMaxY())));
    return new Point(x, y);
}

From source file:me.azenet.UHPlugin.timers.UHTimer.java

/**
 * Sets the duration of the timer, in seconds.
 * /*from  w w  w  . j  a va  2s .  co  m*/
 * @param seconds The duration.
 */
public void setDuration(int seconds) {
    this.duration = seconds;

    this.hoursLeft = (int) Math.floor(this.duration / 3600);
    this.minutesLeft = (int) (Math.floor(this.duration / 60) - (this.hoursLeft * 60));
    this.secondsLeft = this.duration - (this.minutesLeft * 60 + this.hoursLeft * 3600);

    // Lower than 100 because else the counter text is longer than 16 characters.
    this.displayHoursInTimer = (this.hoursLeft != 0 && this.hoursLeft < 100);
}

From source file:nl.enovation.addressbook.cqrs.webui.init.MongoController.java

@RequestMapping(value = "/collection/{id}", method = RequestMethod.GET)
public String collection(@PathVariable("id") String collectionName,
        @RequestParam(value = "page", defaultValue = "1") int pageNumber,
        @RequestParam(value = "itemsperpage", defaultValue = "5") int itemsPerPage, Model model) {
    DBCursor dbCursor = springTemplate.getCollection(collectionName).find();
    List<DBObject> dbObjects = dbCursor.skip((pageNumber - 1) * itemsPerPage).limit(itemsPerPage).toArray();

    List<Map> items = new ArrayList<Map>(dbCursor.length());
    for (DBObject dbObject : dbObjects) {
        items.add(dbObject.toMap());/*from  w w w.j  a  v  a2  s .com*/
    }
    model.addAttribute("items", items);

    int totalItems = dbCursor.count();
    int numPages = ((int) Math.floor(totalItems / itemsPerPage)) + 1;
    model.addAttribute("numPages", numPages);
    model.addAttribute("page", pageNumber);
    model.addAttribute("itemsPerPage", itemsPerPage);
    model.addAttribute("collectionName", collectionName);
    return "data/collection";
}

From source file:co.mcme.animations.actions.MovePlayersAction.java

private boolean isInBounds(Location loc, CuboidRegion bounds) {
    boolean result;
    double x = Math.floor(loc.getX());
    double y = Math.floor(loc.getY());
    double z = Math.floor(loc.getZ());

    Vector min = bounds.getMinimumPoint();
    Vector max = bounds.getMaximumPoint();
    result = (x >= Math.floor(min.getX()) && x <= Math.floor(max.getX()) && y >= Math.floor(min.getY())
            && y <= Math.floor(max.getY()) && z >= Math.floor(min.getZ()) && z <= Math.floor(max.getZ()));

    //        MCMEAnimations.MCMEAnimationsInstance.getLogger().info("-------TESTING--------");
    //        MCMEAnimations.MCMEAnimationsInstance.getLogger().log(Level.INFO, "Loc - X: {0} Y:{1} Z: {2}", new Object[]{x, y, z});
    //        MCMEAnimations.MCMEAnimationsInstance.getLogger().log(Level.INFO, "Min - X: {0} Y:{1} Z: {2}", new Object[]{min.getX(), min.getY(), min.getZ()});
    //        MCMEAnimations.MCMEAnimationsInstance.getLogger().log(Level.INFO, "Max - X: {0} Y:{1} Z: {2}", new Object[]{max.getX(), max.getY(), max.getZ()});
    return result;
}

From source file:Util.java

public static double fix(double x) {
    int sign = sign(x);
    double y = 0;
    if (sign == -1) {
        y = Math.ceil(x);/*from w w  w.  ja va  2  s .c o  m*/
    } else if (sign == 1) {
        y = Math.floor(x);
    }
    return y;
}

From source file:com.mgmtp.perfload.loadprofiles.util.PlotFileCreator.java

/**
 * Create a time-rate-histogram of events of the given operation. The histograms are usually
 * used for diagnostic purposes./*w w  w  . java 2  s  .c o  m*/
 * 
 * @param file
 *            The plot file
 * @param eventList
 *            List of events from which the histogram is derived after applying a filter on the
 *            operation
 * @param operationName
 *            Name of the operation, used as filter to use only events in the histogram, which
 *            have this operation assigned.
 * @param nBin
 *            Number of bins of the resulting histogram.
 * @param xLow
 *            time value of the left boundary of the lowest bin of the resulting histogram
 * @param xUp
 *            time value of the right boundary of the highest bin of the resulting histogram
 * @param timeUnitPlot
 *            The time unit of the resulting plot
 */
public static void createOperationHistogram(final File file, final Collection<LoadEvent> eventList,
        final String operationName, final int nBin, final double xLow, final double xUp,
        final String timeUnitPlot) throws IOException {
    double timeScalingFactor = LoadCurveCalculator.getTimeScalingFactor(LoadCurveCalculator.timeUnit_hour,
            timeUnitPlot);

    double[] xhistoLow = new double[nBin];
    double[] xhistoUp = new double[nBin];
    int[] yhisto = new int[nBin];

    double delta = nBin / (xUp - xLow);
    for (int iBin = 0; iBin < nBin; iBin++) {
        xhistoLow[iBin] = iBin / delta + xLow;
        xhistoUp[iBin] = (iBin + 1) / delta + xLow;
    }
    for (LoadEvent event : eventList) {
        if (event.getOperation().getName().equals(operationName)) {
            double time = timeScalingFactor * event.getTime();
            int xBin = (int) Math.floor((time - xLow) * delta);
            if (xBin >= 0 && xBin < nBin) {
                yhisto[xBin]++;
            } else {
                log.warn("Value " + time + " outside range [" + xLow + ", " + xUp + ")");
            }
        }
    }

    // create plot data
    double[] x = new double[nBin * 2];
    double[] y = new double[nBin * 2];

    int plotBin = 0;
    for (int iBin = 0; iBin < nBin; iBin++) {
        x[plotBin] = xhistoLow[iBin];
        y[plotBin] = yhisto[iBin] / (xhistoUp[iBin] - xhistoLow[iBin]);
        plotBin++;
        x[plotBin] = xhistoUp[iBin];
        y[plotBin] = yhisto[iBin] / (xhistoUp[iBin] - xhistoLow[iBin]);
        plotBin++;
    }
    createPlot(file, x, y, "time " + timeUnitPlot, "Histogram " + operationName);
}