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:org.ejbca.core.protocol.cmp.CmpTestCase.java

protected static void checkCmpPKIErrorMessage(byte[] retMsg, String sender, X500Name recipient, int errorCode,
        String errorMsg) throws IOException {
    ////from w w w .  jav  a 2  s.c o m
    // Parse response message
    //
    PKIMessage respObject = null;
    ASN1InputStream asn1InputStream = new ASN1InputStream(new ByteArrayInputStream(retMsg));
    try {
        respObject = PKIMessage.getInstance(asn1InputStream.readObject());
    } finally {
        asn1InputStream.close();
    }
    assertNotNull(respObject);
    PKIHeader header = respObject.getHeader();
    assertEquals(header.getSender().getTagNo(), 4);
    {
        final X500Name name = X500Name.getInstance(header.getSender().getName());
        assertEquals(name.toString(), sender);
    }
    {
        final X500Name name = X500Name.getInstance(header.getRecipient().getName());
        assertArrayEquals(name.getEncoded(), recipient.getEncoded());
    }

    PKIBody body = respObject.getBody();
    int tag = body.getType();
    assertEquals(tag, 23);
    ErrorMsgContent n = (ErrorMsgContent) body.getContent();
    assertNotNull(n);
    PKIStatusInfo info = n.getPKIStatusInfo();
    assertNotNull(info);
    BigInteger i = info.getStatus();
    assertEquals(i.intValue(), 2);
    DERBitString b = info.getFailInfo();
    assertEquals("Return wrong error code.", errorCode, b.intValue());
    if (errorMsg != null) {
        PKIFreeText freeText = info.getStatusString();
        DERUTF8String utf = freeText.getStringAt(0);
        assertEquals(errorMsg, utf.getString());
    }
}

From source file:com.glaf.core.dao.MyBatisEntityDAO.java

public int getCount(String statementId, Object parameterObject) {
    int totalCount = 0;
    SqlSession session = getSqlSession();

    Object object = null;//from w  w  w.  j a  v  a  2  s  . c  o m
    if (parameterObject != null) {
        object = session.selectOne(statementId, parameterObject);
    } else {
        object = session.selectOne(statementId);
    }

    if (object instanceof Integer) {
        Integer iCount = (Integer) object;
        totalCount = iCount.intValue();
    } else if (object instanceof Long) {
        Long iCount = (Long) object;
        totalCount = iCount.intValue();
    } else if (object instanceof BigDecimal) {
        BigDecimal bg = (BigDecimal) object;
        totalCount = bg.intValue();
    } else if (object instanceof BigInteger) {
        BigInteger bi = (BigInteger) object;
        totalCount = bi.intValue();
    } else {
        String value = object.toString();
        totalCount = Integer.parseInt(value);
    }
    return totalCount;
}

From source file:org.oscarehr.common.dao.DrugDao.java

public int getNumberOfDemographicsWithRxForProvider(String providerNo, Date startDate, Date endDate,
        boolean distinct) {
    String distinctStr = "distinct";
    if (distinct == false) {
        distinctStr = StringUtils.EMPTY;
    }//from   ww w. j a  va2  s .  co m

    Query query = entityManager.createNativeQuery("select count(" + distinctStr
            + " demographic_no)from drugs x where x.provider_no = ? and x.written_date >= ? and x.written_date <= ?");
    query.setParameter(1, providerNo);
    query.setParameter(2, startDate);
    query.setParameter(3, endDate);
    BigInteger bint = (BigInteger) query.getSingleResult();
    return bint.intValue();
}

From source file:org.books.integration.AmazonCatalogBean.java

private Integer toInteger(BigInteger numberOfPages) {
    return numberOfPages.intValue();
}

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);/* ww  w.ja  v  a  2  s .  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:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.AbstractActivityParser.java

protected ObjectNode parseAndAddOutputPortDefinition(ActivityPortDefinitionBean portBean,
        Configuration configuration, Activity activity) {
    ObjectNode configResource = (ObjectNode) configuration.getJson();
    OutputActivityPort outputPort = new OutputActivityPort();

    outputPort.setName(getPortElement(portBean, "name", String.class));
    outputPort.setParent(activity);//from   www.  j  a v a  2 s .co m

    BigInteger depth = getPortElement(portBean, "depth", BigInteger.class);
    if (depth != null)
        outputPort.setDepth(depth.intValue());

    BigInteger granularDepth = getPortElement(portBean, "granularDepth", BigInteger.class);
    if (granularDepth != null)
        outputPort.setGranularDepth(granularDepth.intValue());

    ObjectNode portConfig = configResource.objectNode();
    //      PropertyResource portConfig = configResource.addPropertyAsNewResource(
    //            Scufl2Tools.PORT_DEFINITION.resolve("#outputPortDefinition"),
    //            Scufl2Tools.PORT_DEFINITION.resolve("#OutputPortDefinition"));

    @SuppressWarnings("unused")
    URI portUri = new URITools().relativeUriForBean(outputPort, configuration);
    //      portConfig.addPropertyReference(Scufl2Tools.PORT_DEFINITION.resolve("#definesOutputPort"), portUri);

    // Legacy duplication of port details for XMLSplitter activities
    portConfig.put("name", outputPort.getName());
    portConfig.put("depth", outputPort.getDepth());
    portConfig.put("granularDepth", outputPort.getDepth());

    parseMimeTypes(portBean, portConfig);
    return portConfig;
}

From source file:org.apache.servicemix.wsn.AbstractPullPoint.java

/**
 * /*from  w w w  . ja v  a2s .  co  m*/
 * @param getMessagesRequest
 * @return returns org.oasis_open.docs.wsn.b_1.GetMessagesResponse
 * @throws ResourceUnknownFault
 */
