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.patientview.radar.dao.impl.UserDaoImpl.java

public User createUser(User user) {
    Map<String, Object> userMap = new HashMap<String, Object>();
    userMap.put(USER_USERNAME_FIELD_NAME, user.getUsername());
    userMap.put(USER_PASSWORD_FIELD_NAME, user.getPassword());
    userMap.put(USER_FIRST_NAME_FIELD_NAME, user.getFirstName());
    userMap.put(USER_LAST_NAME_FIELD_NAME, user.getLastName());
    userMap.put(USER_EMAIL_FIELD_NAME, user.getEmail());
    userMap.put(USER_DUMMY_PATIENT_FIELD_NAME, false);
    userMap.put(USER_ACCOUNT_LOCKED_FIELD_NAME, false);
    userMap.put(USER_IS_CLINICIAN_FIELD_NAME, false);

    Number id = userInsert.executeAndReturnKey(userMap);
    user.setId(id.longValue());
    return user;/*from   w w w .  j  a  va 2s .com*/

}

From source file:HexFormat.java

/**
 * Parse a hex number into a Number object. Hexadecimal numbers may be
 * indicated with a leading character designation of '0x'. If up to 1 byte
 * is parsed, returns a Byte. If more than 1 and up to 2 bytes are parsed,
 * return a Short. If more than 2 and up to 4 bytes are parsed, return an
 * Integer. If more than 4 and up to 8 bytes are parsed, return a Long.
 * /*from   w  w  w.  j  a v  a 2s  .  co m*/
 * @param text
 *            a hexadecimal number
 * @param parsePosition
 *            position to start parsing from
 * @return return an integer form of Number object if parse is successful;
 *         <CODE>null</CODE> otherwise
 * 
 * @since 1.0
 */
public Number parse(String text, ParsePosition parsePosition) {
    boolean skipWhitespace = true;
    int startIndex, nibbles;

    // remove whitespace
    StringCharacterIterator iter = new StringCharacterIterator(text, parsePosition.getIndex());
    for (char c = iter.current(); c != CharacterIterator.DONE; c = iter.next()) {
        if (skipWhitespace && Character.isWhitespace(c)) {
            // skip whitespace
            continue;
        }
        break;
    }

    // skip a leading hex designation of the characters '0x'
    if (text.regionMatches(iter.getIndex(), "0x", 0, 2)) {
        parsePosition.setIndex(iter.getIndex() + 2);
    } else {
        parsePosition.setIndex(iter.getIndex());
    }

    startIndex = parsePosition.getIndex();
    Number result = (Number) parseObject(text, parsePosition);

    if (result == null) {
        return (result);
    }

    nibbles = parsePosition.getIndex() - startIndex;
    if (nibbles <= 2) {
        result = new Byte(result.byteValue());
    } else if (nibbles <= 4) {
        result = new Short(result.shortValue());
    } else if (nibbles <= 8) {
        result = new Integer(result.intValue());
    } else if (nibbles <= 16) {
        result = new Long(result.longValue());
    }
    return (result);
}

From source file:LongRange.java

/**
 * <p>Constructs a new <code>LongRange</code> using the specified
 * number as both the minimum and maximum in this range.</p>
 *
 * @param number  the number to use for this range, must not
 *  be <code>null</code>/*from w w w .  jav a 2s  .  c  o  m*/
 * @throws IllegalArgumentException if the number is <code>null</code>
 */
public LongRange(Number number) {
    super();
    if (number == null) {
        throw new IllegalArgumentException("The number must not be null");
    }
    this.min = number.longValue();
    this.max = number.longValue();
    if (number instanceof Long) {
        this.minObject = (Long) number;
        this.maxObject = (Long) number;
    }
}

From source file:org.patientview.radar.dao.impl.UserDaoImpl.java

public Long createLockedPVUser(String username, String password, String firstName, String lastName,
        String email) throws Exception {

    Map<String, Object> userMap = new HashMap<String, Object>();
    userMap.put(USER_USERNAME_FIELD_NAME, username);
    userMap.put(USER_PASSWORD_FIELD_NAME, password);
    userMap.put(USER_FIRST_NAME_FIELD_NAME, firstName);
    userMap.put(USER_LAST_NAME_FIELD_NAME, lastName);
    userMap.put(USER_EMAIL_FIELD_NAME, email);
    userMap.put(USER_DUMMY_PATIENT_FIELD_NAME, false);
    userMap.put(USER_ACCOUNT_LOCKED_FIELD_NAME, true);
    userMap.put(USER_IS_CLINICIAN_FIELD_NAME, false);

    Number id = userInsert.executeAndReturnKey(userMap);

    createRoleInPatientView(id.longValue(), "patient");

    return id.longValue();
}

