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:es.udc.gii.common.eaf.benchmark.multiobjective.wfg.Wfg_Objective.java

protected double s_multi(double y, int A, double B, double C) {
    double tmp1 = Math.abs(y - C) / (2.0 * (Math.floor(C - y) + C));
    double tmp2 = (4.0 * A + 2.0) * Math.PI * (0.5 - tmp1);

    return correct_to_01((1.0 + Math.cos(tmp2) + 4.0 * B * Math.pow(tmp1, 2.0)) / (B + 2.0), EPSILON);
}

From source file:com.itemanalysis.jmetrik.file.JmetrikFileImporter.java

/**
 * 1. Gets the file header or creates one.
 * 2. Sets the number of columns/*from w  w w. ja  v  a2  s  .  c o  m*/
 * 3. Checks the type of data stored in each variable using the first rowsToScan rows.
 *    Variables are integers by default. This method will change the data type to either
 *    double or string.
 *
 */
private void setDataTypes() {
    CSVParser parser = null;
    Reader reader = null;

    try {
        reader = new InputStreamReader(new BOMInputStream(new FileInputStream(dataFile)), "UTF-8");

        //Get column names from variable attributes
        colNames = new String[variableAttributeMap.size()];
        int index = 0;
        Iterator<VariableName> iter = variableAttributeMap.keySet().iterator();
        VariableName tempName = null;
        while (iter.hasNext()) {
            colNames[index++] = iter.next().toString();
        }

        //Create a parser with variable names from the variable attributes
        if (hasHeader) {
            parser = new CSVParser(reader,
                    dataFileFormat.withHeader(colNames).withSkipHeaderRecord(true).withCommentMarker('#'));
        } else {
            parser = new CSVParser(reader, dataFileFormat.withHeader(colNames).withCommentMarker('#'));
        }

        //Check data types in each column.
        String value = "";
        Iterator<CSVRecord> csvIter = parser.iterator();
        CSVRecord csvRecord = null;
        double testValue = 0;
        nrow = 0;

        while (csvIter.hasNext()) {
            csvRecord = csvIter.next();

            iter = variableAttributeMap.keySet().iterator();
            while (iter.hasNext()) {
                tempName = iter.next();
                value = csvRecord.get(tempName.toString()).trim();

                //Check that string can be converted to double. If not, Change variable type.
                //Ignore missing data and other special codes
                try {
                    if (!"".equals(value) && !specialDataCodes.isMissing(value)) {
                        testValue = Double.parseDouble(value);
                        if (testValue != Math.floor(testValue)) {
                            //if any value is a double, the variable is a double
                            variableAttributeMap.get(tempName).setDataType(DataType.DOUBLE);
                        }
                    }
                } catch (NumberFormatException ex) {
                    //if any value is a String, the variable is a String
                    variableAttributeMap.get(tempName).setDataType(DataType.STRING);
                }
            }
            nrow++;
        }

    } catch (IOException ex) {
        theException = ex;
    } finally {
        try {
            if (parser != null)
                parser.close();
            if (reader != null)
                reader.close();
        } catch (IOException ex) {
            theException = ex;
            logger.fatal(ex);
        }
    }

}

From source file:au.org.ala.delta.intkey.directives.invocation.OutputDescribeDirectiveInvocation.java

private void updateProgess(int numTaxaProcessed, int totalNumTaxa) {
    int progressPercent = (int) Math.floor((((double) numTaxaProcessed) / totalNumTaxa) * 100);
    progress(UIUtils.getResourceString("OutputDescribeDirective.Progress.Generating", progressPercent));
}

From source file:org.operamasks.faces.render.graph.CurveAndShapeRenderer.java

