Example usage for java.lang Double intValue

List of usage examples for java.lang Double intValue

Introduction

In this page you can find the example usage for java.lang Double intValue.

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Double as an int after a narrowing primitive conversion.

Usage

From source file:it.cnr.isti.smartfed.test.DatacenterFacilities.java

public static List<FederationDatacenter> getNormalDistribution(int numOfDatacenters, int numHost) {
    Random r = new Random(13213);

    int core_variance = maxNumOfCores - minNumOfCores;
    int delta_cores = core_variance > 0 ? r.nextInt(core_variance) : 0;

    List<FederationDatacenter> list = new ArrayList<FederationDatacenter>();
    NormalDistribution nd = new NormalDistribution(numOfDatacenters / 2d, numOfDatacenters / 4d);

    // System.out.println("Aa"+numHost);

    for (int i = 0; i < numOfDatacenters; i++) {
        // create the virtual processor (PE)
        List<Pe> peList = new ArrayList<Pe>();
        int mips = 25000;
        for (int j = 0; j < minNumOfCores + delta_cores; j++) {
            peList.add(new Pe(j, new PeProvisionerSimple(mips)));
        }// ww w.  ja  v a2 s  .  c o  m

        // create the hosts
        List<Host> hostList = new ArrayList<Host>();
        HostProfile prof = HostProfile.getDefault();
        prof.set(HostParams.RAM_AMOUNT_MB, 16 * 1024 + "");

        int num;
        if (numOfDatacenters == 1) {
            num = numHost;
        } else {
            Double value = new Double(nd.density(i)) * numHost;
            num = value.intValue();
        }

        if (num < 1)
            num = 1;

        for (int k = 0; k < num; k++) {
            hostList.add(HostFactory.get(prof, peList));
        }

        // create the storage
        List<Storage> storageList = new ArrayList<Storage>(); // if empty, no SAN attached

        // create the datacenters
        list.add(FederationDatacenterFactory.getDefault(hostList, storageList));
    }

    return list;
}

From source file:Main.java

public static int getProgressPercentage(long currentDuration, long totalDuration) {
    Double percentage = 0.0;

    long currentSeconds = (int) (currentDuration / 1000);
    long totalSeconds = (int) (totalDuration / 1000);

    percentage = (((double) currentSeconds) / totalSeconds) * 100;

    return percentage.intValue();
}

From source file:Main.java

public static int calculateParScore(Double r1, Double r2, int g, int s) {

    Double score = 0.0;
    //System.out.println("r1 is " + r1 + " , r2 is " + r2);

    if (r1 >= r2) {

        score = s * r2 / r1;/*from  www  .  j  a  v  a2s  .co m*/
    } else {

        score = s + ((r2 - r1) * g / 100);
    }

    return score.intValue();
}

From source file:org.sonar.batch.qualitygate.ConditionUtils.java

private static Comparable<Integer> parseInteger(ResolvedCondition condition, Measure measure) {
    Double value = getValue(condition, measure);
    return value != null ? value.intValue() : null;
}

From source file:Data.Utilities.java

public static Integer timeDiff(GPSRec rec1, GPSRec rec2) {

    Double t1 = (double) rec1.getTimestamp().getTime();
    Double t2 = (double) rec2.getTimestamp().getTime();

    Double timeDiff = Math.abs(t2 - t1);
    //        Double timeDiff = Math.abs(Double.longBitsToDouble(
    //                 - rec2.getTimestamp().getTime()));
    return (timeDiff.intValue());
}

From source file:Main.java

public static int getProgressPercentage(long currentDuration, long totalDuration) {
    Double percentage;
    long currentSeconds = (int) (currentDuration / 1000);
    long totalSeconds = (int) (totalDuration / 1000);
    // calculating percentage
    percentage = (((double) currentSeconds) / totalSeconds) * 100;
    // return percentage
    return percentage.intValue();
}

From source file:org.nuxeo.ecm.platform.pictures.tiles.magick.tiler.MagickTiler.java