From source file:org.patientview.radar.dao.impl.UserDaoImpl.java

public void saveAdminUser(final AdminUser adminUser) throws Exception {
    // save details of the user into the radar tables
    Map<String, Object> adminUserMap = new HashMap<String, Object>() {
        {//from   www. j a  v  a 2  s  .c  o  m
            put(ADMIN_USER_ID_FIELD_NAME, adminUser.getId());
        }
    };

    // the only field in this table is id so only need to do new inserts
    if (!adminUser.hasValidId()) {
        Number id = adminUsersInsert.executeAndReturnKey(adminUserMap);
        adminUser.setId(id.longValue());
    }

    // save main user login into the shared rpv table
    saveUser(adminUser);
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

public static long toLong(Number number) {
    return number.longValue();
}

From source file:org.patientview.radar.dao.impl.UserDaoImpl.java

/**
 * Will save the base user properties to the shared table with RPV
 * @param user User/* w  ww.  jav  a2s  .c  om*/
 */
private void saveUser(User user) throws Exception {
    Map<String, Object> userMap = new HashMap<String, Object>();
    userMap.put(ID_FIELD_NAME, user.getUserId());
    userMap.put(USER_USERNAME_FIELD_NAME, user.getUsername());
    userMap.put(USER_PASSWORD_FIELD_NAME, user.getPassword());
    userMap.put(USER_EMAIL_FIELD_NAME, user.getEmail());
    userMap.put(USER_DUMMY_PATIENT_FIELD_NAME, false);
    userMap.put(USER_IS_CLINICIAN_FIELD_NAME, user.isClinician());

    if (user instanceof ProfessionalUser) {
        userMap.put(USER_FIRST_NAME_FIELD_NAME, ((ProfessionalUser) user).getForename());
        userMap.put(USER_LAST_NAME_FIELD_NAME, ((ProfessionalUser) user).getSurname());
    } else {
        userMap.put(USER_FIRST_NAME_FIELD_NAME, user.getFirstName());
        userMap.put(USER_LAST_NAME_FIELD_NAME, user.getLastName());
    }

    if (user.hasValidUserId()) {
        userMap.put(USER_UPDATED_FIELD_NAME, new Date());
        namedParameterJdbcTemplate.update(buildUpdateQuery(USER_TABLE_NAME, ID_FIELD_NAME, userMap), userMap);
    } else {
        userMap.put(USER_CREATED_FIELD_NAME, new Date());
        Number id = userInsert.executeAndReturnKey(userMap);
        user.setUserId(id.longValue());
    }

    // have to also create a record in the radar mapping table so we know what role it is
    if (user.hasValidId()) {
        saveUserMapping(user);
    }
}

From source file:de.undercouch.bson4jackson.BsonParser.java

@Override
public BigInteger getBigIntegerValue() throws IOException, JsonParseException {
    Number n = getNumberValue();
    if (n == null) {
        return null;
    }//from  w  w w .j av a  2 s.  co m
    if (n instanceof Byte || n instanceof Integer || n instanceof Long || n instanceof Short) {
        return BigInteger.valueOf(n.longValue());
    } else if (n instanceof Double || n instanceof Float) {
        return BigDecimal.valueOf(n.doubleValue()).toBigInteger();
    }
    return new BigInteger(n.toString());
}

From source file:de.undercouch.bson4jackson.BsonParser.java

@Override
public BigDecimal getDecimalValue() throws IOException, JsonParseException {
    Number n = getNumberValue();
    if (n == null) {
        return null;
    }//from w w w. j a va 2 s . c  o  m
    if (n instanceof Byte || n instanceof Integer || n instanceof Long || n instanceof Short) {
        return BigDecimal.valueOf(n.longValue());
    } else if (n instanceof Double || n instanceof Float) {
        return BigDecimal.valueOf(n.doubleValue());
    }
    return new BigDecimal(n.toString());
}

From source file:com.tresys.jalop.utils.jnltest.SubscriberImpl.java

/**
 * Helper utility to run through all records that have been transferred,
 * but not yet synced. For log & audit records, this will remove all
 * records that are not synced (even if they are completely downloaded).
 * For journal records, this finds the record after the most recently
 * synced record record, and deletes all the other unsynced records. For
 * example, if the journal records 1, 2, 3, and 4 have been downloaded, and
 * record number 2 is marked as 'synced', then this will remove record
 * number 4, and try to resume the transfer for record number 3.
 *
 * @throws IOException If there is an error reading existing files, or an
 *          error removing stale directories.
 * @throws org.json.simple.parser.ParseException
 * @throws ParseException If there is an error parsing status files.
 * @throws java.text.ParseException If there is an error parsing a
 *          directory name./*from www  . ja v  a  2s.  com*/
 */
final void prepareForSubscribe() throws IOException, ParseException, java.text.ParseException {

    final File[] outputRecordDirs = this.outputRoot.listFiles(SubscriberImpl.FILE_FILTER);
    long lastSerial = 0;
    if (outputRecordDirs.length >= 1) {
        Arrays.sort(outputRecordDirs);
        final List<File> sortedOutputRecords = java.util.Arrays.asList(outputRecordDirs);
        final File lastRecord = sortedOutputRecords.get(sortedOutputRecords.size() - 1);
        lastSerial = Long.valueOf(lastRecord.getName());
    }

    switch (this.recordType) {
    case Audit:
        this.jnlTest.setLatestAuditSID(lastSerial++);
        break;
    case Journal:
        this.jnlTest.setLatestJournalSID(lastSerial++);
        break;
    case Log:
        this.jnlTest.setLatestLogSID(lastSerial++);
        break;
    }

    this.lastSerialFromRemote = SubscribeRequest.EPOC;
    this.journalOffset = 0;
    final JSONParser p = new JSONParser();
    final File[] recordDirs = this.outputIpRoot.listFiles(SubscriberImpl.FILE_FILTER);

    if (this.lastConfirmedFile.length() > 0) {
        final JSONObject lastConfirmedJson = (JSONObject) p.parse(new FileReader(this.lastConfirmedFile));

        this.lastSerialFromRemote = (String) lastConfirmedJson.get(LAST_CONFIRMED_SID);
    }

    final Set<File> deleteDirs = new HashSet<File>();

    if (this.recordType == RecordType.Journal && recordDirs.length > 0) {
        // Checking the first record to see if it can be resumed, the rest will be deleted
        Arrays.sort(recordDirs);
        final List<File> sortedRecords = new ArrayList<File>(java.util.Arrays.asList(recordDirs));

        final File firstRecord = sortedRecords.remove(0);
        deleteDirs.addAll(sortedRecords);

        JSONObject status;
        try {
            status = (JSONObject) p.parse(new FileReader(new File(firstRecord, STATUS_FILENAME)));

            final Number progress = (Number) status.get(PAYLOAD_PROGRESS);
            if (!CONFIRMED.equals(status.get(DGST_CONF)) && progress != null) {
                // journal record can be resumed
                this.lastSerialFromRemote = (String) status.get(REMOTE_SID);
                this.journalOffset = progress.longValue();
                FileUtils.forceDelete(new File(firstRecord, APP_META_FILENAME));
                FileUtils.forceDelete(new File(firstRecord, SYS_META_FILENAME));
                status.remove(APP_META_PROGRESS);
                status.remove(SYS_META_PROGRESS);
                this.sid = SID_FORMATER.parse(firstRecord.getName()).longValue();
                this.journalInputStream = new FileInputStream(new File(firstRecord, PAYLOAD_FILENAME));
            } else {
                deleteDirs.add(firstRecord);
            }

        } catch (final FileNotFoundException e) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Deleting " + firstRecord + ", because it is missing the '" + STATUS_FILENAME
                        + "' file");
            }
            deleteDirs.add(firstRecord);
        } catch (final ParseException e) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(
                        "Deleting " + firstRecord + ", because failed to parse '" + STATUS_FILENAME + "' file");
            }
            deleteDirs.add(firstRecord);
        }

    } else {
        // Any confirmed record should have been moved so deleting all that are left
        deleteDirs.addAll(java.util.Arrays.asList(recordDirs));
    }

    for (final File f : deleteDirs) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Removing directory for unsynced record: " + f.getAbsolutePath());
        }
        FileUtils.forceDelete(f);
    }
}