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.sun.honeycomb.adm.client.AdminClientImpl.java

public int setProtocolPassword(String realmName, String userName, byte[] hash)
        throws MgmtException, ConnectException, PermissionException {
    if (!loggedIn())
        throw new PermissionException();

    Object[] params = { Long.toString(_sessionId), realmName, userName };

    this.extLog(ExtLevel.EXT_INFO, AdminResourcesConstants.MSG_KEY_SET_PROTOCOL_PASSWORD, params,
            "setProtocolPassword");
    BigInteger retValue = getSilo(SiloInfo.getInstance().getSiloUrl()).setProtocolPassword(realmName, userName,
            ByteArrays.toHexString(hash));
    return retValue.intValue();
}

From source file:org.n52.wps.server.request.InputHandler.java

private IData parseBoundingBox(BoundingBoxType bbt) throws ExceptionReport {
    final BigInteger dim = bbt.getDimensions();
    final double[] lower, upper;

    if (dim != null && (dim.compareTo(INT_MAX) > 0 || dim.compareTo(INT_MIN) < 0)) {
        throw new ExceptionReport(
                String.format("Unsupported BoundingBox dimension %s. Has to be betweeen %s and %s!", dim,
                        INT_MIN, INT_MAX),
                ExceptionReport.INVALID_PARAMETER_VALUE);
    }/*from   www  .  j  a v a2s  .  c o m*/

    try {
        lower = parseCoordinate(bbt.getLowerCorner());
    } catch (NumberFormatException e) {
        throw new ExceptionReport("Invalid lower corner", ExceptionReport.INVALID_PARAMETER_VALUE, e);
    }

    try {
        upper = parseCoordinate(bbt.getUpperCorner());
    } catch (NumberFormatException e) {
        throw new ExceptionReport("Invalid upper corner", ExceptionReport.INVALID_PARAMETER_VALUE, e);
    }

    if (upper.length != lower.length) {
        throw new ExceptionReport(
                String.format("Mismatching BoundingBox dimensions: %s vs %s!", upper.length, lower.length),
                ExceptionReport.INVALID_PARAMETER_VALUE);
    }

    if (dim != null && lower.length != dim.intValue()) {
        throw new ExceptionReport(
                String.format("Mismatching BoundingBox dimensions: %s vs %s!", dim.intValue(), lower.length),
                ExceptionReport.INVALID_PARAMETER_VALUE);
    }
    return new BoundingBoxData(lower, upper, bbt.getCrs());
}

From source file:org.plasma.sdo.helper.DataConverter.java

public Object fromInteger(Type targetType, BigInteger value) {
    DataType targetDataType = DataType.valueOf(targetType.getName());
    switch (targetDataType) {
    case Integer:
        return value;
    case Double:
        return new Double(value.doubleValue());
    case Float:
        return new Float(value.floatValue());
    case Int://ww  w. j  a v  a2  s  .  c  om
        return new Integer(value.intValue());
    case Long:
        return new Long(value.longValue());
    case Decimal:
        return new BigDecimal(value.doubleValue());
    case Bytes:
        return value.toByteArray();
    case String:
        //as per spec: ('+'|'-')? [0-9]+
        return value.toString();
    default:
        throw new InvalidDataConversionException(targetDataType, DataType.Integer, value);
    }
}

From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java

