Example usage for java.math BigInteger intValue

List of usage examples for java.math BigInteger intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

Converts this BigInteger to an int .

Usage

From source file:com.glaf.core.jdbc.QueryHelper.java

@SuppressWarnings("unchecked")
public int getTotal(Connection conn, SqlExecutor sqlExecutor) {
    int total = 0;
    PreparedStatement psmt = null;
    ResultSet rs = null;/*from w w  w. ja v  a 2 s.  c o m*/
    try {
        psmt = conn.prepareStatement(sqlExecutor.getSql());
        if (sqlExecutor.getParameter() != null) {
            List<Object> values = (List<Object>) sqlExecutor.getParameter();
            JdbcUtils.fillStatement(psmt, values);
        }

        rs = psmt.executeQuery();
        if (rs.next()) {
            Object object = rs.getObject(1);
            if (object instanceof Integer) {
                Integer iCount = (Integer) object;
                total = iCount.intValue();
            } else if (object instanceof Long) {
                Long iCount = (Long) object;
                total = iCount.intValue();
            } else if (object instanceof BigDecimal) {
                BigDecimal bg = (BigDecimal) object;
                total = bg.intValue();
            } else if (object instanceof BigInteger) {
                BigInteger bi = (BigInteger) object;
                total = bi.intValue();
            } else {
                String x = object.toString();
                if (StringUtils.isNotEmpty(x)) {
                    total = Integer.parseInt(x);
                }
            }
        }
    } catch (Exception ex) {
        logger.error(ex);
        ex.printStackTrace();
        throw new RuntimeException(ex);
    } finally {
        JdbcUtils.close(psmt);
        JdbcUtils.close(rs);
    }
    return total;
}

From source file:com.glaf.core.jdbc.QueryHelper.java

@SuppressWarnings("unchecked")
public int getTotal(Connection conn, String sql, Map<String, Object> paramMap) {
    if (!DBUtils.isLegalQuerySql(sql)) {
        throw new RuntimeException(" SQL statement illegal ");
    }/*ww w  . j  av a  2 s. c  om*/
    int total = -1;
    PreparedStatement psmt = null;
    ResultSet rs = null;
    try {
        List<Object> values = null;
        if (paramMap != null) {
            SqlExecutor sqlExecutor = DBUtils.replaceSQL(sql, paramMap);
            sql = sqlExecutor.getSql();
            values = (List<Object>) sqlExecutor.getParameter();
        }

        sql = DBUtils.removeOrders(sql);

        logger.debug("sql:\n" + sql);
        logger.debug("values:" + values);

        psmt = conn.prepareStatement(sql);

        if (values != null && !values.isEmpty()) {
            JdbcUtils.fillStatement(psmt, values);
        }

        rs = psmt.executeQuery();
        if (rs.next()) {
            Object object = rs.getObject(1);
            if (object != null) {
                if (object instanceof Integer) {
                    Integer iCount = (Integer) object;
                    total = iCount.intValue();
                } else if (object instanceof Long) {
                    Long iCount = (Long) object;
                    total = iCount.intValue();
                } else if (object instanceof BigDecimal) {
                    BigDecimal bg = (BigDecimal) object;
                    total = bg.intValue();
                } else if (object instanceof BigInteger) {
                    BigInteger bi = (BigInteger) object;
                    total = bi.intValue();
                } else {
                    String x = object.toString();
                    if (StringUtils.isNotEmpty(x)) {
                        total = Integer.parseInt(x);
                    }
                }
            }
        }
    } catch (Exception ex) {
        logger.error(ex);
        ex.printStackTrace();
        throw new RuntimeException(ex);
    } finally {
        JdbcUtils.close(psmt);
        JdbcUtils.close(rs);
    }

    return total;
}

From source file:org.alfresco.wcm.client.impl.WebSiteServiceImpl.java

