Example usage for java.math BigInteger longValue

List of usage examples for java.math BigInteger longValue

Introduction

In this page you can find the example usage for java.math BigInteger longValue.

Prototype

public long longValue() 

Source Link

Document

Converts this BigInteger to a long .

Usage

From source file:fr.cph.stock.android.entity.EntityBuilder.java

@SuppressLint("SimpleDateFormat")
private String extractDate(JSONObject jsonDate, String pattern) throws JSONException {
    BigInteger time = new BigInteger(jsonDate.getString("time"));
    Date date = new Date();
    date.setTime(time.longValue());
    DateFormat formatter = new SimpleDateFormat(pattern);
    String formattedDate = formatter.format(date);
    return formattedDate;
}

From source file:com.netflix.imfutility.cpl._2013.Cpl2013ContextBuilderStrategy.java

private void processResource(BaseResourceType resource) {
    if (!(resource instanceof TrackFileResourceType)) {
        return;/*from  ww  w . ja  v  a 2 s .c om*/
    }
    TrackFileResourceType trackFileResource = (TrackFileResourceType) resource;

    BigInteger repeatCount = trackFileResource.getRepeatCount() != null ? trackFileResource.getRepeatCount()
            : BigInteger.ONE;

    for (long i = 0; i < repeatCount.longValue(); i++) {
        processResourceRepeat(trackFileResource, i);
    }
}

From source file:org.openhie.openempi.dao.hibernate.PersonLinkDaoHibernate.java

private void addPersonLinkInHibernate(Session session, String tableName, PersonLink personLink) {
    log.debug("Storing a person link.");
    String tableFullName = getTableFullName(tableName);

    boolean generateId = (personLink.getPersonLinkId() == null);
    StringBuilder sqlInsertPerson = new StringBuilder(
            "INSERT INTO public." + tableFullName + " (" + PERSON_LINK_ID_COLUMN_NAME + ", "
                    + LEFT_PERSON_ID_COLUMN_NAME + ", " + RIGHT_PERSON_ID_COLUMN_NAME + ", "
                    + (personLink.getBinaryVector() != null ? (BINARY_VECTOR_COLUMN_NAME + ", ") : "")
                    + (personLink.getContinousVector() != null ? (CONTINOUS_VECTOR_COLUMN_NAME + ", ") : "")
                    + WEIGHT_COLUMN_NAME + ", " + LINK_STATUS_COLUMN_NAME + ") VALUES ("
                    + (generateId ? ("nextval('" + tableFullName + SEQUENCE_NAME_POSTFIX + "')") : "?") + ",?,?"
                    + (personLink.getBinaryVector() != null ? ",?" : "")
                    + (personLink.getContinousVector() != null ? ",?" : "") + ",?,?)"
                    + (generateId ? (" RETURNING " + PERSON_LINK_ID_COLUMN_NAME) : "") + ";");

    Query query = session.createSQLQuery(sqlInsertPerson.toString());

    int position = 0;
    if (personLink.getPersonLinkId() != null) {
        query.setLong(position, personLink.getPersonLinkId());
        position++;/*w w w  .  jav a  2s . com*/
    }
    query.setLong(position, personLink.getLeftPersonId());
    position++;
    query.setLong(position, personLink.getRightPersonId());
    position++;
    if (personLink.getBinaryVector() != null) {
        query.setString(position, personLink.getBinaryVector());
        position++;
    }
    if (personLink.getContinousVector() != null) {
        query.setString(position, personLink.getContinousVector());
        position++;
    }
    query.setDouble(position, personLink.getWeight());
    position++;
    query.setInteger(position, personLink.getLinkState());

    if (generateId) {
        BigInteger bigInt = (BigInteger) query.uniqueResult();
        long id = bigInt.longValue();
        personLink.setPersonLinkId(id);
        log.debug("Finished saving the person link with id " + id);
    } else {
        query.executeUpdate();
        log.debug("Finished saving the person link with id " + personLink.getPersonLinkId());
    }
}

From source file:br.com.hslife.orcamento.repository.CartaoCreditoRepository.java

