Example usage for java.lang Number longValue

List of usage examples for java.lang Number longValue

Introduction

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

Prototype

public abstract long longValue();

Source Link

Document

Returns the value of the specified number as a long .

Usage

From source file:de.codesourcery.flocking.ui.NumberInputField.java

private Long limitInt(Number n) {
    final long value = n == null ? 0 : n.longValue();
    if (value < minValue) {
        return (long) minValue;
    }/*from w w w.j a v  a 2  s  .c o  m*/
    if (value > maxValue) {
        return (long) maxValue;
    }
    return value;
}

From source file:org.apache.tinkerpop.gremlin.hadoop.process.computer.giraph.GiraphMemory.java

@Override
public void incr(final String key, final long delta) {
    this.checkKeyValue(key, delta);
    if (this.isMasterCompute) { // only called on setup() and terminate()
        Number value = this.<Rule>getAggregatedValue(key).<Number>getObject();
        value = null == value ? delta : value.longValue() + delta;
        this.setAggregatedValue(key, new Rule(Rule.Operation.INCR, value));
    } else {/*from  w w w.j  a va2 s . com*/
        this.worker.aggregate(key, new Rule(Rule.Operation.INCR, delta));
    }
}

From source file:net.solarnetwork.node.dao.jdbc.power.JdbcPowerDatumDao.java

@Override
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public List<PowerDatum> getDatumNotUploaded(String destination) {
    return findDatumNotUploaded(new RowMapper<PowerDatum>() {

        @Override/*from   w  w w.  j a  va 2  s.com*/
        public PowerDatum mapRow(ResultSet rs, int rowNum) throws SQLException {
            if (log.isTraceEnabled()) {
                log.trace("Handling result row " + rowNum);
            }
            PowerDatum datum = new PowerDatum();
            int col = 1;
            datum.setCreated(rs.getTimestamp(col++));
            datum.setSourceId(rs.getString(col++));

            Number val = (Number) rs.getObject(col++);
            datum.setLocationId(val == null ? null : val.longValue());

            val = (Number) rs.getObject(col++);
            datum.setWatts(val == null ? null : val.intValue());

            val = (Number) rs.getObject(col++);
            datum.setBatteryVolts(val == null ? null : val.floatValue());

            val = (Number) rs.getObject(col++);
            datum.setBatteryAmpHours(val == null ? null : val.doubleValue());

            val = (Number) rs.getObject(col++);
            datum.setDcOutputVolts(val == null ? null : val.floatValue());

            val = (Number) rs.getObject(col++);
            datum.setDcOutputAmps(val == null ? null : val.floatValue());

            val = (Number) rs.getObject(col++);
            datum.setAcOutputVolts(val == null ? null : val.floatValue());

            val = (Number) rs.getObject(col++);
            datum.setAcOutputAmps(val == null ? null : val.floatValue());

            val = (Number) rs.getObject(col++);
            datum.setWattHourReading(val == null ? null : val.longValue());

            val = (Number) rs.getObject(col++);
            datum.setAmpHourReading(val == null ? null : val.doubleValue());

            return datum;
        }
    });
}

From source file:org.apache.qpid.server.configuration.VirtualHostConfiguration.java

private long getBrokerAttributeAsLong(String name) {
    Number brokerValue = (Number) _broker.getAttribute(name);
    return brokerValue == null ? 0 : brokerValue.longValue();
}

From source file:com.anrisoftware.globalpom.format.byteformat.ByteFormat.java

