Example usage for java.lang Double longValue

List of usage examples for java.lang Double longValue

Introduction

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

Prototype

public long longValue() 

Source Link

Document

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

Usage

From source file:nz.co.senanque.oneinvoice.OneInvoiceTest.java

@Test
public void test1() throws Exception {
    ValidationSession validationSession = m_validationEngine.createSession();

    Customer customer = m_customerDAO.createCustomer();
    validationSession.bind(customer);//from   w  ww  .j a v a  2 s  .  co m
    Invoice invoice = new Invoice();
    invoice.setDescription("test invoice");
    customer.setOneInvoice(invoice);
    customer.setAmount(130);

    Double d = invoice.getAmount();

    // proves r1 fired okay
    assertEquals(130L, d.longValue());

    d = customer.getAmountOne();

    // proves r2 fired okay
    assertEquals(130L, d.longValue());

    invoice = new Invoice();
    invoice.setAmount(45);
    customer.getInvoices().add(invoice);
    d = customer.getAmountTwo();

    // proves r3 fired okay
    assertEquals(45L, d.longValue()); // Fails
    d = customer.getAmountThree();
    // proves r4 fired okay.
    assertEquals(45L, d.longValue());
    validationSession.close();
}

From source file:ru.histone.v2.BaseTest.java

protected Object getObjectValue(Object value) {
    if (isDouble(value)) {
        Double v = (Double) value;
        if (v % 1 == 0 && v <= Integer.MAX_VALUE) {
            return v.longValue();
        } else {//from w  ww. ja  va2  s.com
            return v.floatValue();
        }
    } else {
        return value;
    }
}

From source file:org.structr.core.property.LongProperty.java

@Override
public Long convertToNumber(Double source) {

    if (source != null) {
        return source.longValue();
    }// w w  w.ja  va2s. c o  m

    return null;
}

From source file:de.innovationgate.wgpublisher.expressions.tmlscript.wgaglobal.WGAGlobal.java

public static String format(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj)
        throws JavaScriptException {

    Object toBeFormatted = args[0];

    String formatString = null;//from  ww  w.ja  v a 2  s. co m
    if (args.length >= 2 && args[1] != null) {
        formatString = (String) Context.jsToJava(args[1], String.class);
    }

    String language = null;
    if (args.length >= 3 && args[2] != null) {
        language = (String) Context.jsToJava(args[2], String.class);
    }

    String formatTarget = null;

    if (toBeFormatted instanceof NativeJavaObject) {
        toBeFormatted = ((NativeJavaObject) toBeFormatted).unwrap();
    } else if (toBeFormatted instanceof Scriptable && toBeFormatted.getClass().getName()
            .equals("de.innovationgate.ext.org.mozilla.javascript.NativeDate")) {
        Scriptable jsDate = (Scriptable) toBeFormatted;
        Double javaTime = (Double) ScriptableObject.callMethod(jsDate, "getTime", null);
        toBeFormatted = new Date(javaTime.longValue());
    } else if (toBeFormatted instanceof Scriptable) {
        toBeFormatted = ((Scriptable) toBeFormatted).getDefaultValue(null);
    }

    // Fetch locale to use
    try {
        return get(thisObj).getWga().format((Object) Context.jsToJava(toBeFormatted, Object.class),
                formatString, language);
    } catch (WGException e) {
        throw Context.throwAsScriptRuntimeEx(e);
    }
}

From source file:com.linkedin.drelephant.tuning.BaselineComputeUtil.java

/**
 * Returns the average input size in bytes of a job (over last _numJobsForBaseline executions)
 * @param jobDefId job definition id of the job
 * @return average input size in bytes as long
 *///from w w  w .j a  v a 2  s  .co  m
