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:org.apache.accumulo.examples.wikisearch.jexl.Arithmetic.java

protected Object fixLeft(Object left, Object right) {

    if (null == left || null == right)
        return left;

    if (!(right instanceof Number) && left instanceof Number) {
        right = NumberUtils.createNumber(right.toString());
    }//from  w ww.j  a v a  2s.c om

    if (right instanceof Number && left instanceof Number) {
        if (right instanceof Double)
            return ((Double) right).doubleValue();
        else if (right instanceof Float)
            return ((Float) right).floatValue();
        else if (right instanceof Long)
            return ((Long) right).longValue();
        else if (right instanceof Integer)
            return ((Integer) right).intValue();
        else if (right instanceof Short)
            return ((Short) right).shortValue();
        else if (right instanceof Byte)
            return ((Byte) right).byteValue();
        else
            return right;
    }
    if (right instanceof Number && left instanceof String) {
        Number num = NumberUtils.createNumber(left.toString());
        // Let's try to cast left as right's type.
        if (this.isFloatingPointNumber(right) && this.isFloatingPointNumber(left))
            return num;
        else if (this.isFloatingPointNumber(right))
            return num.doubleValue();
        else if (right instanceof Number)
            return num.longValue();
    } else if (right instanceof Boolean && left instanceof String) {
        if (left.equals("true") || left.equals("false"))
            return Boolean.parseBoolean(left.toString());

        Number num = NumberUtils.createNumber(left.toString());
        if (num.intValue() == 1)
            return (Boolean) true;
        else if (num.intValue() == 0)
            return (Boolean) false;
    }
    return left;
}

From source file:ome.testing.OMEData.java

List getRandomNumber(List l, Number number) {

    if (number == null) {
        return null;
    }/*from  w  w  w .j a  va2 s.  c  o  m*/

    if (l == null || l.size() == 0) {
        log.warn(emptyColl);
        return null;
    }

    List ordered = new ArrayList(l);
    List result = new ArrayList();

    while (ordered.size() > 0 && result.size() < number.longValue()) {
        int choice = randomChoice(ordered.size());
        result.add(ordered.remove(choice));
    }

    return result;

}

From source file:org.sakaiproject.assignment.persistence.AssignmentRepositoryImpl.java

@Override
public long countSubmittedSubmissionsForAssignment(String assignmentId) {
    Number number = (Number) sessionFactory.getCurrentSession().createCriteria(AssignmentSubmission.class)
            .setProjection(Projections.rowCount()).add(Restrictions.eq("assignment.id", assignmentId))
            .add(Restrictions.eq("submitted", Boolean.TRUE))
            .add(Restrictions.eq("userSubmission", Boolean.TRUE)).uniqueResult();
    return number.longValue();
}

From source file:org.elasticsearch.xpack.test.rest.XPackRestIT.java

/**
 * Disable monitoring/*ww w. j av a  2 s  .c om*/
 */
private void disableMonitoring() throws Exception {
    if (isMonitoringTest()) {
        final Map<String, Object> settings = new HashMap<>();
        settings.put("xpack.monitoring.collection.enabled", null);
        settings.put("xpack.monitoring.collection.interval", null);
        settings.put("xpack.monitoring.exporters._local.enabled", null);

        awaitCallApi("cluster.put_settings", emptyMap(), singletonList(singletonMap("transient", settings)),
                response -> {
                    Object acknowledged = response.evaluate("acknowledged");
                    return acknowledged != null && (Boolean) acknowledged;
                }, () -> "Exception when disabling monitoring");

        awaitBusy(() -> {
            try {
                ClientYamlTestResponse response = callApi("xpack.usage",
                        singletonMap("filter_path", "monitoring.enabled_exporters"), emptyList(),
                        getApiCallHeaders());

                @SuppressWarnings("unchecked")
                final Map<String, ?> exporters = (Map<String, ?>) response
                        .evaluate("monitoring.enabled_exporters");
                if (exporters.isEmpty() == false) {
                    return false;
                }

                final Map<String, String> params = new HashMap<>();
                params.put("node_id", "_local");
                params.put("metric", "thread_pool");
                params.put("filter_path", "nodes.*.thread_pool.write.active");
                response = callApi("nodes.stats", params, emptyList(), getApiCallHeaders());

                @SuppressWarnings("unchecked")
                final Map<String, Object> nodes = (Map<String, Object>) response.evaluate("nodes");
                @SuppressWarnings("unchecked")
                final Map<String, Object> node = (Map<String, Object>) nodes.values().iterator().next();

                @SuppressWarnings("unchecked")
                final Number activeWrites = (Number) extractValue("thread_pool.write.active", node);
                return activeWrites != null && activeWrites.longValue() == 0L;
            } catch (Exception e) {
                throw new ElasticsearchException("Failed to wait for monitoring exporters to stop:", e);
            }
        });
    }
}

From source file:org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1.java

