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:org.apache.usergrid.apm.service.NetworkTestData.java

public static ClientNetworkMetrics getGeneratedMetricBean(long givenAppId, Date start, Date end) {
    ClientNetworkMetrics bean = new ClientNetworkMetrics();
    bean.setAppConfigType(configs[generator.nextInt(4)]);

    int index = generator.nextInt(uids.length);

    if (givenAppId == 0) {
        bean.setAppId(appId[generator.nextInt(3)]);
    } else {/*from   ww w .j  a v  a2s . c om*/
        bean.setAppId(givenAppId);
    }
    bean.setDeviceId(deviceIds[index]);
    bean.setNetworkCarrier(networkCarriers[generator.nextInt(3)]);
    bean.setNetworkType(networkType[generator.nextInt(3)]);
    bean.setUrl(wsUrls[index]);

    bean.setStartTime((Date) start.clone());
    bean.setEndTime((Date) end.clone());
    bean.setTimeStamp((Date) end.clone());

    long latency = getSimulatedLatency(bean.getNetworkType(), bean.getNetworkCarrier(), bean.getUrl());
    double rate = getFailureRate(bean.getNetworkType(), bean.getNetworkCarrier(), bean.getUrl());

    bean.setLatency(latency / 2);
    bean.setNumSamples(new Long(generator.nextInt(5) + 1));

    Double numErrors = (rate * bean.getNumSamples());

    bean.setNumErrors(numErrors.longValue());

    return bean;
}

From source file:org.apache.usergrid.apm.service.NetworkTestData.java

public static void populateSessionDataForMinutes(int numMin, Calendar startTime, int numDevices,
        Long givenAppId) {//from w  w w  .j ava  2s  .c  o  m

    NetworkMetricsDBService service = ServiceFactory.getMetricsDBServiceInstance();

    for (int j = 0; j < numMin; j++) {
        startTime.add(Calendar.MINUTE, 1);
        for (int l = 0; l < numDevices; l++) {//put 10 random beans
            startTime.set(Calendar.SECOND, generator.nextInt(60));

            Calendar endTime = Calendar.getInstance();
            endTime.setTime(startTime.getTime());
            endTime.add(Calendar.SECOND, generator.nextInt(60));

            Date start = startTime.getTime();
            Date end = endTime.getTime();

            ClientNetworkMetrics bean = new ClientNetworkMetrics();

            int index = generator.nextInt(uids.length);

            if (givenAppId == 0) {
                bean.setAppId(appId[generator.nextInt(3)]);
            } else {
                bean.setAppId(givenAppId);
            }
            bean.setAppConfigType(configs[generator.nextInt(4)]);
            bean.setApplicationVersion(new Integer(generator.nextInt(2) + 1).toString());
            bean.setDeviceId(deviceIds[index]);
            bean.setNetworkCarrier(networkCarriers[generator.nextInt(3)]);
            bean.setNetworkType(networkType[generator.nextInt(3)]);
            bean.setUrl(wsUrls[index]);
            bean.setStartTime(start);
            bean.setEndTime(end);

            long latency = getSimulatedLatency(bean.getNetworkType(), bean.getNetworkCarrier(), bean.getUrl());
            double rate = getFailureRate(bean.getNetworkType(), bean.getNetworkCarrier(), bean.getUrl());

            bean.setLatency(latency / 2);
            bean.setNumSamples(new Long(generator.nextInt(5)));

            Double numErrors = (rate * bean.getNumSamples());

            bean.setNumErrors(numErrors.longValue());

            service.saveNetworkMetrics(bean);
        }
    }
}

From source file:org.apache.usergrid.apm.service.NetworkTestData.java

