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.red5.io.AbstractIOTest.java

public void testNumberLong() {
    log.debug("\ntestNumberLong");
    for (Number n : new Number[] { Long.MIN_VALUE, rnd.nextLong(), -666L, 0L, 666L, Long.MAX_VALUE }) {
        Serializer.serialize(out, n);/* www.  j  a  v  a  2 s . c  o m*/
        dumpOutput();
        Number rn = Deserializer.deserialize(in, Number.class);
        assertEquals("Deserialized Long should be the same", n, rn.longValue());
        resetOutput();
    }
}

From source file:org.patientview.radar.util.impl.RadarRpvSingleUserTableExport.java

public void run() {
    /**/*from ww  w. j  a v a2s  .  c om*/
     * first we need to grab all the unitadmins from patient view as we want to create logins for these in radar
     * but dont save them yet as we dont want to then move all the radar logins over to patient view and do it all
     * twice
     *
     * grab unit admins from patient view
     *
     * then move all users from radar over to PV
     *
     * then use the unit admins we got at start and move them into radar
     *
     * SIMPLES!
     */
    List<ProfessionalUser> patientViewUnitAdmins = jdbcTemplate.query(
            "SELECT " + "   u.*, " + "   un.id AS centreId " + " FROM " + "   USER u, "
                    + "   specialtyuserrole sur, " + "   usermapping um, " + "   unit un " + " WHERE "
                    + "   sur.user_id = u.id " + " AND " + "   sur.role = 'unitstaff' " + " AND "
                    + "   um.username = u.username " + " AND " + "   un.unitcode = um.unitcode ",
            new PatientViewUnitAdminRowMapper());

    // move pv users to radar
    for (ProfessionalUser professionalUser : patientViewUnitAdmins) {
        // check this user isnt in radar already as it will already have been mapped above
        if (!checkForProfessionalUser(professionalUser.getEmail())) {
            try {
                Map<String, Object> professionalUserMap = new HashMap<String, Object>();
                professionalUserMap.put(PROFESSIONAL_USER_SURNAME_FIELD_NAME, professionalUser.getSurname());
                professionalUserMap.put(PROFESSIONAL_USER_FORENAME_FIELD_NAME, professionalUser.getForename());
                professionalUserMap.put(PROFESSIONAL_USER_TITLE_FIELD_NAME, professionalUser.getTitle());
                professionalUserMap.put(PROFESSIONAL_USER_GMC_FIELD_NAME, professionalUser.getGmc());
                professionalUserMap.put(PROFESSIONAL_USER_CENTRE_ROLE_FIELD_NAME, professionalUser.getRole());
                professionalUserMap.put(PROFESSIONAL_USER_PHONE_FIELD_NAME, professionalUser.getPhone());
                professionalUserMap.put(PROFESSIONAL_USER_CENTRE_ID_FIELD_NAME,
                        professionalUser.getCentre().getId());
                professionalUserMap.put(PROFESSIONAL_USER_DATE_JOINED_FIELD_NAME,
                        professionalUser.getDateRegistered());

                Number id = professionalUsersInsert.executeAndReturnKey(professionalUserMap);
                professionalUser.setId(id.longValue());

                userDao.saveUserMapping(professionalUser);
                LOGGER.info("updated unitstaff: " + professionalUser.getUsername());
            } catch (Exception e) {
                failedUsers.add("PV unitadmin failed: " + professionalUser.getId() + " - "
                        + professionalUser.getEmail());
            }
        }
    }

    for (String s : failedUsers) {
        LOGGER.error(s);
    }
}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Coerces a Number to the given primitive number class
 *//*from   w w  w  . j a  v  a 2s  .co m*/
static Number coerceToPrimitiveNumber(Number pValue, Class pClass) throws ElException {
    if (pClass == Byte.class || pClass == Byte.TYPE) {
        return PrimitiveObjects.getByte(pValue.byteValue());
    } else if (pClass == Short.class || pClass == Short.TYPE) {
        return PrimitiveObjects.getShort(pValue.shortValue());
    } else if (pClass == Integer.class || pClass == Integer.TYPE) {
        return PrimitiveObjects.getInteger(pValue.intValue());
    } else if (pClass == Long.class || pClass == Long.TYPE) {
        return PrimitiveObjects.getLong(pValue.longValue());
    } else if (pClass == Float.class || pClass == Float.TYPE) {
        return PrimitiveObjects.getFloat(pValue.floatValue());
    } else if (pClass == Double.class || pClass == Double.TYPE) {
        return PrimitiveObjects.getDouble(pValue.doubleValue());
    } else if (pClass == BigInteger.class) {
        if (pValue instanceof BigDecimal)
            return ((BigDecimal) pValue).toBigInteger();
        else
            return BigInteger.valueOf(pValue.longValue());
    } else if (pClass == BigDecimal.class) {
        if (pValue instanceof BigInteger)
            return new BigDecimal((BigInteger) pValue);
        else
            return new BigDecimal(pValue.doubleValue());
    } else {
        return PrimitiveObjects.getInteger(0);
    }
}

From source file:org.eclipse.wb.internal.xwt.model.property.editor.style.StylePropertyEditor.java

