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:jp.co.golorp.emarf.model.Models.java

/**
 * insert/*  w  w w .  jav a2s.  c  o  m*/
 *
 * @param model
 *            ?
 * @return ??
 */
public static Model create(final Model model) {

    // ??
    String modelName = model.getClass().getSimpleName();

    // 
    TableInfo tableInfo = MetaData.getTableInfo(modelName);
    if (tableInfo == null) {
        throw new SystemError(MessageKeys.ABEND_DATA_INSERT, modelName);
    }

    // ??
    String tableName = tableInfo.getTableName();

    // 
    Set<String> primaryKeys = tableInfo.getPrimaryKeys();

    // OracleSequence?????
    if (primaryKeys.size() == 1) {
        fillByOracleSequence(model, tableName, primaryKeys.iterator().next());
    }

    // ??
    Set<String> primaryPropertyNames = ModelUtil.getPrimaryPropertyNames(modelName);
    if (primaryPropertyNames != null) {

        // ???
        Iterator<String> iPrimaryPropertyNames = primaryPropertyNames.iterator();
        String primaryPropertyName = iPrimaryPropertyNames.next();
        Object o = model.get(primaryPropertyName);
        if (o != null) {

            // ???????
            boolean isExistAllKey = true;

            // criteria???
            Criteria c = Criteria.equal(modelName, primaryPropertyName, o);

            // criteria????
            while (iPrimaryPropertyNames.hasNext()) {
                primaryPropertyName = iPrimaryPropertyNames.next();
                o = model.get(primaryPropertyName);
                if (o == null) {
                    isExistAllKey = false;
                    break;
                }
                c.eq(primaryPropertyName, o);
            }

            // ??????????????
            if (isExistAllKey && Models.getModel(modelName, c) != null) {
                throw new ApplicationError(MessageKeys.ERRORS_DATA_DUPLICATE);
            }
        }
    }

    /*
     * ?
     */

    Statement statement = Models.getStatement(ModelFieldTypes.GET_INSERT_STATEMENT, model);
    if (Models.regist(statement.getSql(), statement.getParams()) != 1) {
        throw new SystemError(MessageKeys.ABEND_DATA_INSERT, tableInfo.getTableMei());
    }

    /*
     * ???
     */

    // ????
    for (String primaryPropertyName : primaryPropertyNames) {

        // ????
        if (model.get(primaryPropertyName) != null) {
            continue;
        }

        // ????
        ColumnInfo primaryKeyInfo = tableInfo.getColumnInfo(primaryPropertyName);
        String primaryKeyName = primaryKeyInfo.getColumnName();

        if (primaryPropertyName.endsWith(Models.ID_SUFFIX)) {
            // AUTO_INCREMENT?ID?

            String sql = "select last_insert_id() as " + primaryKeyName + " from " + tableName;
            List<Map<String, Object>> datas = Models.getDatas(sql);
            if (datas == null) {
                continue;
            }

            Map<String, Object> data = datas.get(0);
            BigInteger value = (BigInteger) data.get(primaryPropertyName);
            if (value.intValue() >= 0) {
                model.set(primaryPropertyName, value.intValue());
            }

        } else if (primaryPropertyName.endsWith(Models.SEQ_SUFFIX)) {
            // ??

            StringBuilder sb = new StringBuilder();
            List<Object> params = new ArrayList<Object>();

            // ?????????????
            Set<String> primaryPropertyNames2 = ModelUtil.getPrimaryPropertyNames(modelName);
            for (String primaryPropertyName2 : primaryPropertyNames2) {

                // ???
                if (primaryPropertyName2.equals(primaryPropertyName)) {
                    break;
                }

                // ????where??
                if (sb.length() > 0) {
                    sb.append(" and");
                }
                ColumnInfo primaryKeyInfo2 = tableInfo.getColumnInfo(primaryPropertyName2);
                String columnName2 = primaryKeyInfo2.getColumnName();
                Object columnValue2 = model.get(primaryPropertyName2);
                sb.append(" ").append(columnName2).append(" = ?");
                params.add(columnValue2);
            }

            // ?
            String sql = "SELECT MAX(" + primaryKeyName + ") AS " + primaryKeyName + " from " + tableName
                    + " WHERE " + sb.toString();
            List<Map<String, Object>> datas = Models.getDatas(sql, params.toArray());
            if (datas == null) {
                continue;
            }

            // ??????????????????????0?
            Map<String, Object> data = datas.get(0);
            Object value = data.get(primaryPropertyName);
            if (value != null) {
                model.set(primaryPropertyName, value);
            } else {
                model.set(primaryPropertyName, 0);
            }
        }
    }

    return Models.refer(model);
}