private void refreshWebsiteCache() {
    Map<String, WebSite> newCache = new HashMap<String, WebSite>(5);

    Session session = CmisSessionHelper.getSession();

    // Execute query
    if (log.isDebugEnabled()) {
        log.debug("About to run CMIS query: " + QUERY_WEB_ROOTS);
    }//from  w w  w. j a  va  2 s  . c o  m
    ItemIterable<QueryResult> results = session.query(QUERY_WEB_ROOTS, false);
    for (QueryResult result : results) {
        // Get the details of the returned object
        String id = result.getPropertyValueById(PropertyIds.OBJECT_ID);
        String hostName = result.getPropertyValueById(WebSite.PROP_HOSTNAME);
        BigInteger hostPort = result.getPropertyValueById(WebSite.PROP_HOSTPORT);
        String context = result.getPropertyValueById(WebSite.PROP_CONTEXT);
        if (context == null) {
            context = "";
        }
        if (context.startsWith("/")) {
            context = context.substring(1);
        }
        if (hostPort == null) {
            // Default to port 80 if not set
            hostPort = new BigInteger("80");
        }
        String key = (hostName + ":" + hostPort.toString()).toLowerCase() + "/" + context;

        String title = result.getPropertyValueById(Asset.PROPERTY_TITLE);
        String description = result.getPropertyValueById(Asset.PROPERTY_DESCRIPTION);
        List<String> configList = result.getPropertyMultivalueById(WebSite.PROP_SITE_CONFIG);
        Map<String, String> configProperties = parseSiteConfig(configList);

        WebsiteInfo siteInfo = getWebsiteInfo(id);

        WebSiteImpl webSite = new WebSiteImpl(id, hostName, hostPort.intValue(),
                webSiteSectionCacheRefreshAfter);
        webSite.setRootSectionId(siteInfo.rootSectionId);
        webSite.setTitle(title);
        webSite.setDescription(description);
        webSite.setContext(context);
        webSite.setSectionFactory(sectionFactory);
        webSite.setConfig(configProperties);
        webSite.setUgcService(createUgcService(session, siteInfo));

        newCache.put(key, webSite);

        // Find the logo asset id
        Asset logo = assetFactory.getSectionAsset(siteInfo.rootSectionId, logoFilename, true);
        webSite.setLogo(logo);
    }

    webSiteCacheRefeshedAt = System.currentTimeMillis();
    webSiteCache = newCache;
}

From source file:com.ephesoft.gxt.rv.server.ReviewValidateServiceImpl.java

private List<Span> getSortedList(final List<Span> spanList) {
    final Set<Span> set = new TreeSet<Span>(new Comparator<Span>() {

        public int compare(final Span firstSpan, final Span secSpan) {
            BigInteger s1Y0 = firstSpan.getCoordinates().getY0();
            BigInteger s1Y1 = firstSpan.getCoordinates().getY1();
            final BigInteger s2Y0 = secSpan.getCoordinates().getY0();
            final BigInteger s2Y1 = secSpan.getCoordinates().getY1();
            final int halfOfSecSpan = (s2Y1.intValue() - s2Y0.intValue()) / 2;
            final int y1 = s2Y1.intValue() + halfOfSecSpan;
            final int y0 = s2Y0.intValue() - halfOfSecSpan;

            // following if else code is to handle abnormal(out of synch) value y0 or y1 coordinate of new span.
            if (isApproxEqual(s1Y0.intValue(), s2Y0.intValue()) && s1Y1.intValue() > y1) {
                s1Y1 = BigInteger.valueOf(y1);
                firstSpan.getCoordinates().setY1(s1Y1);
            } else if (isApproxEqual(s1Y1.intValue(), s2Y1.intValue()) && s1Y0.intValue() < y0) {
                s1Y0 = BigInteger.valueOf(y0);
                firstSpan.getCoordinates().setY0(s1Y0);
            }//from www . j av a2s  .c o m
            final BigInteger s1Y = s1Y1.add(s1Y0);
            final BigInteger s2Y = s2Y1.add(s2Y0);

            // calculating middle of old span.
            final int oldSpanMid = s2Y.intValue() / 2;
            int returnValue = 0;

            // if old span's y coordinate's middle lies within range of new span's y coordinates or not. if true, the two spans
            // belong to same line compare them further on their x coordinates, else they belong to two different lines.
            if (oldSpanMid >= s1Y0.intValue() && oldSpanMid <= s1Y1.intValue()) {
                final BigInteger s1X1 = firstSpan.getCoordinates().getX1();
                final BigInteger s2X1 = secSpan.getCoordinates().getX1();
                returnValue = s1X1.compareTo(s2X1);
            } else {
                returnValue = s1Y.compareTo(s2Y);
            }
            return returnValue;
        }
    });
    set.addAll(spanList);
    final List<Span> spanSortedList = new LinkedList<Span>();
    spanSortedList.addAll(set);

    // TODO add the clear method to remove all elements of set since it not
    // required after adding it to linked list.
    // set.clear();

    return spanSortedList;

}