/**
 * Formats the specified computer byte.// w ww  .  ja va2  s  .co  m
 * <p>
 * The format follows the pattern:
 *
 * <pre>
 * &lt;value&gt; byte
 * </pre>
 *
 * <p>
 * <h2>Examples</h2>
 * <p>
 * <ul>
 * <li>{@code "64 byte"}
 * </ul>
 *
 * @param obj
 *            the {@link Measurable} or {@link Number}.
 *
 * @param multiplier
 *            the unit {@link UnitMultiplier}.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public StringBuffer format(Object obj, StringBuffer buff, FieldPosition pos, UnitMultiplier multiplier) {
    if (obj instanceof Measurable) {
        Measurable measurable = (Measurable) obj;
        formatMeasurable(measurable.longValue(NonSI.BYTE), buff, multiplier);
    } else if (obj instanceof Number) {
        Number value = (Number) obj;
        formatMeasurable(value.longValue(), buff, multiplier);
    }
    return buff;
}

From source file:com.facebook.presto.operator.aggregation.AbstractTestApproximateAggregationFunction.java

private void testCorrectnessOfErrorFunction(List<Number> inputList) throws Exception {
    int inRange = 0;
    int numberOfRuns = 1000;
    double sampleRatio = 1 / (double) WEIGHT;
    double actual = getExpectedValue(inputList);
    Random rand = new Random(1);

    for (int i = 0; i < numberOfRuns; i++) {
        //Compute Sampled Value using sampledList (numberOfRuns times)
        ImmutableList.Builder<Number> sampledList = ImmutableList.builder();
        for (Number x : inputList) {
            if (rand.nextDouble() < sampleRatio) {
                sampledList.add(x);//w w w  .ja va  2s.c  o  m
            }
        }

        ImmutableList<Number> list = sampledList.build();
        BlockBuilder builder = getType().createBlockBuilder(new BlockBuilderStatus(), list.size());
        for (Number sample : list) {
            if (getType().equals(BIGINT)) {
                BIGINT.writeLong(builder, sample.longValue());
            } else if (getType().equals(DOUBLE)) {
                DOUBLE.writeDouble(builder, sample.doubleValue());
            } else {
                throw new AssertionError("Can only handle longs and doubles");
            }
        }
        Page page = new Page(builder.build());
        page = OperatorAssertion.appendSampleWeight(ImmutableList.of(page), WEIGHT).get(0);
        Accumulator accumulator = getFunction().bind(ImmutableList.of(0), Optional.empty(),
                Optional.of(page.getChannelCount() - 1), getConfidence()).createAccumulator();

        accumulator.addInput(page);
        Block result = getFinalBlock(accumulator);

        String approxValue = BlockAssertions.toValues(accumulator.getFinalType(), result).get(0).toString();
        double approx = Double.parseDouble(approxValue.split(" ")[0]);
        double error = Double.parseDouble(approxValue.split(" ")[2]);

        //Check if actual answer lies within [approxAnswer - error, approxAnswer + error]
        if (Math.abs(approx - actual) <= error) {
            inRange++;
        }
    }

    BinomialDistribution binomial = new BinomialDistribution(numberOfRuns, getConfidence());
    int lowerBound = binomial.inverseCumulativeProbability(0.01);
    int upperBound = binomial.inverseCumulativeProbability(0.99);
    assertTrue(lowerBound < inRange && inRange < upperBound, String
            .format("%d out of %d passed. Expected [%d, %d]", inRange, numberOfRuns, lowerBound, upperBound));
}

From source file:org.hil.core.dao.hibernate.ChildrenVaccinationHistoryDaoHibernate.java

public int setNotVaccinated(List<Number> shotIds) {
    String strIds = "(";
    for (Number id : shotIds)
        strIds += id.longValue() + ",";
    strIds = strIds.substring(0, strIds.length() - 1);
    strIds += ")";
    String sql = "UPDATE children_vaccination_history SET vaccinated = 0, date_of_immunization = null, id_vaccinated_location = null, other_vaccinated_location = 0, "
            + " created_time = null, modified_time = null, from_mobile = null WHERE id IN " + strIds;
    log.debug(sql);/*  www  .j  a  va2  s . c  o m*/
    SQLQuery qry = getSession().createSQLQuery(sql);
    return qry.executeUpdate();
}

From source file:ubc.pavlab.aspiredb.server.dao.SecurableDaoBaseImpl.java

@Override
@Transactional(readOnly = true)//from  w  w  w  .  j  av  a2  s .c o  m
public long getCountAll() {
    Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
    Number totalSize = (Number) session.createCriteria(this.elementClass).setProjection(Projections.rowCount())
            .uniqueResult();
    return totalSize.longValue();
}

From source file:MutableLong.java

/**
 * Adds a value.//  www. jav a 2 s.com
 * 
 * @param operand
 *            the value to add
 * @throws NullPointerException
 *             if the object is null
 *
 * @since Commons Lang 2.2
 */
public void add(Number operand) {
    this.value += operand.longValue();
}

From source file:MutableLong.java

/**
 * Subtracts a value./*from w ww .  ja va 2s  .  co  m*/
 * 
 * @param operand
 *            the value to add
 * @throws NullPointerException
 *             if the object is null
 *
 * @since Commons Lang 2.2
 */
public void subtract(Number operand) {
    this.value -= operand.longValue();
}