public int pushSchema(InputStream input, boolean validateOnly)
        throws MgmtException, ConnectException, PermissionException, IOException {
    if (!loggedIn())
        throw new PermissionException();

    int res = -1;

    InputStream is = new BufferedInputStream(input);

    // tmp buffer used to read schema from client
    byte[] buffer = new byte[CliConstants.MAX_BYTE_SCHEMA_PER_ENVELOPE];
    int length = CliConstants.MAX_BYTE_SCHEMA_PER_ENVELOPE;
    int offset = 0;
    byte mask = CliConstants.MDCONFIG_FIRST_MESSAGE;

    // piece of schema sent in one WS-management envelope
    String schemaPiece = null;/*from  ww w. jav a  2  s  .  c om*/

    // Runner, timestamp for 'commit'
    MultiCellSchemaUpdate[] schemaUpdate = null;
    MultiCellRunner runner = null;
    long timestamp = -1;

    // Cell to target for 'validation only'
    HCCell masterCell = null;
    if (validateOnly) {
        masterCell = getCell(SiloInfo.getInstance().getMasterUrl());
    } else {
        timestamp = System.currentTimeMillis();
        MultiCellOp[] ops = allocateMultiCellOp(MultiCellSchemaUpdate.class);
        runner = new MultiCellRunner(ops);
        // Nothing will hapeen until we set the cookie with the
        // first buffer we read.
        runner.start();
    }

    int nbPiece = 0;
    do {
        res = is.read(buffer, offset, length);
        if (res == -1) {
            break;
        }
        offset += res;
        length -= res;
        if (offset == CliConstants.MAX_BYTE_SCHEMA_PER_ENVELOPE) {
            schemaPiece = new String(buffer, "UTF-8");
            if (validateOnly) {
                try {
                    BigInteger wsRet = masterCell.updateSchema(null, schemaPiece, (long) -1, mask, (byte) 0);
                    if (wsRet.intValue() != CliConstants.MGMT_OK) {
                        return CliConstants.MGMT_SCHEMA_UPLOAD_FAILED;
                    }
                } catch (Exception e) {
                    throw new MgmtException("Failed to validate schema:\n" + e.getMessage());
                }
            } else {
                nbPiece++;
                SchemaUpdateCookie cookie = new SchemaUpdateCookie(schemaPiece, nbPiece, timestamp, mask);
                runner.setCookie(cookie);
                int r = runner.waitForPartialResult();
                if (r != 0) {
                    return CliConstants.MGMT_SCHEMA_UPLOAD_FAILED;
                }
            }
            mask = 0;
            buffer = new byte[CliConstants.MAX_BYTE_SCHEMA_PER_ENVELOPE];
            offset = 0;
            length = CliConstants.MAX_BYTE_SCHEMA_PER_ENVELOPE;
        }
    } while (res != -1);

    mask |= CliConstants.MDCONFIG_LAST_MESSAGE;
    if (offset > 0) {
        schemaPiece = new String(buffer, 0, offset, "UTF-8");
    } else {
        // we still send a message with a null schemaPiece to 
        // send the mask with the value MDCONFIG_LAST_MESSAGE
        schemaPiece = null;
    }
    if (validateOnly) {
        BigInteger wsRet = BigInteger.valueOf(CliConstants.MGMT_OK);
        try {
            wsRet = masterCell.updateSchema(null, schemaPiece, (long) -1, mask, (byte) 0);
        } catch (Exception e) {
            throw new MgmtException("Failed to validate schema:\n" + e.getMessage());
            //throwException(e, "updateSchema");
        }
        return wsRet.intValue();
    } else {
        SchemaUpdateCookie cookie = new SchemaUpdateCookie(schemaPiece, nbPiece, timestamp, mask);
        runner.setCookie(cookie);

        Object[] params = { Long.toString(this._sessionId) };
        this.extLog(ExtLevel.EXT_INFO, AdminResourcesConstants.MSG_KEY_UPDATE_SCHEMA, params, "pushSchema");

        return runner.waitForResult();
    }
}

From source file:org.alfresco.mobile.android.api.services.impl.AbstractDocumentFolderServiceImpl.java

/** {@inheritDoc} */
public PagingResult<Node> getChildren(Folder parentFolder, ListingContext lcontext) {

    if (isObjectNull(parentFolder)) {
        throw new IllegalArgumentException(String
                .format(Messagesl18n.getString("ErrorCodeRegistry.GENERAL_INVALID_ARG_NULL"), "parentFolder"));
    }/*from  w w w. j a  v  a  2s.  c o m*/

    try {
        NavigationService navigationService = cmisSession.getBinding().getNavigationService();
        OperationContext ctxt = new OperationContextImpl(cmisSession.getDefaultContext());
        ObjectFactory objectFactory = cmisSession.getObjectFactory();

        // By default Listing context has default value
        String orderBy = getSorting(SORT_PROPERTY_NAME, true);
        BigInteger maxItems = null;
        BigInteger skipCount = null;

        if (lcontext != null) {
            orderBy = getSorting(lcontext.getSortProperty(), lcontext.isSortAscending());
            maxItems = BigInteger.valueOf(lcontext.getMaxItems());
            skipCount = BigInteger.valueOf(lcontext.getSkipCount());
        }
        // get the children
        ObjectInFolderList children = navigationService.getChildren(session.getRepositoryInfo().getIdentifier(),
                parentFolder.getIdentifier(), ctxt.getFilterString(), orderBy, ctxt.isIncludeAllowableActions(),
                ctxt.getIncludeRelationships(), ctxt.getRenditionFilterString(), ctxt.isIncludePathSegments(),
                maxItems, skipCount, null);

        // convert objects
        List<Node> page = new ArrayList<Node>();
        List<ObjectInFolderData> childObjects = children.getObjects();

        if (childObjects != null) {
            // //Log.d(TAG, "childObjects : " + childObjects.size());
            for (ObjectInFolderData objectData : childObjects) {
                if (objectData.getObject() != null) {
                    Node n = convertNode(objectFactory.convertObject(objectData.getObject(), ctxt));
                    page.add(n);
                }
            }
        }

        Boolean hasMoreItem = false;
        if (maxItems != null) {
            hasMoreItem = children.hasMoreItems() && page.size() == maxItems.intValue();
        } else {
            hasMoreItem = children.hasMoreItems();
        }

        return new PagingResultImpl<Node>(page, hasMoreItem, children.getNumItems().intValue());
    } catch (Exception e) {
        convertException(e);
    }
    return null;
}

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