From source file:be.fedict.eid.tsl.TrustServiceList.java

public Integer getHistoricalInformationPeriod() {
    if (null == this.trustStatusList) {
        return null;
    }//ww  w .  j  a  va2  s  .co m
    TSLSchemeInformationType schemeInformation = this.trustStatusList.getSchemeInformation();
    if (null == schemeInformation) {
        return null;
    }
    BigInteger historicalInformationPeriod = schemeInformation.getHistoricalInformationPeriod();
    if (null == historicalInformationPeriod) {
        return null;
    }
    return historicalInformationPeriod.intValue();
}

From source file:jp.aegif.nemaki.cmis.service.impl.NavigationServiceImpl.java

@Override
public List<ObjectInFolderContainer> getDescendants(CallContext callContext, String repositoryId,
        String folderId, BigInteger depth, String filter, Boolean includeAllowableActions,
        IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment,
        boolean foldersOnly, ExtensionsData extension, Holder<ObjectData> anscestorObjectData) {

    exceptionService.invalidArgumentRequiredString("folderId", folderId);

    Lock parentLock = threadLockService.getReadLock(repositoryId, folderId);

    try {// w  w w  .  j  av  a2  s.com
        parentLock.lock();

        // //////////////////
        // General Exception
        // //////////////////
        Folder folder = contentService.getFolder(repositoryId, folderId);
        exceptionService.permissionDenied(callContext, repositoryId,
                PermissionMapping.CAN_GET_DESCENDENTS_FOLDER, folder);

        // //////////////////
        // Specific Exception
        // //////////////////
        exceptionService.invalidArgumentFolderId(folder, folderId);
        exceptionService.invalidArgumentDepth(depth);

        // //////////////////
        // Body of the method
        // //////////////////
        // check depth
        int d = (depth == null ? 2 : depth.intValue());

        // set defaults if values not set
        boolean iaa = (includeAllowableActions == null ? false : includeAllowableActions.booleanValue());
        boolean ips = (includePathSegment == null ? false : includePathSegment.booleanValue());

        // Set ObjectData of the starting folder for ObjectInfo
        ObjectData _folder = compileService.compileObjectData(callContext, repositoryId, folder, filter,
                includeAllowableActions, includeRelationships, renditionFilter, false);
        anscestorObjectData.setValue(_folder);

        // get the tree.
        return getDescendantsInternal(callContext, repositoryId, _folder, filter, iaa, false,
                includeRelationships, null, ips, 0, d, foldersOnly);

    } finally {
        parentLock.unlock();
    }
}

From source file:com.sourcesense.opencmis.server.HstCmisRepository.java

/**
 * CMIS getDescendants.//from   ww w  . j  av  a2s  .c  o  m
 */