@WebMethod(operationName = "GetMessages")
@WebResult(name = "GetMessagesResponse", targetNamespace = "http://docs.oasis-open.org/wsn/b-1", partName = "GetMessagesResponse")
public GetMessagesResponse getMessages(
        @WebParam(name = "GetMessages", targetNamespace = "http://docs.oasis-open.org/wsn/b-1", partName = "GetMessagesRequest") GetMessages getMessagesRequest)
        throws ResourceUnknownFault, UnableToGetMessagesFault {

    log.debug("GetMessages");
    BigInteger max = getMessagesRequest.getMaximumNumber();
    System.out.println("**********************************BigInteger max " + max);
    List<NotificationMessageHolderType> messages = getMessages(max != null ? max.intValue() : 0);
    GetMessagesResponse response = new GetMessagesResponse();
    response.getNotificationMessage().addAll(messages);
    return response;
}

From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.AbstractActivityParser.java

protected ObjectNode parseAndAddInputPortDefinition(ActivityPortDefinitionBean portBean,
        Configuration configuration, Activity activity) {
    ObjectNode configResource = (ObjectNode) configuration.getJson();
    ObjectNode portConfig = configResource.objectNode();

    InputActivityPort inputPort = new InputActivityPort();
    inputPort.setName(getPortElement(portBean, "name", String.class));
    inputPort.setParent(activity);/* w  w  w  .j a  va2s  .  co  m*/

    BigInteger depth = getPortElement(portBean, "depth", BigInteger.class);
    if (depth != null)
        inputPort.setDepth(depth.intValue());

    //      PropertyResource portConfig = configResource.addPropertyAsNewResource(
    //            Scufl2Tools.PORT_DEFINITION.resolve("#inputPortDefinition"),
    //            Scufl2Tools.PORT_DEFINITION.resolve("#InputPortDefinition"));

    @SuppressWarnings("unused")
    URI portUri = new URITools().relativeUriForBean(inputPort, configuration);
    //      portConfig.addPropertyReference(Scufl2Tools.PORT_DEFINITION.resolve("#definesInputPort"), portUri);

    parseMimeTypes(portBean, portConfig);

    String translated = getPortElement(portBean, "translatedElementType", String.class);
    if (translated != null) {
        // As "translated element type" is confusing, we'll instead use "dataType"
        //         portConfig.addPropertyReference(Scufl2Tools.PORT_DEFINITION.resolve("#dataType"),
        //               URI.create("java:" + translated));
        portConfig.put("dataType", "java:" + translated);

        // TODO: Include mapping to XSD types like xsd:string
    }
    // T2-1681: Ignoring isAllowsLiteralValues and handledReferenceScheme

    // Legacy duplication of port details for XMLSplitter activities
    portConfig.put("name", inputPort.getName());
    portConfig.put("depth", inputPort.getDepth());

    return portConfig;
}

From source file:org.trnltk.numeral.DigitsToTextConverter.java

private int getNthGroupNumber(BigInteger naturalNumber, int n) {
    naturalNumber = naturalNumber.divide(ONE_THOUSAND.pow(n));
    naturalNumber = naturalNumber.mod(ONE_THOUSAND);
    return naturalNumber.intValue();
}

From source file:com.glaf.core.dao.MyBatisEntityDAO.java

public Paging getPage(int pageNo, int pageSize, SqlExecutor countExecutor, SqlExecutor queryExecutor) {
    if (pageSize <= 0) {
        pageSize = Paging.DEFAULT_PAGE_SIZE;
    }//from w ww.  j  a  v a  2s  .  c  o  m
    if (pageNo <= 0) {
        pageNo = 1;
    }

    Object object = null;
    int totalCount = 0;
    Paging page = new Paging();
    SqlSession session = getSqlSession();

    Object parameter = countExecutor.getParameter();
    if (parameter != null) {
        object = session.selectOne(countExecutor.getStatementId(), parameter);
    } else {
        object = session.selectOne(countExecutor.getStatementId());
    }

    if (object instanceof Integer) {
        Integer iCount = (Integer) object;
        totalCount = iCount.intValue();
    } else if (object instanceof Long) {
        Long iCount = (Long) object;
        totalCount = iCount.intValue();
    } else if (object instanceof BigDecimal) {
        BigDecimal bg = (BigDecimal) object;
        totalCount = bg.intValue();
    } else if (object instanceof BigInteger) {
        BigInteger bi = (BigInteger) object;
        totalCount = bi.intValue();
    } else {
        String value = object.toString();
        totalCount = Integer.parseInt(value);
    }

    if (totalCount == 0) {
        page.setRows(new java.util.ArrayList<Object>());
        page.setCurrentPage(0);
        page.setPageSize(0);
        page.setTotal(0);
        return page;
    }

    page.setTotal(totalCount);

    int maxPageNo = (page.getTotal() + (pageSize - 1)) / pageSize;
    if (pageNo > maxPageNo) {
        pageNo = maxPageNo;
    }

    List<Object> rows = null;

    Object queryParams = queryExecutor.getParameter();

    int begin = (pageNo - 1) * pageSize;

    RowBounds rowBounds = new RowBounds(begin, pageSize);

    if (queryParams != null) {
        rows = session.selectList(queryExecutor.getStatementId(), queryParams, rowBounds);
    } else {
        rows = session.selectList(queryExecutor.getStatementId(), null, rowBounds);
    }

    page.setRows(rows);
    page.setPageSize(pageSize);
    page.setCurrentPage(pageNo);

    logger.debug("params:" + queryParams);
    logger.debug("rows size:" + rows.size());

    return page;
}