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.rhq.enterprise.gui.common.servlet.ParameterizedServlet.java

/**
 * Parse a long parameter./*from  w w  w .j ava 2  s. c  o 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.evolveum.midpoint.repo.sql.helpers.ObjectUpdater.java

private <T extends ObjectType> String nonOverwriteAddObjectAttempt(PrismObject<T> object, RObject rObject,
        String originalOid, Session session, OrgClosureManager.Context closureContext)
        throws ObjectAlreadyExistsException, SchemaException, DtoTranslationException {

    // check name uniqueness (by type)
    if (StringUtils.isNotEmpty(originalOid)) {
        LOGGER.trace("Checking oid uniqueness.");
        //todo improve this table name bullshit
        Class hqlType = ClassMapper.getHQLTypeClass(object.getCompileTimeClass());
        SQLQuery query = session/*w w  w  . j  av  a2  s  .  c om*/
                .createSQLQuery("select count(*) from " + RUtil.getTableName(hqlType) + " where oid=:oid");
        query.setString("oid", object.getOid());

        Number count = (Number) query.uniqueResult();
        if (count != null && count.longValue() > 0) {
            throw new ObjectAlreadyExistsException("Object '" + object.getCompileTimeClass().getSimpleName()
                    + "' with oid '" + object.getOid() + "' already exists.");
        }
    }

    updateFullObject(rObject, object);

    LOGGER.trace("Saving object (non overwrite).");
    String oid = (String) session.save(rObject);
    lookupTableHelper.addLookupTableRows(session, rObject, false);
    caseHelper.addCertificationCampaignCases(session, rObject, false);

    if (closureManager.isEnabled()) {
        Collection<ReferenceDelta> modifications = createAddParentRefDelta(object);
        closureManager.updateOrgClosure(null, modifications, session, oid, object.getCompileTimeClass(),
                OrgClosureManager.Operation.ADD, closureContext);
    }

    return oid;
}

From source file:com.facebook.stetho.json.ObjectMapper.java

private Object getValueForField(Field field, Object value) throws JSONException {
    try {/*from ww  w .  j av  a 2  s.  c  om*/
        if (value != null) {
            if (value == JSONObject.NULL) {
                return null;
            }
            if (value.getClass() == field.getType()) {
                return value;
            }
            if (value instanceof JSONObject) {
                return convertValue(value, field.getType());
            } else {
                if (field.getType().isEnum()) {
                    return getEnumValue((String) value, field.getType().asSubclass(Enum.class));
                } else if (value instanceof JSONArray) {
                    return convertArrayToList(field, (JSONArray) value);
                } else if (value instanceof Number) {
                    // Need to convert value to Number This happens because json treats 1 as an Integer even
                    // if the field is supposed to be a Long
                    Number numberValue = (Number) value;
                    Class<?> clazz = field.getType();
                    if (clazz == Integer.class || clazz == int.class) {
                        return numberValue.intValue();
                    } else if (clazz == Long.class || clazz == long.class) {
                        return numberValue.longValue();
                    } else if (clazz == Double.class || clazz == double.class) {
                        return numberValue.doubleValue();
                    } else if (clazz == Float.class || clazz == float.class) {
                        return numberValue.floatValue();
                    } else if (clazz == Byte.class || clazz == byte.class) {
                        return numberValue.byteValue();
                    } else if (clazz == Short.class || clazz == short.class) {
                        return numberValue.shortValue();
                    } else {
                        throw new IllegalArgumentException("Not setup to handle class " + clazz.getName());
                    }
                }
            }
        }
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException("Unable to set value for field " + field.getName(), e);
    }
    return value;
}

From source file:net.jofm.format.NumberFormat.java

private Object convert(Number result, Class<?> destinationClazz) {
    if (destinationClazz.equals(BigDecimal.class)) {
        return new BigDecimal(result.doubleValue());
    }//from  w  ww  .j a  va2  s.  co m
    if (destinationClazz.equals(Short.class) || destinationClazz.equals(short.class)) {
        return new Short(result.shortValue());
    }
    if (destinationClazz.equals(Integer.class) || destinationClazz.equals(int.class)) {
        return new Integer(result.intValue());
    }
    if (destinationClazz.equals(Long.class) || destinationClazz.equals(long.class)) {
        return new Long(result.longValue());
    }
    if (destinationClazz.equals(Float.class) || destinationClazz.equals(float.class)) {
        return new Float(result.floatValue());
    }
    if (destinationClazz.equals(Double.class) || destinationClazz.equals(double.class)) {
        return new Double(result.doubleValue());
    }

    throw new FixedMappingException("Unable to parse the data to type " + destinationClazz.getName() + " using "
            + this.getClass().getName());
}

From source file:org.haiku.haikudepotserver.pkg.PkgServiceImpl.java

/**
 * <p>This method will provide a total of the package versions.</p>
 *///from  w ww.j  av a2s.c  o m

@Override
public long total(ObjectContext context, PkgSearchSpecification search) {

    SQLTemplate sqlTemplate = (SQLTemplate) context.getEntityResolver().getQueryDescriptor("SearchPkgVersions")
            .buildQuery();

    SQLTemplate query = (SQLTemplate) sqlTemplate.createQuery(ImmutableMap.of("search", search, "isTotal", true,
            "englishNaturalLanguage", NaturalLanguage.getEnglish(context)));
    query.setFetchingDataRows(true);

    DataRow dataRow = (DataRow) (context.performQuery(query)).get(0);
    Number newTotal = (Number) dataRow.get("total");

    return newTotal.longValue();
}