public boolean existsLinkages(CartaoCredito cartaoCredito) {
    boolean result = true;

    String sqlFatura = "select count(id) from faturacartao where idConta = " + cartaoCredito.getConta().getId()
            + " and statusFaturaCartao <> 'ABERTA'";
    String sqlLancamento = "select count(*) from lancamentoconta l inner join conta cc on cc.id = l.idConta inner join cartaocredito c on c.id = cc.idCartao where c.id = "
            + cartaoCredito.getId();/*  www.j ava 2 s.c  om*/
    String sqlContaCompartilhada = "select count(*) from contacompartilhada cc inner join conta c on c.id = cc.idConta where c.id = "
            + cartaoCredito.getConta().getId();

    Query queryFatura = getSession().createSQLQuery(sqlFatura);
    Query queryLancamento = getSession().createSQLQuery(sqlLancamento);
    Query queryContaCompartilhada = getSession().createSQLQuery(sqlContaCompartilhada);

    BigInteger queryResultFatura = (BigInteger) queryFatura.uniqueResult();
    BigInteger queryResultLancamento = (BigInteger) queryLancamento.uniqueResult();
    BigInteger queryResultContaCompartilhada = (BigInteger) queryContaCompartilhada.uniqueResult();

    if (queryResultFatura.longValue() == 0 && queryResultLancamento.longValue() == 0
            && queryResultContaCompartilhada.longValue() == 0) {
        return false;
    }

    return result;
}

From source file:org.polymap.core.runtime.recordstore.lucene.NumericValueCoder.java

public boolean encode(Document doc, String key, Object value, boolean indexed, boolean stored) {
    if (value instanceof Number) {
        NumericField field = (NumericField) doc.getFieldable(key);
        if (field == null) {
            field = new NumericField(key, stored ? Store.YES : Store.NO, indexed);
            doc.add(field);//from w w w.  ja  va2s.  c om
        }
        if (value instanceof Integer) {
            field.setIntValue((Integer) value);
        } else if (value instanceof Long) {
            field.setLongValue((Long) value);
        } else if (value instanceof Float) {
            field.setFloatValue((Float) value);
        } else if (value instanceof Double) {
            field.setDoubleValue((Double) value);
        } else if (value instanceof BigInteger) {
            BigInteger bint = (BigInteger) value;
            if (bint.bitLength() < 32) {
                field.setIntValue(bint.intValue());
            } else if (bint.bitLength() < 64) {
                field.setLongValue(bint.longValue());
            } else {
                throw new RuntimeException("Too much bits in BigInteger: " + bint.bitLength());
            }
        } else if (value instanceof BigDecimal) {
            BigDecimal bdeci = (BigDecimal) value;
            // FIXME check double overflow
            field.setDoubleValue(bdeci.doubleValue());
        } else {
            throw new RuntimeException("Unknown Number type: " + value.getClass());
        }
        //log.debug( "encode(): " + field );
        return true;
    } else {
        return false;
    }
}

From source file:fr.gael.dhus.database.dao.ProductDao.java

/**
 * TODO: manage access by page./* w ww . j  a v  a 2s  .com*/
 * @param user
 * @return
 */
public List<Product> getNoCollectionProducts(User user) {
    ArrayList<Product> products = new ArrayList<>();
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append("SELECT p.ID ");
    sqlBuilder.append("FROM PRODUCTS p ");
    sqlBuilder.append("LEFT OUTER JOIN COLLECTION_PRODUCT cp ").append("ON p.ID = cp.PRODUCTS_ID ");
    sqlBuilder.append("WHERE cp.COLLECTIONS_ID IS NULL");
    final String sql = sqlBuilder.toString();
    List<BigInteger> queryResult = getHibernateTemplate().execute(new HibernateCallback<List<BigInteger>>() {
        @Override
        @SuppressWarnings("unchecked")
        public List<BigInteger> doInHibernate(Session session) throws HibernateException, SQLException {
            SQLQuery query = session.createSQLQuery(sql);
            return query.list();
        }
    });

    for (BigInteger pid : queryResult) {
        Product p = read(pid.longValue());
        if (p == null) {
            throw new IllegalStateException("Existing product is null ! product id = " + pid.longValue());
        }
        products.add(p);
    }

    return products;
}

From source file:gov.nih.nci.caarray.security.SecurityUtils.java

private static Map<Long, Privileges> createPrivilegesMapFromResults(List<Object[]> results) {
    final Map<Long, Privileges> permissionsMap = new HashMap<Long, Privileges>();
    BigInteger currId = null;
    Privileges perm = null;/*w ww.  ja  va  2  s.  co m*/
    for (final Object[] result : results) {
        final BigInteger id = (BigInteger) result[0];
        final String privilegeName = (String) result[1];
        if (!id.equals(currId)) {
            currId = id;
            perm = new Privileges();
            permissionsMap.put(currId.longValue(), perm);
        }
        perm.getPrivilegeNames().add(privilegeName);
    }

    return permissionsMap;
}

From source file:org.opensingular.form.type.core.STypeLong.java