private void drawSeriesCurve(Graphics2D g2, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataset, int series) {
    // do nothing if item is not visible
    if (!(getItemVisible(series, 0) && (getItemLineVisible(series, 0) || drawArea))) {
        return;/* ww  w  .  j  av  a2 s.  c om*/
    }

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    PlotOrientation orientation = plot.getOrientation();

    int itemCount = dataset.getColumnCount();
    double[][] points = new double[itemCount][2];
    int count = 0;

    // get data points
    for (int i = 0; i < itemCount; i++) {
        Number value = dataset.getValue(series, i);
        if (value != null) {
            points[count][0] = domainAxis.getCategoryMiddle(i, itemCount, dataArea, xAxisLocation);
            points[count][1] = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, yAxisLocation);
            count++;
        }
    }

    if (count < 2) {
        return;
    }

    // draw curve
    CubicSplineFunction2D f = new CubicSplineFunction2D(points, count);
    GeneralPath path = new GeneralPath();

    double startX = points[0][0];
    double startY = points[0][1];
    double endX = points[count - 1][0];
    double endY = points[count - 1][1];
    double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation);

    if (orientation == PlotOrientation.HORIZONTAL) {
        if (drawArea) {
            path.moveTo((float) yz, (float) startX);
            path.lineTo((float) startY, (float) startX);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) f.getValue(x), (float) x);
            }
            path.lineTo((float) endY, (float) endX);
            path.lineTo((float) yz, (float) endX);
            path.closePath();
        } else {
            path.moveTo((float) startY, (float) startX);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) f.getValue(x), (float) x);
            }
            path.lineTo((float) endY, (float) endX);
        }
    } else {
        if (drawArea) {
            path.moveTo((float) startX, (float) yz);
            path.lineTo((float) startX, (float) startY);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) x, (float) f.getValue(x));
            }
            path.lineTo((float) endX, (float) endY);
            path.lineTo((float) endX, (float) yz);
            path.closePath();
        } else {
            path.moveTo((float) startX, (float) startY);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) x, (float) f.getValue(x));
            }
            path.lineTo((float) endX, (float) endY);
        }
    }

    Paint paint = getSeriesPaint(series);
    Stroke stroke = getSeriesStroke(series);

    if (drawArea) {
        g2.setPaint(paint);
        g2.fill(path);

        // create paint for outline
        if (paint instanceof Color) {
            paint = ((Color) paint).darker();
        } else if (paint instanceof GradientPaint) {
            paint = ((GradientPaint) paint).getColor1().darker();
        }
    }

    if (getItemLineVisible(series, 0)) {
        g2.setPaint(paint);
        g2.setStroke(stroke);
        g2.draw(path);
    }
}

From source file:de.tor.tribes.types.Attack.java

public final void setArriveTime(Date arriveTime) {
    if (arriveTime == null) {
        return;//w  ww .ja  va  2 s  .  c  o  m
    }
    if (ServerSettings.getSingleton().isMillisArrival()) {
        this.arriveTime = arriveTime;
    } else {
        this.arriveTime = new Date((long) Math.floor((double) arriveTime.getTime() / 1000.0) * 1000L);
    }
}

From source file:eu.cloudwave.wp5.feedbackhandler.aggregations.strategies.RequestAggregationStrategyImpl.java

/**
 * Number of expected measurement value groups in the chosen time range based on the chosen aggregation interval
 * //from  w ww .  j av  a  2s  . com
 * Example: time range: 1 day, aggregation interval: hours --> expects you to have 24 value groups, if this is not the
 * case, we have to add groups with 0 values, otherwise the minimum and average value will be wrong
 * 
 * @return number of groups as int
 */
private double getExpectedNumberOfMeasurementValueGroups() {

    // no statement about expected number of measurement value groups because no time range is selected
    if (this.timeRangeFrom == null || this.timeRangeTo == null)
        return 0;

    double expectedCount = 0;

    switch (this.timestampAggregation) {
    case Calendar.SECOND:
        expectedCount = Math.floor((this.timeRangeTo - this.timeRangeFrom) / 1000);
        break;
    case Calendar.MINUTE:
        expectedCount = Math.floor((this.timeRangeTo - this.timeRangeFrom) / (1000 * 60));
        break;
    case Calendar.HOUR:
        expectedCount = Math.floor((this.timeRangeTo - this.timeRangeFrom) / (1000 * 60 * 60));
        break;
    case Calendar.DAY_OF_MONTH:
        expectedCount = Math.floor((this.timeRangeTo - this.timeRangeFrom) / (1000 * 60 * 60 * 24));
        break;
    case Calendar.MONTH:
        expectedCount = Math.floor((this.timeRangeTo - this.timeRangeFrom) / (1000 * 60 * 60 * 24 * 30));
        break;
    }

    return expectedCount;
}

From source file:com.alibaba.simpleimage.util.ImageUtils.java

public static final short clampRoundShort(double in) {
    return (in > Short.MAX_VALUE ? Short.MAX_VALUE
            : (in >= Short.MIN_VALUE ? (short) Math.floor(in + 0.5) : Short.MIN_VALUE));
}

From source file:fredboat.Config.java

public String getRandomGoogleKey() {
    return getGoogleKeys().get((int) Math.floor(Math.random() * getGoogleKeys().size()));
}

From source file:com.persistent.cloudninja.controller.TenantTaskListController.java

/**
 * Method added to generate simulated data for bytes sent and received
 * @return String : Random generated String
 */// w w w.jav  a 2 s.c  o m
