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:br.com.hslife.orcamento.repository.ContaRepository.java

public boolean existsLinkages(Conta conta) {
    boolean result = false;

    BigInteger resultFechamentoPeriodo = (BigInteger) getSession().createSQLQuery(
            "select count(id) from fechamentoperiodo where operacao = 'FECHAMENTO' and idContaBancaria = "
                    + conta.getId())/* ww  w  . j  a va  2 s  .co m*/
            .uniqueResult();
    BigInteger resultLancamento = (BigInteger) getSession()
            .createSQLQuery("select count(id) from lancamentoconta where idConta = " + conta.getId())
            .uniqueResult();

    if (resultFechamentoPeriodo.longValue() != 0) {
        return true;
    }

    if (resultLancamento.longValue() != 0) {
        return true;
    }

    return result;

}

From source file:com.abiquo.server.core.cloud.VirtualDatacenterDAO.java

public DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int virtualDatacenterId) {
    Object[] vmResources = (Object[]) getSession().createSQLQuery(SUM_VM_RESOURCES)
            .setParameter("virtualDatacenterId", virtualDatacenterId).uniqueResult();

    Long cpu = vmResources[0] == null ? 0 : ((BigDecimal) vmResources[0]).longValue();
    Long ram = vmResources[1] == null ? 0 : ((BigDecimal) vmResources[1]).longValue();
    Long hd = vmResources[2] == null ? 0 : ((BigDecimal) vmResources[2]).longValue();

    BigDecimal extraHd = (BigDecimal) getSession().createSQLQuery(SUM_EXTRA_HD_RESOURCES)
            .setParameter("virtualDatacenterId", virtualDatacenterId).uniqueResult();
    Long hdTot = extraHd == null ? hd : hd + extraHd.longValue() * 1024 * 1024;

    BigDecimal storage = (BigDecimal) getSession().createSQLQuery(SUM_VOLUMES_RESOURCES)
            .setParameter("virtualDatacenterId", virtualDatacenterId).uniqueResult();

    BigInteger publicIps = (BigInteger) getSession().createSQLQuery(COUNT_PUBLIC_IP_RESOURCES)
            .setParameter("virtualDatacenterId", virtualDatacenterId).uniqueResult();

    DefaultEntityCurrentUsed used = new DefaultEntityCurrentUsed(cpu.intValue(), ram, hdTot);

    // Storage usage is stored in MB
    used.setStorage(storage == null ? 0 : storage.longValue() * 1024 * 1024);
    used.setPublicIp(publicIps == null ? 0 : publicIps.longValue());
    used.setVlanCount(getVLANUsage(virtualDatacenterId).size());

    return used;/*from  ww w.j a  v a 2 s .  co m*/
}

From source file:org.esupportail.portlet.filemanager.services.opencmis.CmisAccessImpl.java

/**
 * @param cmisObject//  w  ww. ja va  2s  .c  o m
 * @param path
 * @param parentPath
 * @return a JsTreeFile where lid = /cmis_parent_parent_object_idJsTreeFile.ID_TITLE_SPLITcmis_parent_parent_object_name/cmis_parent_object_idJsTreeFile.ID_TITLE_SPLITcmis_parent_object_name/cmis_object_idJsTreeFile.ID_TITLE_SPLITcmis_object_name
 */