private Long getAvgInputSizeInBytes(String jobDefId) {
    String sql = "SELECT AVG(inputSizeInBytes) as avgInputSizeInMB FROM "
            + "(SELECT job_exec_id, SUM(cast(value as decimal)) inputSizeInBytes, MAX(start_time) AS start_time "
            + "FROM yarn_app_result yar INNER JOIN yarn_app_heuristic_result yahr "
            + "ON yar.id=yahr.yarn_app_result_id " + "INNER JOIN yarn_app_heuristic_result_details yahrd "
            + "ON yahr.id=yahrd.yarn_app_heuristic_result_id "
            + "WHERE job_def_id=:jobDefId AND yahr.heuristic_name='" + CommonConstantsHeuristic.MAPPER_SPEED
            + "' " + "AND yahrd.name='Total input size in MB' "
            + "GROUP BY job_exec_id ORDER BY start_time DESC LIMIT :num ) temp";

    logger.debug("Running query for average input size computation " + sql);

    SqlRow baseline = Ebean.createSqlQuery(sql).setParameter("jobDefId", jobDefId)
            .setParameter("num", _numJobsForBaseline).findUnique();
    Double avgInputSizeInBytes = baseline.getDouble("avgInputSizeInMB") * FileUtils.ONE_MB;
    return avgInputSizeInBytes.longValue();
}

From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.Media.java

public String getJpcId() {
    String imagePk = get(JPCID);/*from ww  w. j a  v  a2 s .  c o  m*/
    if (StringUtils.contains(imagePk, "e+") == true) {
        Double l = NumberUtils.toDouble(imagePk);
        imagePk = Long.toString(l.longValue());
    }
    return imagePk;
}

From source file:org.gitools.analysis.stats.test.ZscoreTest.java

@Override
public void processPopulation(Iterable<Double> population) {

    Double seed;
    try {//from  www. ja v  a  2s  .  c  o m
        seed = find(population, notNull());
    } catch (NoSuchElementException e) {
        seed = 1.0;
    }

    this.random = new Random(seed.longValue());
    this.population = Lists.newArrayList(filter(population, notNull()));
}

From source file:org.dashbuilder.dataprovider.csv.CSVParser.java

protected Object parseValue(DataColumn column, String value) throws Exception {
    ColumnType type = column.getColumnType();
    try {//from   www. ja va  2s.co  m
        if (type.equals(ColumnType.DATE)) {
            String pattern = dataSetDef.getPattern(column.getId());
            // Handle special date pattern "epoch"
            if (pattern != null && DATE_FORMAT_EPOCH.equalsIgnoreCase(pattern)) {
                Double _epoch = Double.parseDouble(value);
                return new Date(_epoch.longValue() * 1000);
            } else {
                DateFormat dateFormat = getDateFormat(column.getId());
                return dateFormat.parse(value);
            }
        } else if (type.equals(ColumnType.NUMBER)) {
            DecimalFormat numberFormat = getNumberFormat(column.getId());
            return numberFormat.parse(value).doubleValue();
        } else {
            return value;
        }
    } catch (ParseException e) {
        String msg = "Error parsing value: " + value + ", " + e.getMessage()
                + ". Check column\u0027s data type consistency!";
        throw new Exception(msg);
    }
}

From source file:com.qmetry.qaf.automation.integration.qmetry.qmetry6.scheduler.Qmetry6SchedulerFilter.java

private boolean isTCIDMaching(TestNGScenario method, Testcase qtc) {
    long xmltcid = qtc.getTestcaseId();

    Map<String, Object> params = method.getMetaData();
    if ((null != params) && params.containsKey("TC_ID")) {
        Double tcids[] = StringUtil.extractNums((String) params.get("TC_ID"));
        for (Double tcid : tcids) {
            if (xmltcid == tcid.longValue()) {
                return true;
            }//www  .  j a  va  2s . co m
        }
    }
    Double[] tcidsFromName = StringUtil.extractNums((String) params.get("name"));
    for (Double tcid : tcidsFromName) {
        if (xmltcid == tcid.longValue()) {
            return true;
        }
    }
    return false;
}

From source file:com.qmetry.qaf.automation.integration.qmetry.testnglistener.QmetrySchedulerFilter.java

private boolean isTCIDMaching(TestNGScenario method, Testcase qtc) {
    long xmltcid = qtc.getTestcaseid().longValue();
    Map<String, Object> params = method.getMetaData();

    if ((null != params) && params.containsKey("TC_ID")) {
        Double tcids[] = StringUtil.extractNums((String) params.get("TC_ID"));
        for (Double tcid : tcids) {
            if (xmltcid == tcid.longValue()) {
                return true;
            }//from www  .j  a va  2  s  .c om
        }
    }
    Double[] tcidsFromName = StringUtil.extractNums((String) params.get("name"));
    for (Double tcid : tcidsFromName) {
        if (xmltcid == tcid.longValue()) {
            return true;
        }
    }

    return false;
}