@RequestMapping(value = "/showTrafficSimulationPage.htm")
public ModelAndView showTrafficsimulation(HttpServletRequest request, HttpServletResponse response,
        @CookieValue(value = "CLOUDNINJAAUTH", required = false) String cookie) {

    int START_INDEX = 2;
    int END_INDEX = 100;
    TrafficSimulationDTO trafficSimulationDTO = new TrafficSimulationDTO();

    if (cookie == null) {
        cookie = request.getAttribute("cookieNameAttr").toString();
    }

    String tenantId = AuthFilterUtils.getFieldValueFromCookieString(CloudNinjaConstants.COOKIE_TENANTID_PREFIX,
            cookie);
    response.addCookie(getTenantLogoCookieInResponse(tenantId, cookie));

    Random randomGen = new Random();
    int randomNum = randomGen.nextInt(END_INDEX - START_INDEX + 1) + START_INDEX;

    StringBuilder strbldr = new StringBuilder();
    for (int i = 0; i < randomNum; i++) {
        strbldr.append(Character.toChars((int) (Math.floor(26 * randomGen.nextDouble()) + 65)));
    }

    trafficSimulationDTO.setTenantId(tenantId);
    trafficSimulationDTO.setRandomString(strbldr.toString());
    return new ModelAndView("trafficSimulation", "trafficSimulationDTO", trafficSimulationDTO);

}

From source file:com.opengamma.analytics.financial.interestrate.future.provider.BondFutureHullWhiteMethod.java

/**
 * Computes the future price from the curves used to price the underlying bonds and a Hull-White one factor model.
 * @param future The future security./*from  w  w  w  . ja va 2  s.com*/
 * @param data The curve and Hull-White parameters.
 * @param nbPoint The number of point in the numerical cross estimation.
 * @return The future price.
 */