/**
 * @return the current style value./*from w w w . ja  va 2  s.c  o  m*/
 */
long getStyle(Property property) throws Exception {
    Number value = (Number) property.getValue();
    return value != null ? value.longValue() : 0;
}

From source file:com.hortonworks.streamline.streams.metrics.storm.topology.StormTopologyMetricsImpl.java

private Long getLongValueOrDefault(Map<String, ?> map, String key, Long defaultValue) {
    if (map.containsKey(key)) {
        Number number = (Number) map.get(key);
        if (number != null) {
            return number.longValue();
        }/*from   w w  w .ja v  a2s.c  om*/
    }
    return defaultValue;
}

From source file:edu.kit.dama.staging.util.DataOrganizationUtils.java

/**
 * Return the number of files which are part of the data organization of the
 * digital object with the provided id. Only the FileNodes in the view
 * 'default' are counted.// ww w. j  a v  a  2  s  . c  om
 *
 * @param pObjectId The id of the object to query for.
 *
 * @return The number of FileNodes associated with pObjectId or 0 if no
 * amount could be obtained.
 */
public static Long getAssociatedFileCount(DigitalObjectId pObjectId) {
    IMetaDataManager doMdm = MetaDataManagement.getMetaDataManagement()
            .getMetaDataManager(PersistenceFacade.getInstance().getPersistenceUnitName());
    doMdm.setAuthorizationContext(AuthorizationContext.factorySystemContext());
    try {
        Number result = (Number) doMdm
                .findSingleResult("SELECT COUNT(a) FROM DataOrganizationNode a WHERE a.digitalObjectIDStr='"
                        + pObjectId.getStringRepresentation() + "' AND a.viewName='" + Constants.DEFAULT_VIEW
                        + "' AND TYPE(a)=FileNode");
        return (result != null) ? result.longValue() : 0l;
    } catch (UnauthorizedAccessAttemptException ex) {
        return 0l;
    } finally {
        doMdm.close();
    }
}

From source file:org.mifos.customers.office.persistence.OfficeDaoHibernate.java

@Override
public void validateNoOfficesExistGivenOfficeLevel(OfficeLevel officeLevel) {
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("LEVEL_ID", officeLevel.getValue());
    Number count = (Number) this.genericDao.executeUniqueResultNamedQuery("office.getOfficeCountForLevel",
            queryParameters);/*  ww w  .ja va  2s.c o m*/
    if (count != null && count.longValue() > 0) {
        throw new BusinessRuleException(OfficeConstants.KEYHASACTIVEOFFICEWITHLEVEL);
    }
}

From source file:org.sonar.server.issue.index.IssueDoc.java

@Override
@CheckForNull/*from ww w  .j  a v a  2 s  .  co  m*/
public Duration effort() {
    Number effort = getNullableField(IssueIndexDefinition.FIELD_ISSUE_EFFORT);
    return (effort != null) ? Duration.create(effort.longValue()) : null;
}

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

@Override
public long countUngradedSubmittedSubmissionsForAssignment(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("graded", Boolean.TRUE))
            .uniqueResult();//from   www .  java  2  s .c o  m
    return number.longValue();
}

From source file:cloudnet.weather.data.forecastio.FormatConverter.java

private void aggregateData(String inputDir) {
    LOGGER.info("read weather data...");

    File path = new File(inputDir);
    JSONParser parser = new JSONParser();

    for (File cityDir : path.listFiles()) {

        // If not a dir; next file in data path
        if (!cityDir.isDirectory()) {
            continue;
        }/* w  w  w  .  j a  v  a 2s  .c o  m*/

        LOGGER.trace(String.format("Processing %s...", cityDir.getAbsolutePath()));

        String[] extensions = { "json" };

        List<File> fileList = new ArrayList<>(FileUtils.listFiles(cityDir, extensions, false));

        for (File file : fileList) {

            try {
                try (Reader reader = new BufferedReader(new FileReader(file))) {
                    JSONObject jsonObject = (JSONObject) parser.parse(reader);

                    String timezone = (String) jsonObject.get("timezone");
                    locationTimeZone.put(cityDir.getName(), timezone);

                    Number currentTemp = (Number) ((JSONObject) jsonObject.get("currently")).get("temperature");
                    Number currentTime = (Number) ((JSONObject) jsonObject.get("currently")).get("time");

                    JSONObject hourlyForecast = (JSONObject) jsonObject.get("hourly");
                    JSONArray data = (JSONArray) hourlyForecast.get("data");

                    if (currentTemp != null) {
                        addWeatherdata(currentTime.longValue(), cityDir.getName(), currentTemp.doubleValue());
                    }

                    for (Object o : data) {
                        JSONObject oo = (JSONObject) o;

                        Number time = (Number) oo.get("time");
                        Number temp = (Number) oo.get("temperature");

                        long timeDiff = time.longValue() - currentTime.longValue();

                        if (temp != null) {
                            addWeatherdata(currentTime.longValue() + timeDiff, cityDir.getName(),
                                    temp.doubleValue());
                        }
                    }
                }

            } catch (IOException | ParseException e) {
                LOGGER.error("aggregateData", e);
            }
        }
    }
}