private JsTreeFile cmisObjectAsJsTreeFile(CmisObject cmisObject, String path, String parentPath,
        boolean folderDetails, boolean fileDetails) {
    // TODO: folderDetails
    // TODO: fileDetails
    String title = cmisObject.getName();
    String lid = cmisObject.getId().concat(JsTreeFile.ID_TITLE_SPLIT).concat(title);
    if (path != null) {
        lid = path;
    } else if (parentPath != null) {
        lid = parentPath.concat("/").concat(lid);
    }
    // remove / at the beginning if it exists
    if (lid.startsWith("/"))
        lid = lid.substring(1);

    String type = (BaseTypeId.CMIS_DOCUMENT.equals(cmisObject.getBaseTypeId())) ? "file" : "folder";

    // root case :
    if ("".equals(path)) {
        title = "";
        type = "drive";
    }

    JsTreeFile file = new JsTreeFile(title, lid, type);
    if (fileDetails) {

        if ("file".equals(type)) {
            String icon = resourceUtils.getIcon(title);
            file.setIcon(icon);

            Document document = (Document) cmisObject;
            BigInteger size = BigInteger.ZERO;
            List<Object> contentStreamLength = document.getProperty("cmis:contentStreamLength").getValues();
            if (!contentStreamLength.isEmpty())
                size = (BigInteger) contentStreamLength.get(0);
            file.setSize(size.longValue());
            file.setOverSizeLimit(file.getSize() > resourceUtils.getSizeLimit(title));
        }

        Date date = cmisObject.getLastModificationDate().getTime();
        file.setLastModifiedTime(new SimpleDateFormat(this.datePattern).format(date));

    }

    if (folderDetails && ("folder".equals(type) || "drive".equals(type))) {
        Folder folder = (Folder) cmisObject;
        ItemIterable<CmisObject> pl = folder.getChildren();
        long totalSize = 0;
        long fileCount = 0;
        long folderCount = 0;
        fileCount = pl.getTotalNumItems();

        for (CmisObject child : pl) {
            String childType = (BaseTypeId.CMIS_DOCUMENT.equals(child.getBaseTypeId())) ? "file" : "folder";
            if ("folder".equals(childType)) {
                ++folderCount;
            } else if ("file".equals(childType)) {
                ++fileCount;
                Document document = (Document) child;
                BigInteger size = BigInteger.ZERO;
                List<Object> contentStreamLength = document.getProperty("cmis:contentStreamLength").getValues();
                if (!contentStreamLength.isEmpty())
                    size = (BigInteger) contentStreamLength.get(0);
                totalSize += size.longValue();
            }
        }
        file.setTotalSize(totalSize);
        file.setFileCount(fileCount);
        file.setFolderCount(folderCount);
    }

    Set<Action> actions = cmisObject.getAllowableActions().getAllowableActions();
    // check if actions seem to be filled correctly
    if (actions.contains(Action.CAN_GET_PROPERTIES)) {
        // ok, set capability based on available actions
        file.setWriteable(actions.contains(Action.CAN_DELETE_OBJECT));
    }

    return file;
}

From source file:org.gridobservatory.greencomputing.dao.TimeseriesDao.java

protected void insertTimeSeriesAcquisitions(final BigInteger timeSeriesId,
        final List<TimeseriesAcquisitionType> acquisitions) {
    executor.submit(new Runnable() {
        @Override/*from  w  w  w  .  java 2  s  .c  o m*/
        public void run() {
            if (acquisitions != null) {
                getJdbcTemplate().batchUpdate(
                        "insert into time_series_acquisition (time_series_id, ts, value) values (?,?,?)",
                        new BatchPreparedStatementSetter() {

                            @Override
                            public void setValues(PreparedStatement ps, int i) throws SQLException {
                                ps.setLong(1, timeSeriesId.longValue());
                                long dateInMilis = acquisitions.get(i).getTs()
                                        .multiply(BigInteger.valueOf(1000l)).longValue();
                                ps.setTimestamp(2, new Timestamp(dateInMilis));
                                ps.setBigDecimal(3, new BigDecimal(acquisitions.get(i).getV()));
                            }

                            @Override
                            public int getBatchSize() {
                                return acquisitions.size();
                            }
                        });
            }
        }
    });
}

From source file:org.openvpms.component.system.common.jxpath.OpenVPMSTypeConverter.java