public List<ObjectInFolderContainer> getDescendants(CallContext context, String folderId, BigInteger depth,
        String filter, Boolean includeAllowableActions, Boolean includePathSegment,
        ObjectInfoHandler objectInfos, boolean foldersOnly, HttpServletRequest servletRequest)
        throws ObjectBeanManagerException, RepositoryException {
    debug("getDescendants or getFolderTree");
    boolean userReadOnly = checkUser(context, false);

    // check depth
    int d = (depth == null ? 2 : depth.intValue());
    if (d == 0) {
        throw new CmisInvalidArgumentException("Depth must not be 0!");
    }
    if (d < -1) {
        d = -1;
    }

    // split filter
    Set<String> filterCollection = splitFilter(filter);

    // set defaults if values not set
    boolean iaa = (includeAllowableActions == null ? false : includeAllowableActions.booleanValue());
    boolean ips = (includePathSegment == null ? false : includePathSegment.booleanValue());

    HstRequestContext requestContext = getRequestContext(servletRequest);
    ObjectBeanPersistenceManager contentPersistenceManager = getContentPersistenceManager(requestContext);

    // get the folder
    HippoFolderBean folder = (HippoFolderBean) contentPersistenceManager.getObjectByUuid(folderId);

    // set object info of the the folder
    if (context.isObjectInfoRequired()) {
        compileObjectType(context, folder, null, false, false, userReadOnly, objectInfos);
    }

    // get the tree
    List<ObjectInFolderContainer> result = new ArrayList<ObjectInFolderContainer>();
    gatherDescendants(context, folder, result, foldersOnly, d, filterCollection, iaa, ips, userReadOnly,
            objectInfos);

    return result;
}

From source file:org.jbpm.formModeler.core.processing.formRendering.FormRenderingFormatter.java

/**
 * Default display. One field after each other
 *
 * @param form//from  w w  w  . ja v a 2  s .  com
 * @param renderMode
 */
protected void defaultDisplay(Form form, String namespace, String renderMode, String labelMode, String mode) {
    Set<Field> fields = form.getFormFields();
    List<Field> sortedFields = new ArrayList(fields);
    Collections.sort(sortedFields, new Field.Comparator());
    FormStatusData formStatusData = getFormProcessor().read(form, namespace);

    setAttribute("width", deduceWidthForForm(form, renderMode, labelMode, mode));
    renderFragment("outputStart");
    renderFragment("formHeader");
    /*Calculate colspans*/
    List colspans = new ArrayList();
    List fieldGroups = new ArrayList();
    fieldGroups.add(new ArrayList());
    for (Field field : sortedFields) {
        List currentList = (List) fieldGroups.get(fieldGroups.size() - 1);
        if (!Boolean.TRUE.equals(field.getGroupWithPrevious())) {
            fieldGroups.add(currentList = new ArrayList());
        }
        currentList.add(field);
    }
    for (int i = 0; i < fieldGroups.size(); i++) {
        List list = (List) fieldGroups.get(i);
        if (!list.isEmpty())
            colspans.add(new BigInteger(String.valueOf(list.size())));
    }

    BigInteger mcm = calculateMCM(colspans);
    BigInteger max = calculateMax(colspans);

    /*Render fields with colspans*/
    List groupList = new ArrayList();

    boolean first = true;

    for (int i = 0; i < sortedFields.size(); i++) {
        Field field = sortedFields.get(i);
        groupList.add(field);
        if (i < sortedFields.size() - 1) {
            Field nextField = sortedFields.get(i + 1);
            if (nextField.getGroupWithPrevious() != null && nextField.getGroupWithPrevious().booleanValue()) {
                continue;
            }
        }
        if (i > 0 && Form.DISPLAY_MODE_NONE.equals(mode)) {
            renderFragment("outputEnd");
            setAttribute("width", deduceWidthForForm(form, renderMode, labelMode, mode));
            renderFragment("outputStart");
        }
        defaultDisplayGroup(form, groupList, mcm.intValue(), max.intValue(), renderMode, labelMode,
                formStatusData, mode, namespace, i, first);
        groupList.clear();
        first = false;
    }

    displayFooter(form);
    renderFragment("outputEnd");
}