public MethodCallStatus getStatusOfLastServiceToBeCalledForRun(BigInteger runId)
        throws ApolloDatabaseException {
    String query = "SELECT status_id, message FROM run_status WHERE run_id = " + runId.intValue();
    PreparedStatement pstmt;/*from ww w.  j ava2 s.c  o  m*/
    ResultSet rs;
    try (Connection conn = datasource.getConnection()) {
        pstmt = conn.prepareStatement(query);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            int statusId = rs.getInt(1);
            String message = rs.getString(2);

            MethodCallStatusEnum statusEnum = getStatusEnumForStatusId(statusId);

            MethodCallStatus status = new MethodCallStatus();
            status.setMessage(message);
            status.setStatus(statusEnum);
            return status;
        } else {
            throw new ApolloDatabaseStatusNotFoundForRunIdException(
                    "No status was found in the run_status table for run ID " + runId.intValue());
        }

    } catch (SQLException ex) {
        throw new ApolloDatabaseException("SQLException attempting to get status and message for run ID "
                + runId.intValue() + ": " + ex.getMessage());
    }
}

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

public void updateStatusOfRun(BigInteger runId, int statusId, String message) throws ApolloDatabaseException {
    String query = "SELECT id FROM run_status WHERE run_id = " + runId.intValue();
    PreparedStatement pstmt;/*  ww  w .  j  a va  2 s.c o  m*/
    ResultSet rs;

    try (Connection conn = datasource.getConnection()) {
        pstmt = conn.prepareStatement(query);
        rs = pstmt.executeQuery();

        if (rs.next()) {
            query = "UPDATE run_status SET status_id = ?, message = ? WHERE run_id = ?";
        } else {
            query = "INSERT INTO run_status (status_id, message, run_id) VALUES (?,?,?)";
        }
        pstmt = conn.prepareStatement(query);

        pstmt.setInt(1, statusId);
        pstmt.setString(2, message);
        pstmt.setInt(3, runId.intValue());
        pstmt.execute();

    } catch (SQLException ex) {
        throw new ApolloDatabaseException(
                "SQLException attempting to insert or update status of run for run ID " + runId + ": "
                        + ex.getMessage());
    }
}

From source file:xc.mst.repo.RepositoryDAO.java

public boolean checkOutsideRange(String sql, AtomicInteger tally, AtomicInteger numMatching) {
    // could LIMIT accomplish the same thing as explain ?
    // no - I dont think so, because if the answer is zero - limit takes a looooong time

    List<Map<String, Object>> records = this.jdbcTemplate.queryForList("explain " + sql);

    BigInteger rows2examine = (BigInteger) records.get(0).get("rows");
    LOG.debug("rows: " + rows2examine);
    if (rows2examine == null) {
        return false;
    } else if (rows2examine.intValue() > getEstimateCompleteListSizeThreshold()) {
        if (tally != null) {
            tally.addAndGet(2);//from  w  w  w. j a  v a2  s  .c o  m
        }
        if (numMatching != null) {
            numMatching.set(rows2examine.intValue());
        }
    } else {
        int exactCount = this.jdbcTemplate.queryForInt(sql);
        if (exactCount > 0) {
            if (tally != null) {
                tally.addAndGet(1);
            }
            if (numMatching != null) {
                numMatching.set(exactCount);
            }
        }
    }

    if (tally != null)
        LOG.debug("tally: " + tally.get());
    if (numMatching != null)
        LOG.debug("numMatching: " + numMatching.get());

    return true;
}

From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java

public int getSchema(PrintStream out, boolean template) throws MgmtException, ConnectException, IOException {
    BigInteger wsRet = BigInteger.valueOf(CliConstants.MGMT_OK);
    HCCell cell = getCell(SiloInfo.getInstance().getMasterUrl());
    try {/*  ww  w.  ja v a 2 s .c o m*/
        wsRet = cell.retrieveSchema(new PrintStreamCallback(out), (template) ? (byte) 1 : (byte) 0);
    } catch (Exception e) {
        return CliConstants.MGMT_CANT_RETRIEVE_SCHEMA;
    }
    return wsRet.intValue();
}

From source file:edu.pitt.apollo.db.ApolloDbUtils.java

public int getSoftwareIdentificationKeyForRun(BigInteger runId) throws ApolloDatabaseException {

    try (Connection conn = datasource.getConnection()) {
        String query = "SELECT software_id from run WHERE " + "id = ?";
        PreparedStatement pstmt = conn.prepareStatement(query);
        pstmt.setInt(1, runId.intValue());
        ResultSet rs = pstmt.executeQuery();
        int softwareId;
        if (rs.next()) {
            softwareId = rs.getInt("software_id");
            return softwareId;
        } else {//from   w  w w .j av  a2 s .c  o  m
            throw new ApolloDatabaseKeyNotFoundException("No entry found in run where id = " + runId);
        }
    } catch (SQLException e) {
        throw new ApolloDatabaseException(e.getMessage());
    }
}