From source file:fr.tse.fi2.hpp.labs.queries.impl.lab5.BloomFilterQuery.java

public boolean contain(String plaque, float loD, float laD, float loA, float laA) {
    String str = plaque + laA + loA + laD + loD;
    String[] str2hash = new String[k];

    MessageDigest md = null;//from  w  ww .  jav a 2  s. com
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    for (int i = 0; i < 10; i++) {
        str2hash[i] = salt[i] + str;
        try {
            md.update(str2hash.toString().getBytes("UTF-16"));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        byte[] res = md.digest();
        BigInteger indiceB = new BigInteger(res);
        int indice = indiceB.intValue();

        if (indice < 0)
            indice = -indice;
        indice = indice % 14378;
        if (!bloomFilter.get(indice))
            return false;
    }
    return true;
}

From source file:fr.tse.fi2.hpp.labs.queries.impl.lab5.BloomFilterQuery.java

@Override
protected void process(DebsRecord record) {
    // TODO Auto-generated method stub
    String str = record.getHack_license() + record.getDropoff_latitude() + record.getDropoff_longitude()
            + record.getPickup_latitude() + record.getPickup_longitude();

    MessageDigest md = null;/*from   w ww.  j  a v  a  2 s. c  o  m*/
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    String[] str2hash = new String[k];
    for (int i = 0; i < 10; i++) {
        str2hash[i] = salt[i] + str;
        try {
            md.update(str2hash[i].toString().getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        byte[] res = md.digest();
        BigInteger indiceB = new BigInteger(res);
        int indice = indiceB.intValue();
        if (indice < 0)
            indice = -indice;
        indice = indice % 14378;
        if (!bloomFilter.get(indice))
            bloomFilter.set(indice);
    }

}

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

@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
        ParserState parserState) throws ReaderException {
    ApiConsumerConfig config = unmarshallConfig(t2FlowParser, configBean, "xstream", ApiConsumerConfig.class);

    Configuration configuration = new Configuration();
    configuration.setParent(parserState.getCurrentProfile());

    ObjectNode json = (ObjectNode) configuration.getJson();
    configuration.setType(ACTIVITY_URI.resolve("#Config"));

    json.put("apiConsumerDescription", config.getApiConsumerDescription());
    json.put("apiConsumerName", config.getApiConsumerName());
    json.put("description", config.getDescription());
    json.put("className", config.getClassName());
    json.put("methodName", config.getMethodName());

    ArrayNode parameterNames = json.arrayNode();
    json.put("parameterNames", parameterNames);
    for (String parameterName : config.getParameterNames().getString())
        parameterNames.add(parameterName);

    ArrayNode parameterDimensions = json.arrayNode();
    json.put("parameterDimensions", parameterDimensions);
    for (BigInteger parameterDimension : config.getParameterDimensions().getInt())
        parameterDimensions.add(parameterDimension.intValue());

    ArrayNode parameterTypes = json.arrayNode();
    json.put("parameterTypes", parameterTypes);
    for (String parameterType : config.getParameterTypes().getString())
        parameterTypes.add(parameterType);

    json.put("returnType", config.getReturnType());
    json.put("returnDimension", config.getReturnDimension().intValue());
    json.put("isMethodConstructor", config.isIsMethodConstructor());
    json.put("isMethodStatic", config.isIsMethodStatic());

    return configuration;
}

From source file:gemlite.core.internal.support.jpa.files.dao.GmBatchDaoImpl.java

@Override
public int countJobExecutions() {
    Query q = em.createNativeQuery("SELECT COUNT(1) from BATCH_JOB_EXECUTION");
    BigInteger count = (BigInteger) q.getSingleResult();
    return count.intValue();
}

From source file:gemlite.core.internal.support.jpa.files.dao.GmBatchDaoImpl.java

@Override
public int countRunningJob() {
    String countRunningJob = "select count(1) from batch_job_execution where status = 'STARTED'";
    Query query = em.createNativeQuery(countRunningJob);
    BigInteger count = (BigInteger) query.getSingleResult();
    return count.intValue();
}

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

@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
        ParserState parserState) throws ReaderException {
    SoaplabConfig soaplabConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", SoaplabConfig.class);

    Configuration configuration = new Configuration();
    configuration.setParent(parserState.getCurrentProfile());

    ObjectNode json = (ObjectNode) configuration.getJson();
    configuration.setType(scufl2Uri.resolve("#Config"));

    String endpoint = soaplabConfig.getEndpoint();
    if (endpoint == null || endpoint.isEmpty())
        throw new ReaderException("Soablab config has no endpoint set");
    json.put("endpoint", endpoint);

    double pollingBackoff = soaplabConfig.getPollingBackoff();
    json.put("pollingBackoff", pollingBackoff);

    BigInteger pollingInterval = soaplabConfig.getPollingInterval();
    if (pollingInterval != null)
        json.put("pollingInterval", pollingInterval.intValue());

    BigInteger pollingIntervalMax = soaplabConfig.getPollingIntervalMax();
    if (pollingIntervalMax != null)
        json.put("pollingIntervalMax", pollingIntervalMax.intValue());

    return configuration;
}

From source file:org.wso2.dss.sample.rdbms.FileServiceTestCase.java

@Test(groups = { "wso2.dss" })
public void testGetFileSize() throws DataServiceFault, RemoteException {

    log.info("Running FileServiceTestCase#testGetFileSize");
    FileService stub = new FileServiceStub(SERVICE_EPR);
    stub._getcreatenewfile("file6.txt", "txt");
    BigInteger value = stub._getgetfilesize("file6.txt")[0].getFileSize();
    assertTrue(value == null || value.intValue() == 0);
    DataHandler dh = new StringDataHandler("record1");
    stub._postappenddatatofile("file6.txt", dh);
    dh = new StringDataHandler("record2");
    stub._postappenddatatofile("file6.txt", dh);
    assertEquals(((stub._getgetfilesize("file6.txt")[0]).getFileSize()).intValue(), 14);

}

From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.ProjectsProcessorsConfiguration.java

/**
 * Processor for the project categories.
 *
 * @param projectId/*w ww. ja  v a 2  s.c  om*/
 *       Id of the project being synced.
 * @return the processor
 */
@Bean
@StepScope
public ProjectCategoryProcessor projectCategoriesProcessor(
        @Value("#{jobExecutionContext['mantis.loop.project_id']}") final BigInteger projectId) {

    final ProjectCategoryProcessor proc = new ProjectCategoryProcessor();
    if (projectId != null) {
        proc.setProjectId(projectId.intValue());
    }

    return proc;
}

From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.ProjectsProcessorsConfiguration.java

/**
 * Processor that builds the custom field bean.
 *
 * @param projectId/*w  w w  .  j  a v a 2s.  c  om*/
 *       Id of the project being synced.
 * @return the processor
 */
@Bean
@StepScope
public ProjectCustomFieldProcessor projectCustomFieldProcessor(
        @Value("#{jobExecutionContext['mantis.loop.project_id']}") final BigInteger projectId) {

    final ProjectCustomFieldProcessor proc = new ProjectCustomFieldProcessor();
    if (projectId != null) {
        proc.setProjectId(projectId.intValue());
    }

    return proc;
}