@Override
protected Long convertNotNativeNotString(Object valor) {
    if (valor instanceof Number) {
        BigInteger bigIntegerValue = new BigInteger(String.valueOf(valor));
        if (bigIntegerValue.compareTo(new BigInteger(String.valueOf(Long.MAX_VALUE))) > 0) {
            throw createConversionError(valor, Long.class, " Valor muito grande.", null);
        }/*from  w w  w. java2  s .c  om*/
        if (bigIntegerValue.compareTo(new BigInteger(String.valueOf(Long.MIN_VALUE))) < 0) {
            throw createConversionError(valor, Long.class, " Valor muito pequeno.", null);
        }
        return bigIntegerValue.longValue();
    }
    throw createConversionError(valor);
}

From source file:burstcoin.jminer.core.round.Round.java

/**
 * Handle message./*from   w  ww . j  a  v a  2  s .c  o m*/
 *
 * @param event the event
 */
@EventListener
public void handleMessage(CheckerResultEvent event) {
    if (blockNumber == event.getBlockNumber()) {
        // check new lowest result
        if (event.getResult() != null) {
            long nonce = event.getNonce();
            BigInteger deadline = event.getResult().divide(BigInteger.valueOf(baseTarget));
            long calculatedDeadline = deadline.longValue();

            if (devPool) {
                if (calculatedDeadline < targetDeadline) {
                    // remember for next triggered commit
                    devPoolResults.add(new DevPoolResult(event.getBlockNumber(), calculatedDeadline,
                            event.getNonce(), event.getChunkPartStartNonce()));
                } else {
                    // todo there will be a lot of skipped, makes no sense, cause lowest not used here, remove or make adjustable by setting.
                    //            publisher.publishEvent(new RoundSingleResultSkippedEvent(this, event.getBlockNumber(), nonce, event.getChunkPartStartNonce(), calculatedDeadline,
                    //                                                                     targetDeadline, poolMining));
                    runningChunkPartStartNonces.remove(event.getChunkPartStartNonce());
                    triggerFinishRoundEvent(event.getBlockNumber());
                }
            } else {
                if (event.getResult().compareTo(lowest) < 0) {
                    lowest = event.getResult();
                    if (calculatedDeadline < targetDeadline) {
                        network.commitResult(blockNumber, calculatedDeadline, nonce,
                                event.getChunkPartStartNonce(), plots.getSize());

                        // ui event
                        fireEvent(new RoundSingleResultEvent(this, event.getBlockNumber(), nonce,
                                event.getChunkPartStartNonce(), calculatedDeadline, poolMining));
                    } else {
                        // ui event
                        fireEvent(new RoundSingleResultSkippedEvent(this, event.getBlockNumber(), nonce,
                                event.getChunkPartStartNonce(), calculatedDeadline, targetDeadline,
                                poolMining));
                        // chunkPartStartNonce finished
                        runningChunkPartStartNonces.remove(event.getChunkPartStartNonce());
                        triggerFinishRoundEvent(event.getBlockNumber());
                    }
                } else {
                    // chunkPartStartNonce finished
                    runningChunkPartStartNonces.remove(event.getChunkPartStartNonce());
                    triggerFinishRoundEvent(event.getBlockNumber());
                }
            }
        } else {
            LOG.error("CheckerResultEvent result == null");
        }
    } else {
        LOG.trace("event for previous block ...");
    }
}

From source file:chibi.gemmaanalysis.SummaryStatistics.java

/**
 * For each gene, count how many expression experiments it appears in.
 * //from  ww w .j a  v a2s .com
 * @param taxon
 */
public void geneOccurrenceDistributions(Taxon taxon) {

    Map<Long, Integer> counts = new HashMap<Long, Integer>();

    // get all expression experiments

    Collection<ExpressionExperiment> eeColl = expressionExperimentService.loadAll();

    int i = 0;
    for (ExpressionExperiment experiment : eeColl) {
        if (i > MAX_EXPS)
            break;
        Taxon eeTax = expressionExperimentService.getTaxon(experiment);
        if (eeTax == null || !eeTax.equals(taxon))
            continue;
        Collection<ArrayDesign> ads = expressionExperimentService.getArrayDesignsUsed(experiment);

        // only count each gene once per data set.
        Collection<Long> seenids = new HashSet<Long>();

        for (ArrayDesign design : ads) {
            log.info(i + " " + design);
            Collection<Object[]> vals = compositeSequenceService.getRawSummary(design, null);
            log.info("Got " + vals.size() + " reports");
            for (Object[] objects : vals) {

                BigInteger geneidi = (BigInteger) objects[10];
                if (geneidi == null) {
                    continue;
                }
                Long geneid = geneidi.longValue();

                if (seenids.contains(geneid))
                    continue;

                if (counts.get(geneid) == null) {
                    counts.put(geneid, 0);
                }
                counts.put(geneid, counts.get(geneid) + 1);
                seenids.add(geneid);
            }
        }
        i++;
    }

    for (Long l : counts.keySet()) {
        System.out.println(l + "\t" + counts.get(l));
    }
}