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.lucene.index.FieldsWriter.java

final void writeField(FieldInfo fi, Fieldable field) throws IOException {
    fieldsStream.writeVInt(fi.number);//  ww w.  j  ava  2s.  c om
    int bits = 0;
    if (field.isTokenized())
        bits |= FIELD_IS_TOKENIZED;
    if (field.isBinary())
        bits |= FIELD_IS_BINARY;
    if (field instanceof NumericField) {
        switch (((NumericField) field).getDataType()) {
        case INT:
            bits |= FIELD_IS_NUMERIC_INT;
            break;
        case LONG:
            bits |= FIELD_IS_NUMERIC_LONG;
            break;
        case FLOAT:
            bits |= FIELD_IS_NUMERIC_FLOAT;
            break;
        case DOUBLE:
            bits |= FIELD_IS_NUMERIC_DOUBLE;
            break;
        default:
            assert false : "Should never get here";
        }
    }
    fieldsStream.writeByte((byte) bits);

    if (field.isBinary()) {
        final byte[] data;
        final int len;
        final int offset;
        data = field.getBinaryValue();
        len = field.getBinaryLength();
        offset = field.getBinaryOffset();

        fieldsStream.writeVInt(len);
        fieldsStream.writeBytes(data, offset, len);
    } else if (field instanceof NumericField) {
        final NumericField nf = (NumericField) field;
        final Number n = nf.getNumericValue();
        switch (nf.getDataType()) {
        case INT:
            fieldsStream.writeVVInt(n.intValue());
            break;
        case LONG:
            fieldsStream.writeVVLong(n.longValue());
            break;
        case FLOAT:
            fieldsStream.writeVVVInt(Float.floatToIntBits(n.floatValue()));
            break;
        case DOUBLE:
            fieldsStream.writeVVVLong(Double.doubleToLongBits(n.doubleValue()));
            break;
        default:
            assert false : "Should never get here";
        }
    } else {
        fieldsStream.writeString(field.stringValue());
    }
}

From source file:org.diorite.config.impl.ConfigPropertyValueImpl.java