private void markVertexUpdated(AtlasVertex vertex) {
    Date now = new Date();
    Number currVersion = vertex.getProperty(Constants.VERSION_PROPERTY_KEY, Number.class);
    long newVersion = currVersion == null ? 1 : (currVersion.longValue() + 1);

    vertex.setProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, now.getTime());
    vertex.setProperty(Constants.VERSION_PROPERTY_KEY, newVersion);
}

From source file:org.openmrs.module.idgen.service.db.HibernateIdentifierSourceDAO.java

/**
 * @see IdentifierSourceDAO#getSequenceValue(org.openmrs.module.idgen.SequentialIdentifierGenerator)
 *///  w w w . j a v  a  2 s . c  o  m
@Override
public Long getSequenceValue(SequentialIdentifierGenerator generator) {
    Number val = (Number) sessionFactory.getCurrentSession()
            .createSQLQuery("select next_sequence_value from idgen_seq_id_gen where id = :id")
            .setParameter("id", generator.getId()).uniqueResult();
    return val == null ? null : val.longValue();
}

From source file:dk.statsbiblioteket.netark.dvenabler.wrapper.NumericDocValuesWrapper.java

@Override
public long get(int docID) {
    tracker.ping(docID);/*from w w w  .ja  v  a  2s . c om*/
    try {
        IndexableField iField = reader.document(docID, FIELDS).getField(dvConfig.getName());
        if (iField == null) {
            log.warn("No stored value for field '" + dvConfig.getName() + "' in doc " + docID
                    + ". Returning -1");
            // This should have been handled by {@link DVAtomicReader#getDocsWithField}
            return -1;
        }
        Number number = iField.numericValue();
        if (number == null) {
            throw new RuntimeException("No numeric value '" + iField.stringValue() + "' for field '"
                    + dvConfig.getName() + "' in doc " + docID + ". This looks like a non-numeric field!");
        }
        // TODO: Determine correct method to call from field info
        switch (dvConfig.getNumericType()) {
        case LONG:
            return number.longValue();
        case INT:
            return number.intValue();
        case DOUBLE:
            return Double.doubleToLongBits(number.doubleValue());
        case FLOAT:
            return Float.floatToIntBits(number.longValue());
        default:
            throw new IllegalStateException(
                    "Unknown NumericType " + dvConfig.getNumericType() + " for field " + dvConfig.getName());
        }
    } catch (IOException e) {
        throw new RuntimeException("Unable to get field '" + dvConfig.getName() + "' from docID " + docID, e);
    }
}

From source file:op.tools.SYSTools.java

public static BigDecimal checkBigDecimal(String txt) {
    BigDecimal bd = null;//  w  ww . j a  v  a2s  . c om

    txt = assimilateDecimalSeparators(txt);
    try {
        NumberFormat nf = DecimalFormat.getNumberInstance();
        Number number = nf.parse(txt);

        if (number instanceof Long) {
            bd = BigDecimal.valueOf(number.longValue());
        } else if (number instanceof Double) {
            bd = BigDecimal.valueOf(number.doubleValue());
        } else if (number instanceof BigDecimal) {
            bd = (BigDecimal) number;
        }

    } catch (ParseException ex) {
        OPDE.debug(ex);
        // Pech
    }
    return bd;
}

From source file:org.openadaptor.auxil.connector.iostream.writer.FileWriteConnector.java

/**
 * attempts to retrieve a valid number from the supplied string. This
 * number is then multiplied by the mupltiplier and used for the
 * rollover size. If the string does not fit the format then we simply
 * leave the rollover size as it was and return.
 *
 * @param s - the string to be converted
 * @param indicater - the file size indicater (eg. Gb, Mb, Kb, ...)
 * @param multiplier - the value to multiply the rollover size by to
 * convert to bytes (eg. 2Kb becomes 2000)
 */// w  w  w. j  a  va 2 s . com
private void parseSize(String s, String indicater, int multiplier) {
    try {
        DecimalFormat nf = new DecimalFormat("#,##0" + indicater);
        Number n = nf.parse(s.toLowerCase());

        rolloverSize = n.longValue() * multiplier;
    } catch (ParseException e) {
    }
}

From source file:org.openadaptor.auxil.connector.iostream.writer.FileWriteConnector.java

/**
 * attempts to retrieve a valid number from the supplied string. This
 * number is then multiplied by the mupltiplier to convert it into
 * milliseconds and used for the rollover period. If the string does
 * not fit the format then we simply leave the rollover period as it
 * was and return.// ww w .j ava  2  s .c o m
 *
 * @param s - the string to be converted
 * @param indicater - the rollover period indicater (eg. M, W, D, ...)
 * @param multiplier - the value to multiply the rollover period by to
 * convert to milliseconds (eg. 2D becomes 2*24*60*60*1000)
 */
private void parseDate(String s, String indicater, long multiplier) {
    try {
        DecimalFormat nf = new DecimalFormat("#" + indicater);
        Number n = nf.parse(s.toLowerCase());

        rolloverPeriod = n.longValue() * multiplier;
    } catch (ParseException e) {
    }
}