/**
 * Convert a {@link BigInteger} to another type
 * /*ww w.  j  av  a2 s.c om*/
 * @param type
 *            the class to convert too
 * @param value
 *            the value to convert
 * @return Number
 *            the converted number of null.
 *            
 */
protected Number allocateNumber(Class type, BigInteger value) {
    if (type == Byte.class || type == byte.class) {
        return new Byte(value.byteValue());
    }
    if (type == Short.class || type == short.class) {
        return new Short(value.shortValue());
    }
    if (type == Integer.class || type == int.class) {
        return new Integer(value.intValue());
    }
    if (type == Long.class || type == long.class) {
        return new Long(value.longValue());
    }
    if (type == Float.class || type == float.class) {
        return new Float(value.floatValue());
    }
    if (type == Double.class || type == double.class) {
        return new Double(value.doubleValue());
    }
    if (type == BigDecimal.class) {
        return new BigDecimal(value);
    }
    if (type == BigInteger.class) {
        return value;
    }

    return null;
}

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

private void addPersonInHibernate(Session session, String tableName, Person person) {
    log.debug("Saving person record: " + person);
    String tableFullName = getTableFullName(tableName);
    StringBuilder sqlInsertPerson = new StringBuilder("INSERT INTO public." + tableFullName + " (" +
    // adding the Id - it is auto generated
            PERSON_ID_COLUMN_NAME);/*from   ww  w  .java 2  s.c  om*/
    // adding the custom fields
    Map<String, Object> attributes = person.getAttributes();
    for (Map.Entry<String, Object> pairs : attributes.entrySet()) {
        ValidationUtil.sanityCheckFieldName(pairs.getKey());
        if (pairs.getValue() != null)
            sqlInsertPerson.append(", " + COLUMN_NAME_PREFIX + pairs.getKey().toLowerCase());
    }
    boolean generateId = (person.getPersonId() == null);
    sqlInsertPerson.append(
            ") VALUES (" + (generateId ? ("nextval('" + tableFullName + SEQUENCE_NAME_POSTFIX + "')") : "?"));
    for (Map.Entry<String, Object> pairs : attributes.entrySet()) {
        if (pairs.getValue() != null)
            sqlInsertPerson.append(",?");
    }
    sqlInsertPerson.append(")" + (generateId ? (" RETURNING " + PERSON_ID_COLUMN_NAME) : "") + ";");

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

    int position = 0;
    if (!generateId) {
        query.setLong(position, person.getPersonId());
        position++;
    }
    for (Map.Entry<String, Object> pairs : attributes.entrySet()) {
        if (pairs.getValue() != null) {
            query.setParameter(position, pairs.getValue());
            position++;
        }
    }

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

From source file:org.esa.cci.sst.tool.Configuration.java

private long parsePattern(String key, String value) {
    final long pattern;
    try {/*from   w w w . j  av a 2s . c om*/
        final BigInteger bigInteger = new BigInteger(value, 16);
        if (bigInteger.bitLength() > 64) {
            throw new ToolException("Too many bits in pattern: " + key, ToolException.TOOL_CONFIGURATION_ERROR);
        }
        if (bigInteger.bitCount() > 1) {
            throw new ToolException("Too many bits set in pattern: " + key,
                    ToolException.TOOL_CONFIGURATION_ERROR);
        }
        pattern = bigInteger.longValue();
    } catch (NumberFormatException e) {
        throw new ToolException("Cannot parse pattern: " + key, e, ToolException.TOOL_CONFIGURATION_ERROR);
    }
    return pattern;
}

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

private long getTotalNumberOfRecordsInHibernate(Session session, String tableName) {
    StringBuilder sqlSelect = new StringBuilder(
            "SELECT COUNT(*) FROM public." + getTableFullName(tableName) + ";");
    java.math.BigInteger bigInt = (java.math.BigInteger) session.createSQLQuery(sqlSelect.toString())
            .uniqueResult();//from ww  w.j  av  a2  s.com
    long totalNum = bigInt.longValue();
    return totalNum;
}

From source file:com.google.uzaygezen.core.LongBitVector.java

@Override
public void copyFrom(BigInteger s) {
    Preconditions.checkArgument(s.signum() >= 0, s);
    Preconditions.checkArgument(s.bitLength() <= size());
    // Note that the long value will be negative iff bitLength == 644 and bit 63
    // is set.//  w ww  . ja va2 s  . c om
    copyFrom(s.longValue());
}

From source file:org.o3project.optsdn.don.NetworkInformation.java

/**
 * Get informations from IDEx file(idex.txt).
 * - DP ID//from w  w  w  .  ja  v a 2 s .c  o  m
 * - OF Port
 * 
 * @param filepath The IDEx file path
 * @throws Exception File Read Failed
 */
private void parseIdExFile(String filepath) throws Exception {
    String idexJson = readIdexAsJson(filepath);

    ObjectMapper mapper = new ObjectMapper();
    @SuppressWarnings("unchecked")
    Map<String, Map<String, String>> value = mapper.readValue(idexJson, Map.class);

    Set<Entry<String, Map<String, String>>> entrySet = value.entrySet();
    dpidMap = new HashMap<String, Long>();
    Map<String, Integer> ofPortMap = new HashMap<String, Integer>();
    for (Entry<String, Map<String, String>> entry : entrySet) {
        Map<String, String> params = entry.getValue();
        BigInteger bigintDpid = new BigInteger(params.get(DPID));
        if (bigintDpid.compareTo(BigInteger.valueOf(0)) < 0
                || bigintDpid.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
            throw new Exception("DP ID is out of boundary. (DP ID valid between 0 and 2^63-1)");
        }
        long dpid = bigintDpid.longValue();

        String informationModelId = entry.getKey();
        Port port = new Port(informationModelId);
        String neId = port.getNeId();

        Long existDpid = dpidMap.get(neId);
        if (existDpid == null) {
            dpidMap.put(neId, dpid);
        } else if (!existDpid.equals(dpid)) {
            logger.warn("Fail to add DP ID[" + dpid + "]. " + "The DP ID of NE[" + neId + "] is already set"
                    + "(exist DP ID[" + existDpid + "]).");
        }

        int ofPortId = Integer.valueOf(params.get(PORT));
        Integer existOfPortId = ofPortMap.get(informationModelId);
        if (existOfPortId != null) {
            if (!existOfPortId.equals(ofPortId)) {
                logger.warn("Fail to add OpenFlow Port ID[" + ofPortId + "]. " + "The OpenFlow Port ID of Port["
                        + informationModelId + "] is already set" + "(exist OpenFlow Port ID[" + existOfPortId
                        + "]).");
            }
        } else {
            if (ofPortId < 0 && ofPortId > Integer.MAX_VALUE) {
                throw new Exception("OpenFlow Port ID is out of boundary. "
                        + "(OpenFlow Port ID valid between 0 and 2^31-1)");
            }

            ofPortMap.put(informationModelId, ofPortId);
        }
    }

    for (Port port : portSet) {
        Integer openFlowPortId = ofPortMap.get(port.getInformationModelId());
        if (openFlowPortId == null) {
            continue;
        }
        port.setOpenFlowPortId(openFlowPortId);
    }

    for (List<List<Port>> linkList : omsConnectionInfoListMap.values()) {
        for (List<Port> link : linkList) {
            Port port1 = link.get(0);
            Integer openFlowPortId1 = ofPortMap.get(port1.getInformationModelId());
            if (openFlowPortId1 != null) {
                port1.setOpenFlowPortId(openFlowPortId1);
            }

            Port port2 = link.get(1);
            Integer openFlowPortId2 = ofPortMap.get(port2.getInformationModelId());
            if (openFlowPortId2 != null) {
                port2.setOpenFlowPortId(openFlowPortId2);
            }
        }
    }
}