public double price(final BondFuture future, final HullWhiteIssuerProviderInterface data, final int nbPoint) {
    ArgumentChecker.notNull(future, "Future");
    ArgumentChecker.notNull(data, "Hull-White data bundle");
    final Pair<String, Currency> issuerCcy = future.getDeliveryBasket()[0].getIssuerCcy();
    ArgumentChecker.isTrue(data.getHullWhiteIssuerCurrency().equals(issuerCcy),
            "Incompatible data and futures");
    final int nbBond = future.getDeliveryBasket().length;
    final String issuerName = future.getDeliveryBasket()[0].getIssuer();
    final HullWhiteOneFactorPiecewiseConstantParameters parameters = data.getHullWhiteParameters();
    final IssuerProviderInterface issuer = data.getIssuerProvider();
    final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(
            issuer, future.getCurrency(), issuerName);
    final double expiry = future.getNoticeLastTime();
    final double delivery = future.getDeliveryLastTime();
    final double dfdelivery = data.getIssuerProvider().getDiscountFactor(issuerCcy, delivery);
    // Constructing non-homogeneous point series for the numerical estimations.
    final int nbPtWing = ((int) Math.floor(nbPoint / 20.)); // Number of point on each wing.
    final int nbPtCenter = nbPoint - 2 * nbPtWing;
    final double prob = 1.0 / (2.0 * nbPtCenter);
    final double xStart = NORMAL.getInverseCDF(prob);
    final double[] x = new double[nbPoint];
    for (int loopwing = 0; loopwing < nbPtWing; loopwing++) {
        x[loopwing] = xStart * (1.0 + (nbPtWing - loopwing) / 2.0);
        x[nbPoint - 1 - loopwing] = -xStart * (1.0 + (nbPtWing - loopwing) / 2.0);
    }
    for (int loopcent = 0; loopcent < nbPtCenter; loopcent++) {
        x[nbPtWing + loopcent] = xStart + loopcent * (-2.0 * xStart) / (nbPtCenter - 1);
    }
    // Figures for each bond
    final double[][] cfTime = new double[nbBond][];
    final double[][] df = new double[nbBond][];
    final double[][] alpha = new double[nbBond][];
    final double[][] beta = new double[nbBond][];
    final double[][] cfaAdjusted = new double[nbBond][];
    final double[] e = new double[nbBond];
    final double[][] pv = new double[nbPoint][nbBond];
    final AnnuityPaymentFixed[] cf = new AnnuityPaymentFixed[nbBond];
    for (int loopbnd = 0; loopbnd < nbBond; loopbnd++) {
        cf[loopbnd] = future.getDeliveryBasket()[loopbnd].accept(CFEC, multicurvesDecorated);
        final int nbCf = cf[loopbnd].getNumberOfPayments();
        cfTime[loopbnd] = new double[nbCf];
        df[loopbnd] = new double[nbCf];
        alpha[loopbnd] = new double[nbCf];
        beta[loopbnd] = new double[nbCf];
        cfaAdjusted[loopbnd] = new double[nbCf];
        for (int loopcf = 0; loopcf < nbCf; loopcf++) {
            cfTime[loopbnd][loopcf] = cf[loopbnd].getNthPayment(loopcf).getPaymentTime();
            df[loopbnd][loopcf] = issuer.getDiscountFactor(issuerCcy, cfTime[loopbnd][loopcf]);
            alpha[loopbnd][loopcf] = MODEL.alpha(parameters, 0.0, expiry, delivery, cfTime[loopbnd][loopcf]);
            beta[loopbnd][loopcf] = MODEL.futuresConvexityFactor(parameters, expiry, cfTime[loopbnd][loopcf],
                    delivery);
            cfaAdjusted[loopbnd][loopcf] = df[loopbnd][loopcf] / dfdelivery * beta[loopbnd][loopcf]
                    * cf[loopbnd].getNthPayment(loopcf).getAmount() / future.getConversionFactor()[loopbnd];
            for (int looppt = 0; looppt < nbPoint; looppt++) {
                pv[looppt][loopbnd] += cfaAdjusted[loopbnd][loopcf]
                        * Math.exp(-alpha[loopbnd][loopcf] * alpha[loopbnd][loopcf] / 2.0
                                - alpha[loopbnd][loopcf] * x[looppt]);
            }
        }
        e[loopbnd] = future.getDeliveryBasket()[loopbnd].getAccruedInterest()
                / future.getConversionFactor()[loopbnd];
        for (int looppt = 0; looppt < nbPoint; looppt++) {
            pv[looppt][loopbnd] -= e[loopbnd];
        }
    }
    // Minimum: create a list of index of the CTD in each interval and a first estimate of the crossing point (x[]).
    final double[] pvMin = new double[nbPoint];
    final int[] indMin = new int[nbPoint];
    for (int looppt = 0; looppt < nbPoint; looppt++) {
        pvMin[looppt] = Double.POSITIVE_INFINITY;
        for (int loopbnd = 0; loopbnd < nbBond; loopbnd++) {
            if (pv[looppt][loopbnd] < pvMin[looppt]) {
                pvMin[looppt] = pv[looppt][loopbnd];
                indMin[looppt] = loopbnd;
            }
        }
    }
    final ArrayList<Double> refx = new ArrayList<>();
    final ArrayList<Integer> ctd = new ArrayList<>();
    int lastInd = indMin[0];
    ctd.add(indMin[0]);
    for (int looppt = 1; looppt < nbPoint; looppt++) {
        if (indMin[looppt] != lastInd) {
            ctd.add(indMin[looppt]);
            lastInd = indMin[looppt];
            refx.add(x[looppt]);
        }
    }

    // Sum on each interval
    final int nbInt = ctd.size();
    final double[] kappa = new double[nbInt - 1];
    double price = 0.0;
    if (nbInt == 1) {
        for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(0)].length; loopcf++) {
            price += cfaAdjusted[ctd.get(0)][loopcf];
        }
        price -= e[ctd.get(0)];
    } else {
        // The intersections
        final BracketRoot bracketer = new BracketRoot();
        final double accuracy = 1.0E-8;
        final RidderSingleRootFinder rootFinder = new RidderSingleRootFinder(accuracy);
        for (int loopint = 1; loopint < nbInt; loopint++) {
            final BondDifference cross = new BondDifference(cfaAdjusted[ctd.get(loopint - 1)],
                    alpha[ctd.get(loopint - 1)], e[ctd.get(loopint - 1)], cfaAdjusted[ctd.get(loopint)],
                    alpha[ctd.get(loopint)], e[ctd.get(loopint)]);
            final double[] range = bracketer.getBracketedPoints(cross, refx.get(loopint - 1) - 0.01,
                    refx.get(loopint - 1) + 0.01);
            kappa[loopint - 1] = rootFinder.getRoot(cross, range[0], range[1]);
        }
        // From -infinity to first cross.
        for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(0)].length; loopcf++) {
            price += cfaAdjusted[ctd.get(0)][loopcf] * NORMAL.getCDF(kappa[0] + alpha[ctd.get(0)][loopcf]);
        }
        price -= e[ctd.get(0)] * NORMAL.getCDF(kappa[0]);
        // Between cross
        for (int loopint = 1; loopint < nbInt - 1; loopint++) {
            for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(loopint)].length; loopcf++) {
                price += cfaAdjusted[ctd.get(loopint)][loopcf]
                        * (NORMAL.getCDF(kappa[loopint] + alpha[ctd.get(loopint)][loopcf])
                                - NORMAL.getCDF(kappa[loopint - 1] + alpha[ctd.get(loopint)][loopcf]));
            }
            price -= e[ctd.get(loopint)] * (NORMAL.getCDF(kappa[loopint]) - NORMAL.getCDF(kappa[loopint - 1]));
        }
        // From last cross to +infinity
        for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(nbInt - 1)].length; loopcf++) {
            price += cfaAdjusted[ctd.get(nbInt - 1)][loopcf]
                    * (1.0 - NORMAL.getCDF(kappa[nbInt - 2] + alpha[ctd.get(nbInt - 1)][loopcf]));
        }
        price -= e[ctd.get(nbInt - 1)] * (1 - NORMAL.getCDF(kappa[nbInt - 2]));
    }

    return price;
}