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:org.openmrs.module.kenyaemr.KenyaEmrUiUtils.java

/**
 * Formats a regimen in long format/*from  w  ww.  j  a  v a  2  s .  c o m*/
 * @param regimen the regimen
 * @param ui the UI utils
 * @return the string value
 */
public String formatRegimenLong(RegimenOrder regimen, UiUtils ui) {
    if (CollectionUtils.isEmpty(regimen.getDrugOrders())) {
        return "Empty";
    }
    List<String> components = new ArrayList<String>();
    for (DrugOrder o : regimen.getDrugOrders()) {
        StringBuilder sb = new StringBuilder();

        ConceptName cn = o.getConcept().getShortNameInLocale(Metadata.LOCALE);
        if (cn == null) {
            cn = o.getConcept().getName(Metadata.LOCALE);
        }
        sb.append(cn.getName());

        if (o.getDrug() != null) {
            sb.append(" " + o.getDrug().getDoseStrength() + o.getDrug().getUnits());
        }

        if (o.getDose() != null) {
            // If dose is a whole number, don't format with decimals... e.g. 3.0tabs looks weird
            boolean hasDecimals = Math.floor(o.getDose()) != o.getDose();
            String dose = hasDecimals ? ui.format(o.getDose()) : ui.format(o.getDose().intValue());

            sb.append(" " + dose + o.getUnits());
        }
        if (o.getFrequency() != null) {
            sb.append(" " + o.getFrequency());
        }
        components.add(sb.toString());
    }
    return OpenmrsUtil.join(components, " + ");
}

From source file:org.ect.reo.simulation.simulator.Statistic.java

private int getBatchNrEvent(int event) {

    // return the batch number for this event number, it will return -1 if the batch number is not valid (less than 0 or greater than numOfBatches - 1)
    int result = (int) Math.floor((double) (event - sim.getWarmUpEvents()) / sim.getBatchLengthEvents());
    return ((result >= 0) && (result < numOfBatches)) ? result : -1;
}

From source file:grafix.graficos.indices.IndiceADX.java

public static double trunc(double d, int c) {
    int aux = (int) Math.pow(10, c);
    return Math.floor(d * aux) / (double) aux;
}

From source file:ch.newscron.encryption.Encryption.java

/**
 * Computes the max number of available characters, considering the initial URL, base64, AES, MD5 hash and JSON object.
 * !! Available characters do not include the follow special characters (which require > 1 bytes): "/", "\", """, "'" and any kind of accents!!
 * @param initialURL ("http://domain/path")
 * @return the max number of available characters for the four fields (customerID, reward1, reward2, validity)
 *//* w  ww.j a v  a2  s.  c om*/
public static Integer availableParameterLength(String initialURL) {
    try {
        JSONObject emptyData = new JSONObject();
        emptyData.put("custID", "");
        emptyData.put("rew1", "");
        emptyData.put("rew2", "");
        emptyData.put("val", "");
        emptyData.put("hash", "");

        //Max size of URL for Internet Explorer... :-(
        int maxURLSize = 2000;

        //Remove size of initial url (host+domain)
        maxURLSize -= initialURL.getBytes("UTF-8").length;

        //Base64 ratio of 3/4
        maxURLSize = (int) Math.ceil((maxURLSize * 3) / 4);

        //Maximum number of blocks available * 16
        maxURLSize = (int) Math.floor(maxURLSize / 16) * 16;

        //Remove size of hash (16 bytes) and empty JSON (without fields)
        maxURLSize -= (16 + emptyData.toJSONString().getBytes("UTF-8").length);

        //Remaining number of characters available
        return maxURLSize;

    } catch (Exception e) {
    }

    return null;
}

From source file:de.biomedical_imaging.ij.steger.Link.java

private void interpolate_gradient(float[] gradx, float[] grady, double px, double py, int width,
        MutableDouble gx, MutableDouble gy) {
    int gix, giy, gpos;
    double gfx, gfy, gx1, gy1, gx2, gy2, gx3, gy3, gx4, gy4;

    gix = (int) Math.floor(px);
    giy = (int) Math.floor(py);

    gfx = px % 1.0;//from ww w . j  av a2 s.  c  o  m
    ;
    gfy = py % 1.0;
    gpos = LinesUtil.LINCOOR(gix, giy, width);
    gx1 = gradx[gpos];
    gy1 = grady[gpos];
    gpos = LinesUtil.LINCOOR(gix + 1, giy, width);
    gx2 = gradx[gpos];
    gy2 = grady[gpos];
    gpos = LinesUtil.LINCOOR(gix, giy + 1, width);
    gx3 = gradx[gpos];
    gy3 = grady[gpos];
    gpos = LinesUtil.LINCOOR(gix + 1, giy + 1, width);
    gx4 = gradx[gpos];
    gy4 = grady[gpos];
    gx.setValue((1 - gfy) * ((1 - gfx) * gx1 + gfx * gx2) + gfy * ((1 - gfx) * gx3 + gfx * gx4));
    gy.setValue((1 - gfy) * ((1 - gfx) * gy1 + gfx * gy2) + gfy * ((1 - gfx) * gy3 + gfx * gy4));
}