From source file:org.richfaces.component.UIProgressBar.java

/**
 * Converts value attr to number value/*  w w  w  .  java  2  s .c om*/
 * 
 * @param v -
 *            value attr
 * @return result
 */
public Number getNumber(Object v) {
    Number result = null;
    if (v != null) {
        try {
            if (v instanceof String) { // String
                result = Double.parseDouble((String) v);
            } else {
                Number n = (Number) v;
                if ((n instanceof BigDecimal) || (n instanceof Double) // Double
                // or
                // BigDecimal
                        || (n instanceof Float)) {
                    result = n.floatValue();
                } else if (n instanceof Integer || n instanceof Long) { // Integer
                    result = n.longValue();
                }
            }
        } catch (Exception e) {
            e.getMessage();
        }
        return result;
    }
    return new Integer(0);
}

From source file:org.camunda.spin.impl.json.jackson.JacksonJsonNode.java

public SpinJsonNode prop(String name, Number newProperty) {
    ObjectNode node = (ObjectNode) jsonNode;

    // Numbers magic because Jackson has no native .put(Number value)
    if (newProperty instanceof Long) {
        node.put(name, newProperty.longValue());
    } else if (newProperty instanceof Integer) {
        node.put(name, newProperty.intValue());
    } else if (newProperty instanceof Float) {
        node.put(name, newProperty.floatValue());
    } else {//from w  w  w  . ja  v  a2s  . c  o  m
        // convert any other sub class of Number into Float
        node.put(name, newProperty.floatValue());
    }

    return this;
}

From source file:edu.dlnu.liuwenpeng.Time.TimeSeriesCollection.java

/**    
* Returns the indices of the two data items surrounding a particular     
* millisecond value.      /*from  w  ww.  j a  v  a  2 s  . co  m*/
*     
* @param series  the series index.    
* @param milliseconds  the time.    
*     
* @return An array containing the (two) indices of the items surrounding     
*         the time.    
*/
public int[] getSurroundingItems(int series, long milliseconds) {
    int[] result = new int[] { -1, -1 };
    TimeSeries timeSeries = getSeries(series);
    for (int i = 0; i < timeSeries.getItemCount(); i++) {
        Number x = getX(series, i);
        long m = x.longValue();
        if (m <= milliseconds) {
            result[0] = i;
        }
        if (m >= milliseconds) {
            result[1] = i;
            break;
        }
    }
    return result;
}

From source file:it.drwolf.ridire.index.sketch.AsyncSketchCreator.java

private void processTrinaryTable(String freqTable, long firstFreq, StrTokenizer strTokenizer,
        List<String> lines, String lemma, IndexWriter indexWriter, String sketch, String functional,
        String semantic, String goodFor) throws CorruptIndexException, IOException {
    Map<String, Map<String, Number>> resTable = this.createResTable(lines, strTokenizer);
    HashMap<String, Map<String, SketchResult>> sr = new HashMap<String, Map<String, SketchResult>>();
    for (String pre : resTable.keySet()) {
        Map<String, Number> preTable = resTable.get(pre);
        Number fA = 0;
        for (Number pfA : preTable.values()) {
            fA = fA.longValue() + pfA.longValue();
        }//from w w  w.j ava  2s  . c om
        Map<String, SketchResult> preRes = sr.get(pre);
        if (preRes == null) {
            preRes = new HashMap<String, SketchResult>();
        }
        for (String target : preTable.keySet()) {
            List<Number> fBs = this.entityManager
                    .createNativeQuery("select freq from " + freqTable + " where item=:item")
                    .setParameter("item", target).getResultList();
            SketchResult res = preRes.get(target);
            if (res == null) {
                res = new SketchResult();
            }
            if (fBs != null && fBs.size() > 0) {
                long fB = fBs.get(0).longValue();
                if (fBs != null && fBs.size() > 0 && fB > 0) {
                    res.setCollocata(target);
                    long n = this.corpusSizeParams.getCorpusSize(freqTable.substring(5)).longValue();
                    long fAB = preTable.get(target).longValue();
                    double score = this.getSketchScore(CWBCollocatesExtractor.LOGDICE_SCORE, fA.longValue(), fB,
                            fAB, n);
                    res.setScore(score);
                    res.setfA(fA.longValue());
                    res.setfB(fB);
                    res.setfAB(fAB);
                    preRes.put(target, res);
                }
            } else {
                continue;
            }
        }
        sr.put(pre, preRes);
    }
    for (String pre : sr.keySet()) {
        this.addDocument(sr.get(pre), lemma, indexWriter, String.format(sketch, pre), "WORD_SKETCH", functional,
                semantic, goodFor);
    }
}

From source file:org.ms123.common.data.TriggerServiceImpl.java

private long getLong(Object l) {
    try {//w  ww . java2s .co  m
        if (l == null)
            return -1;
        if (l instanceof Date) {
            return ((Date) l).getTime();
        }
        Number n = (Number) l;
        return n.longValue();
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}