@SuppressWarnings("unchecked")
@Override//ww  w  .ja va2 s.  c o  m
public void setRawValue(@Nullable T value) {
    Class<T> rawType = this.template.getRawType();
    Class<?> primitiveRawType = DioriteReflectionUtils.getPrimitive(rawType);
    if (!primitiveRawType.isPrimitive()) {
        if (value != null) {
            if (!rawType.isInstance(value)
                    && !DioriteReflectionUtils.getWrapperClass(rawType).isInstance(value)) {
                throw new IllegalArgumentException("Invalid object type: " + value + " in template property: "
                        + this.template.getName() + " (" + this.template.getGenericType() + ")");
            }
        } else {
            // keep collections not null if possible.
            try {
                if (Collection.class.isAssignableFrom(rawType)
                        || (Map.class.isAssignableFrom(rawType) && !Config.class.isAssignableFrom(rawType))) {
                    this.rawValue = YamlCollectionCreator.createCollection(rawType, 10);
                    return;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else if (value instanceof Number) {
        Number num = (Number) value;
        if (primitiveRawType == byte.class) {
            num = num.byteValue();
        }
        if (primitiveRawType == short.class) {
            num = num.shortValue();
        }
        if (primitiveRawType == int.class) {
            num = num.intValue();
        }
        if (primitiveRawType == long.class) {
            num = num.longValue();
        }
        if (primitiveRawType == float.class) {
            num = num.floatValue();
        }
        if (primitiveRawType == double.class) {
            num = num.doubleValue();
        }
        this.rawValue = (T) num;
        return;
    } else {
        throw new IllegalArgumentException("Invalid object type: " + value + " in template property: "
                + this.template.getName() + " (" + this.template.getGenericType() + ")");
    }
    this.rawValue = value;
}

From source file:org.apache.cocoon.faces.taglib.UIComponentTag.java

protected final long evaluateLong(String value) {
    if (FacesUtils.isExpression(value)) {
        Number obj = (Number) createValueBinding(value).getValue(getFacesContext());
        return obj.longValue();
    }/*w ww  .  j  a  v  a  2s .  co  m*/

    return Long.parseLong(value);
}

From source file:com.proper.uip.common.core.dao.HibernateDao.java

@SuppressWarnings("unchecked")
public <K> Page<K> pageSQLQuery(PageConfig pageConfig, SQLQuery sqlQuery, Object... values) {
    Page<K> page = new Page<K>(pageConfig);
    String totalSql = "select count(*) as total from(" + sqlQuery.getQueryString() + ")";
    Query countQuery = this.getSession().createSQLQuery(totalSql);
    setParams(countQuery, values);/*w w w  .j  a  v  a  2  s . co m*/
    Number total = (Number) countQuery.uniqueResult();
    if (total != null) {
        page.setTotal(total.longValue());
        sqlQuery.setFirstResult(page.getOffset()).setMaxResults(page.getPageSize());
        setParams(sqlQuery, values);
        List<K> list = sqlQuery.list();
        page.setRows(list);
    } else {
        page.setTotal(0);
        page.setRows(new ArrayList<K>());
    }
    return page;
}

From source file:com.proper.uip.common.core.dao.HibernateDao.java

@SuppressWarnings("unchecked")
public Page<Map<String, Object>> pageSQLQuery(PageConfig pageConfig, String sql, Object... values) {
    Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageConfig);
    String totalSql = "select count(*) as total from(" + sql + ")";
    Query countQuery = this.getSession().createSQLQuery(totalSql);
    setParams(countQuery, values);//from w w  w . jav  a  2s  . c o m
    Number total = (Number) countQuery.uniqueResult();
    if (total != null) {
        page.setTotal(total.longValue());
        Query query = this.getSession().createSQLQuery(sql).setFirstResult(page.getOffset())
                .setMaxResults(page.getPageSize()).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
        setParams(query, values);
        List<Map<String, Object>> list = query.list();
        page.setRows(list);
    } else {
        page.setTotal(0);
        page.setRows(new ArrayList<Map<String, Object>>());
    }
    return page;
}

From source file:org.hyperic.hq.ui.servlet.ParameterizedServlet.java

/**
 * Parse a required long parameter./*from   w w  w  .  j  a  v a2s .  c  o m*/
 *
 * @param request the servlet request
 * @param paramName the parameter name
 * @return the value of the parsed parameter
 * @throws IllegalArgumentException if the parameter didn't exist
 */
protected long parseRequiredLongParameter(HttpServletRequest request, String paramName) {
    long value;
    String param = request.getParameter(paramName);
    if (null != param) {
        Number n = NumberUtil.stringAsNumber(param);
        if (n.equals(NumberUtil.NaN)) {
            throw invalidParamErr(paramName, param);
        } else {
            value = n.longValue();
        }
    } else {
        throw requiredParamErr(paramName);
    }
    return value;
}

From source file:org.hyperic.hq.ui.servlet.ParameterizedServlet.java

/**
 * Parse a long parameter./*from  w w w  .j  a va2 s.  co  m*/
 *
 * @param request the servlet request
 * @param paramName the name of the parameter to parse
 * @param defaultValue the default value for the parameter
 * @return the value of the parsed parameter or the default if the
 * parameter didn't exist
 */
protected long parseLongParameter(HttpServletRequest request, String paramName, long defaultValue) {
    long value = defaultValue;
    String param = request.getParameter(paramName);
    if (null != param) {
        Number n = NumberUtil.stringAsNumber(param);
        if (n.equals(NumberUtil.NaN)) {
            invalidParamWarn(paramName, param, defaultValue);
        } else {
            value = n.longValue();
        }
    }
    return value;
}

From source file:com.parse.ParseConfig.java

/**
 * Access a {@code long} value, returning a default value if it doesn't exist.
 *
 * @param key//from   w  w  w.  j a  v  a 2 s. c  o m
 *          The key to access the value for.
 * @param defaultValue
 *          The value to return if the key is not present or has the wrong type.
 * @return The default value if there is no such key or if it is not a number.
 */
public long getLong(String key, long defaultValue) {
    Number number = getNumber(key);
    return number != null ? number.longValue() : defaultValue;
}

From source file:com.bdb.weather.display.summary.HighLowMedianTempPanel.java

@Override
public void chartMouseClicked(ChartMouseEventFX event) {
    ChartEntity entity = event.getEntity();
    ////from  w w  w . j  av  a  2s  .  co m
    // Was a point on the plot selected?
    //
    if (entity instanceof XYItemEntity) {
        XYItemEntity itemEntity = (XYItemEntity) entity;
        XYDataset dataset = itemEntity.getDataset();
        Number x = dataset.getXValue(itemEntity.getSeriesIndex(), itemEntity.getItem());

        //ZoneId id = ZoneId.of(ZoneId.systemDefault().getId());
        //ZoneOffset offset = ZoneOffset.of(ZoneId.systemDefault().getId());
        LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochSecond(x.longValue() / 1000),
                ZoneId.systemDefault());

        boolean doubleClick = event.getTrigger().getClickCount() == 2;
        if (doubleClick)
            supporter.launchView(viewLauncher, time.toLocalDate());
    }
}

From source file:org.red5.io.amf3.Output.java

/** {@inheritDoc} */
@Override/*w  w  w . j  a  va 2s  .com*/
public void writeNumber(Number num) {
    writeAMF3();
    if (num.longValue() < AMF3.MIN_INTEGER_VALUE || num.longValue() > AMF3.MAX_INTEGER_VALUE) {
        // Out of range for integer encoding
        buf.put(AMF3.TYPE_NUMBER);
        buf.putDouble(num.doubleValue());
    } else if (num instanceof Long || num instanceof Integer || num instanceof Short || num instanceof Byte) {
        buf.put(AMF3.TYPE_INTEGER);
        putInteger(num.longValue());
    } else {
        buf.put(AMF3.TYPE_NUMBER);
        buf.putDouble(num.doubleValue());
    }
}