From source file:net.sf.logsaw.core.internal.logresource.simple.SimpleLogResource.java

/**
 * Returns the units of work for parsing the given log file.
 * @return the units of work or <code>IProgressMonitor.UNKNOWN</code>
 *//*from w  ww  .j  a v a  2 s  .  c  om*/
protected int getUnitsOfWork() {
    // If file is less than 1kB, totalWork will be one
    return ((int) Math.floor((double) logFile.length() / FileUtils.ONE_KB)) + 1;
}

From source file:de.tud.kom.p2psim.impl.simengine.Simulator.java

private void shutdownSimulation(Exception reason, long startTime) {
    this.running = false;
    if (finishedWithoutError) {
        log.info("Simulation successfully finished.");
    } else {/*from  www.  j  av a  2s.c o  m*/
        log.error("Simulation finished with the error = " + reason);
    }
    long runTime = System.currentTimeMillis() - startTime;
    long minutes = (long) Math.floor((runTime) / 60000);
    long secs = (runTime % 60000) / 1000;
    log.info("Realtime Duration of experiment (m:s) " + minutes + ":" + secs);
    log.info("Simulated time is " + getSimulatedRealtime());
    if (AttributeWriter.hasInstance()) {
        AttributeWriter.getInstance().closeWriter();
    }
    if (MetricsWriter.hasInstance()) {
        MetricsWriter.getInstance().closeWriter();
    }
    if (SkyNetBatchSimulator.hasInstance()) {
        SkyNetBatchSimulator.getInstance().finish(finishedWithoutError);
    }
}

From source file:com.ibm.bi.dml.runtime.controlprogram.parfor.opt.CostEstimator.java

/**
 * /*www.ja  v a  2 s.co m*/
 * @param plan
 * @param n
 * @return
 */
public double computeLocalParBound(OptTree plan, OptNode n) {
    return Math.floor(rComputeLocalValueBound(plan.getRoot(), n, plan.getCK()));
}

From source file:org.bench4Q.console.ui.section.P_WIRTSection.java

private void wirtCDFPrepare() {

    if (thiswirt.size() <= 0) {
        return;//w  ww  . ja  va  2s . com
    }

    Double[] wirtOrderd = new Double[thiswirt.size()];
    thiswirt.toArray(wirtOrderd);
    Arrays.sort(wirtOrderd);

    double[][] temp = new double[2][wirtOrderd.length];
    int tempIndex = 1;
    int num = 1;
    Double current = wirtOrderd[0];
    temp[0][0] = 0;
    temp[1][0] = 0;
    for (int i = 1; i < wirtOrderd.length; i++) {
        // if ( (wirtOrderd[i]-current<0.00001) ||
        // (current-wirtOrderd[i]<0.00001) ) {
        if (Math.floor(wirtOrderd[i]) == Math.floor(current)) {
            num++;
        } else {
            temp[0][tempIndex] = current;
            temp[1][tempIndex] = num;

            current = wirtOrderd[i];
            num = 1;
            tempIndex++;
        }
    }
    temp[0][tempIndex] = current;
    temp[1][tempIndex] = num;
    tempIndex++;
    result = new double[2][tempIndex];

    result[0][0] = temp[0][0];
    result[1][0] = temp[1][0];

    for (int i = 1; i < tempIndex; i++) {
        result[0][i] = temp[0][i];
        result[1][i] = temp[1][i];
    }
    for (int i = 1; i < tempIndex; i++) {
        result[1][i] = result[1][i - 1] + result[1][i];
    }
    for (int i = 0; i < tempIndex; i++) {
        result[1][i] = result[1][i] * 100l / wirtOrderd.length;
    }
}

From source file:org.obiba.onyx.core.domain.participant.Participant.java

@Transient
public Long getAge() {
    if (birthDate == null)
        return 0l;
    Calendar todayCal = Calendar.getInstance();
    Calendar birthCal = Calendar.getInstance();

    birthCal.setTime(birthDate);/* w ww. ja v a2s .c o m*/
    Long age = todayCal.getTimeInMillis() - birthCal.getTimeInMillis();
    Double ageDouble = SI.MILLI(SI.SECOND).getConverterTo(NonSI.YEAR).convert(Double.valueOf(age.toString()));
    ageDouble = Math.floor(ageDouble);
    age = Math.round(ageDouble);

    return (age);
}