public static void populateDataForMinutes(int numMin, Calendar startTime, int numDevices, Long givenAppId,
        Vector<Device> devices) {

    NetworkMetricsDBService service = ServiceFactory.getMetricsDBServiceInstance();

    for (int j = 0; j < numMin; j++) {
        startTime.add(Calendar.MINUTE, 1);
        for (int l = 0; l < numDevices; l++) {//put 10 random beans
            startTime.set(Calendar.SECOND, generator.nextInt(60));

            Calendar endTime = Calendar.getInstance();
            endTime.setTime(startTime.getTime());
            endTime.add(Calendar.SECOND, generator.nextInt(60));

            Date start = startTime.getTime();
            Date end = endTime.getTime();

            ClientNetworkMetrics bean = new ClientNetworkMetrics();
            int index = generator.nextInt(devices.size());
            Device d = devices.get(index);

            bean.setAppId(givenAppId);/*  w w  w  .j  a v  a 2 s  .  co m*/

            bean.setAppConfigType(configs[generator.nextInt(4)]);
            bean.setApplicationVersion(new Integer(generator.nextInt(2) + 1).toString());
            bean.setDeviceId(d.getUniqueDeviceId());
            bean.setNetworkCarrier(d.getNetworkCarrier());
            bean.setNetworkType(d.getNetworkType());
            bean.setDeviceModel(d.getModel());
            bean.setDevicePlatform(d.getPlatform());

            bean.setUrl(wsUrls[index]);
            bean.setStartTime(start);
            bean.setEndTime(end);
            bean.setTimeStamp(end);

            long latency = getSimulatedLatency(bean.getNetworkType(), bean.getNetworkCarrier(), bean.getUrl());
            double rate = getFailureRate(bean.getNetworkType(), bean.getNetworkCarrier(), bean.getUrl());

            bean.setLatency(latency * 2);
            bean.setNumSamples(1L);

            Double numErrors = (rate * bean.getNumSamples());

            bean.setNumErrors(numErrors.longValue());

            service.saveNetworkMetrics(bean);
        }
    }
}

From source file:org.apache.usergrid.apm.service.NetworkTestData.java

public static void populateCompactNetworkMetricsForMinutes(int numMin, Calendar startTime, int numDevices,
        Long givenAppId, Vector<Device> devices) {

    NetworkMetricsDBService service = ServiceFactory.getMetricsDBServiceInstance();
    List<MetricsChartCriteria> cqs = ServiceFactory.getNetworkMetricsChartCriteriaService()
            .getDefaultChartCriteriaForApp(givenAppId);

    int cqSize = cqs.size();

    for (int j = 0; j < numMin; j++) {
        startTime.add(Calendar.MINUTE, 1);
        for (int l = 0; l < numDevices; l++) {//put 10 random beans
            startTime.set(Calendar.SECOND, generator.nextInt(60));

            Calendar endTime = Calendar.getInstance();
            endTime.setTime(startTime.getTime());
            endTime.add(Calendar.SECOND, generator.nextInt(60));

            Date start = startTime.getTime();
            Date end = endTime.getTime();

            CompactNetworkMetrics bean = new CompactNetworkMetrics();

            int index = generator.nextInt(devices.size());
            Device d = devices.get(index);

            bean.setAppId(givenAppId);//from w w  w  .  j av a2 s . com

            bean.setChartCriteriaId(cqs.get(generator.nextInt(cqSize)).getId());
            bean.setAppConfigType(configs[generator.nextInt(4)]);
            bean.setApplicationVersion(new Integer(generator.nextInt(2) + 1).toString());
            bean.setDeviceId(d.getUniqueDeviceId());
            bean.setNetworkCarrier(d.getNetworkCarrier());
            bean.setNetworkType(d.getNetworkType());
            bean.setDeviceModel(d.getModel());
            bean.setDevicePlatform(d.getPlatform());
            bean.setTimeStamp(start);
            bean.setSamplePeriod(SamplePeriod.MINUTE);

            long latency = getSimulatedLatency(bean.getNetworkType(), bean.getNetworkCarrier(), null);
            double rate = getFailureRate(bean.getNetworkType(), bean.getNetworkCarrier(), null);

            bean.setMaxLatency(latency * 2);
            bean.setMinLatency(latency / 2);
            bean.setNumSamples(new Long(generator.nextInt(5)));

            Double numErrors = (rate * bean.getNumSamples());

            bean.setNumErrors(numErrors.longValue());
            bean.setSumLatency(bean.getNumSamples() * latency);
            int serverLatencyWeight = generator.nextInt(50) + 10;
            bean.setSumServerLatency((latency * serverLatencyWeight) / 100);
            service.saveCompactNetworkMetrics(bean);

        }
    }
}

From source file:com.example.mobilewebproxy.MainActivity.java