static int[] computeCropCoords(ImageInfo input, int maxTiles, int tileWidth, int tileHeight, int xCenter,
        int yCenter) {
    int startX = 0;
    int startY = 0;
    int cropWidth = 0;
    int cropHeight = 0;
    int ntx = 0;//from   ww  w  . ja  va 2s .  com
    int nty = 0;

    if (input.getWidth() > input.getHeight()) {
        cropWidth = input.getWidth() / maxTiles;
        if ((input.getWidth() % maxTiles) > 0) {
            cropWidth += 1;
        }
        Double exactCropHeight = (new Double(tileHeight)) / tileWidth * cropWidth;
        if (exactCropHeight - exactCropHeight.intValue() > 0) {
            cropHeight = exactCropHeight.intValue() + 1;
        } else {
            cropHeight = exactCropHeight.intValue();
        }
        ntx = maxTiles;
        nty = input.getHeight() / cropHeight;
        if ((input.getHeight() % cropHeight) > 0) {
            nty += 1;
        }
    } else {
        cropHeight = input.getHeight() / maxTiles;
        if ((input.getHeight() % maxTiles) > 0) {
            cropHeight += 1;
        }
        Double exactCropWidth = (new Double(tileWidth)) / tileHeight * cropHeight;
        if (exactCropWidth - exactCropWidth.intValue() > 0) {
            cropWidth = exactCropWidth.intValue() + 1;
        } else {
            cropWidth = exactCropWidth.intValue();
        }
        nty = maxTiles;
        ntx = input.getWidth() / cropWidth;
        if ((input.getWidth() % cropWidth) > 0) {
            ntx += 1;
        }
    }

    startX = xCenter * cropWidth;
    startY = yCenter * cropHeight;

    double widthRatio = new Double(tileWidth) / cropWidth;
    double heightRatio = new Double(tileHeight) / cropHeight;

    if (xCenter == ntx - 1) {
        cropWidth = input.getWidth() - (xCenter) * cropWidth;
        tileWidth = (int) Math.round(cropWidth * widthRatio);
    }
    if (yCenter == nty - 1) {
        cropHeight = input.getHeight() - (yCenter) * cropHeight;
        tileHeight = (int) Math.round(cropHeight * heightRatio);
    }

    int[] result = { startX, startY, cropWidth, cropHeight, ntx, nty, tileWidth, tileHeight };

    return result;
}

From source file:com.aw.core.format.NumeroEnTextoFormatter.java

/**
*Devuelve en letras un monto determinado.
*@param valor: Objeto Double que ser mostrada en letras.
*@return String: Monto en Letras./*from  w ww.j a v a 2s .  c o m*/
*/
private static String valorEnLetras(Double valor) {

    String centavos = "00";
    double doubleValor = valor;
    int numero = valor.intValue();
    int posPunto = String.valueOf(valor).indexOf(".");
    int posComa = String.valueOf(valor).indexOf(",");
    double doubleNumero = Double.parseDouble(String.valueOf(numero));
    if (posPunto > 0 || posComa > 0) {
        if (posPunto > 0)
            centavos = String.valueOf(valor).substring(posPunto + 1);
        if (posComa > 0)
            centavos = String.valueOf(valor).substring(posComa + 1);
    } else
        centavos = "00";

    String cadena = "";
    int millon;
    int cienMil;

    if (numero < 1000000000) {

        if (numero > 999999) {
            millon = (new Double(numero / 1000000)).intValue();
            numero = numero - millon * 1000000;
            cadena += base(millon, true) + (millon > 1 ? " MILLONES " : " MILLON ");
        }
        if (numero > 999) {
            cienMil = (new Double(numero / 1000)).intValue();
            numero = numero - cienMil * 1000;
            cadena += base(cienMil, false) + " MIL ";
        }

        cadena += base(numero, true);

        if (cadena != null && cadena.trim().length() > 0) {
            cadena += " CON ";
        }

        if (centavos.trim().length() == 1)
            centavos += "0";
        cadena += String.valueOf(centavos) + "/100";

    }

    return cadena.trim();
    //return  cadena.trim()+" Nuevos Soles";
}

From source file:com.asprise.imaging.core.scan.twain.TwainUtil.java

/**
 * Extract the value represented by the given object (Number or String).
 * @param object the object to extract value from
 * @param defaultValue default value to be returned if object is null or {@linkplain NumberFormatException}.
 * @return the value extracted or default value if failed to extract the value.
 *///ww  w . j a  v  a2  s  . co m
public static int toInteger(Object object, int defaultValue) {
    if (object == null) {
        return defaultValue;
    }
    if (object instanceof Number) {
        return ((Number) object).intValue();
    }

    try {
        Double value = Double.valueOf(object.toString().trim());
        return value.intValue();
    } catch (NumberFormatException e) {
        return defaultValue;
    }
}

From source file:Main.java

/**
 * Convert a time in ms in a percentage of the total duration time
 *
 * @param currentDuration, long - time passed from the start of playing (ms)
 * @param totalDuration,   long - total duration of the reproduction (ms)
 * @return int, percentage of the file played
 *///from w w  w.  j  a  v  a  2  s  . co m
public static int getProgressPercentage(long currentDuration, long totalDuration) {
    Double percentage = (double) 0;

    long currentSeconds = (int) (currentDuration / 1000);
    long totalSeconds = (int) (totalDuration / 1000);

    // calculating percentage
    percentage = (((double) currentSeconds) / totalSeconds) * 100;

    // return percentage
    return percentage.intValue();
}