From source file:org.openhab.binding.ulux.internal.ump.messages.ControlMessage.java

@Override
protected void addData(final ByteBuffer buffer) {
    BigInteger controlFlags = BigInteger.valueOf(0);

    // TODO this.lockMode
    // TODO this.backgroundLight

    if (this.i2cPlugAndPlay) {
        controlFlags = controlFlags.setBit(31);
    }/*from w  ww.  j  a  v  a2  s .co  m*/
    if (this.i2cHumidityChangeRequest) {
        controlFlags = controlFlags.setBit(25);
    }
    if (this.i2cTemperatureChangeRequest) {
        controlFlags = controlFlags.setBit(24);
    }
    if (this.motionSensorChangeRequest) {
        controlFlags = controlFlags.setBit(11);
    }
    if (this.keepAlive) {
        controlFlags = controlFlags.setBit(10);
    }
    if (this.changeFilter) {
        controlFlags = controlFlags.setBit(9);
    }
    if (this.frameAcknowledgement) {
        controlFlags = controlFlags.setBit(8);
    }
    if (this.volumeChangeRequest) {
        controlFlags = controlFlags.setBit(5);
    }
    if (this.pageChangeRequest) {
        controlFlags = controlFlags.setBit(4);
    }
    if (this.audioActiveChangeRequest) {
        controlFlags = controlFlags.setBit(3);
    }
    if (this.displayActiveChangeRequest) {
        controlFlags = controlFlags.setBit(2);
    }
    if (this.proximitySensorChangeRequest) {
        controlFlags = controlFlags.setBit(1);
    }
    if (this.lightSensorChangeRequest) {
        controlFlags = controlFlags.setBit(0);
    }

    buffer.putInt(controlFlags.intValue());
}

From source file:jp.aegif.nemaki.cmis.aspect.type.impl.TypeManagerImpl.java

/**
 * CMIS getTypesChildren. If parent type id is not specified, return only
 * base types./*w w w .ja  va  2 s .c  o  m*/
 */
@Override
public TypeDefinitionList getTypesChildren(CallContext context, String repositoryId, String typeId,
        boolean includePropertyDefinitions, BigInteger maxItems, BigInteger skipCount) {

    Map<String, TypeDefinitionContainer> types = TYPES.get(repositoryId);

    TypeDefinitionListImpl result = new TypeDefinitionListImpl(new ArrayList<TypeDefinition>());

    int skip = (skipCount == null ? 0 : skipCount.intValue());
    if (skip < 0) {
        skip = 0;
    }

    int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
    if (max < 1) {
        return result;
    }

    if (typeId == null) {
        int count = skip;
        for (String key : basetypes.keySet()) {
            count--;
            if (count >= 0)
                continue;
            TypeDefinitionContainer type = basetypes.get(key);
            result.getList().add(DataUtil.copyTypeDefinition(type.getTypeDefinition()));
        }

        result.setHasMoreItems((result.getList().size() + skip) < max);
        result.setNumItems(BigInteger.valueOf(basetypes.size()));
    } else {
        TypeDefinitionContainer tc = types.get(typeId);
        if ((tc == null) || (tc.getChildren() == null)) {
            return result;
        }

        for (TypeDefinitionContainer child : tc.getChildren()) {
            if (skip > 0) {
                skip--;
                continue;
            }

            result.getList().add(DataUtil.copyTypeDefinition(child.getTypeDefinition()));

            max--;
            if (max == 0) {
                break;
            }
        }

        result.setHasMoreItems((result.getList().size() + skip) < tc.getChildren().size());
        result.setNumItems(BigInteger.valueOf(tc.getChildren().size()));
    }

    if (!includePropertyDefinitions) {
        for (TypeDefinition type : result.getList()) {
            try {
                if (type.getPropertyDefinitions() != null) {
                    type.getPropertyDefinitions().clear();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return result;
}