private static String getBytesTextValue(String prevCount, long countRaise) {

    long totalBytes = countRaise;
    Double prevNum;/*  w ww .j ava  2 s . c om*/
    Double convertedValue;
    StringBuilder builder = new StringBuilder(prevCount);

    if (!prevCount.endsWith("kb") && !prevCount.endsWith("mb")) {
        builder.deleteCharAt(prevCount.length() - 1);

        Integer temp = Integer.parseInt(builder.toString());
        totalBytes += temp.longValue();
    } else if (prevCount.endsWith("kb")) {
        builder.delete(prevCount.length() - 2, prevCount.length());

        prevNum = Double.parseDouble(builder.toString());
        convertedValue = prevNum * 1024.0;

        totalBytes += convertedValue.longValue();
    }

    else if (prevCount.endsWith("mb")) {
        builder.delete(prevCount.length() - 2, prevCount.length());

        prevNum = Double.parseDouble(builder.toString());
        convertedValue = prevNum * 1024.0 * 1024.0;

        totalBytes += convertedValue.longValue();
    }

    return bytesToReadableString(totalBytes);
}

From source file:com.projity.util.ClassUtils.java

/**
 * Convert a Double to an Object of a given class
 * @param value Double value to convert// ww w . ja v  a  2s.c  o m
 * @param clazz Class the class to convert to
 * @return new object of the given class
 * @throws IllegalArgumentException if the value is not convertible to the class
 */
public static Object doubleToObject(Double value, Class clazz) {
    if (clazz == Boolean.class)
        return new Boolean(value.doubleValue() != 0.0);
    else if (clazz == Byte.class)
        return new Byte(value.byteValue());
    else if (clazz == Short.class)
        return new Short(value.shortValue());
    else if (clazz == Integer.class)
        return new Integer(value.intValue());
    else if (clazz == Long.class)
        return new Long(value.longValue());
    else if (clazz == Float.class)
        return new Float(value.floatValue());
    else if (clazz == Double.class)
        return value;
    else if (clazz == Money.class)
        return Money.getInstance(value.doubleValue());
    else if (clazz == Duration.class)
        return Duration.getInstanceFromDouble(value);
    else if (clazz == Work.class)
        return Work.getWorkInstanceFromDouble(value);

    throw new IllegalArgumentException("Class " + clazz + " cannot be converted from a Double");
}

From source file:org.openmhealth.data.generator.service.StepCountDataPointGenerator.java

@Override
public StepCount newMeasure(TimestampedValueGroup valueGroup) {

    DurationUnitValue duration = new DurationUnitValue(SECOND, valueGroup.getValue(DURATION_KEY));
    double stepsPerMin = valueGroup.getValue(STEPS_PER_MINUTE_KEY);

    Double stepCount = stepsPerMin * duration.getValue().doubleValue() / 60.0;

    return new StepCount.Builder(stepCount.longValue())
            .setEffectiveTimeFrame(ofStartDateTimeAndDuration(valueGroup.getTimestamp(), duration)).build();
}

From source file:nz.co.senanque.functions.FunctionTest.java

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

    Customer customer = m_customerDAO.createCustomer();
    validationSession.bind(customer);//from ww w .  ja va 2  s  .  c o 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());

    long days = invoice.getDays();

    // proves r2 fired okay
    assertEquals(3834L, days);

    Date revisedDate = invoice.getRevisedDate();
    assertEquals("Mon Apr 24 00:00:00 NZST 2000", revisedDate.toString());

}

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

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

    Customer customer = m_customerDAO.createCustomer();
    validationSession.bind(customer);/*ww w.  j  a  v  a 2 s. c o m*/

    // proves r2 fired okay
    Invoice invoice = new Invoice();
    invoice.setDescription("test invoice");
    invoice.setAmount(100);
    customer.setOneInvoice(invoice);
    Double d = customer.getAmountOne();
    assertEquals(100L, d.longValue());

    customer.setOneInvoice(null);
    d = customer.getAmountOne();
    assertEquals(0L, d.longValue());

    validationSession.close();
}

From source file:org.apache.hadoop.hive.ql.udf.UDFToLong.java

public Long evaluate(Double i) {
    if (i == null) {
        return null;
    } else {/*from ww  w.j av  a 2s .c o m*/
        return Long.valueOf(i.longValue());
    }
}