Example usage for org.apache.commons.lang ArrayUtils toObject

List of usage examples for org.apache.commons.lang ArrayUtils toObject

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toObject.

Prototype

public static Boolean[] toObject(boolean[] array) 

Source Link

Document

Converts an array of primitive booleans to objects.

Usage

From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java

/**
 * @see eionet.meta.dao.ISchemaSetDAO#getSchemaSetVersions(String, java.lang.String, int...)
 */// w ww  .  j  a  v  a 2  s.co m
@Override
public List<SchemaSet> getSchemaSetVersions(String userName, String continuityId, int... excludeIds) {

    if (StringUtils.isBlank(continuityId)) {
        throw new IllegalArgumentException("Continuity id must not be blank!");
    }

    String sql = "select * from T_SCHEMA_SET where WORKING_COPY=false and CONTINUITY_ID=:continuityId";
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("continuityId", continuityId);

    if (StringUtils.isBlank(userName)) {
        sql += " and REG_STATUS=:regStatus";
        params.put("regStatus", RegStatus.RELEASED.toString());
    }

    if (excludeIds != null && excludeIds.length > 0) {
        sql += " and SCHEMA_SET_ID not in (:excludeIds)";
        params.put("excludeIds", Arrays.asList(ArrayUtils.toObject(excludeIds)));
    }
    sql += " order by SCHEMA_SET_ID desc";

    List<SchemaSet> resultList = getNamedParameterJdbcTemplate().query(sql, params, new RowMapper<SchemaSet>() {
        @Override
        public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException {
            SchemaSet ss = new SchemaSet();
            ss.setId(rs.getInt("SCHEMA_SET_ID"));
            ss.setIdentifier(rs.getString("IDENTIFIER"));
            ss.setContinuityId(rs.getString("CONTINUITY_ID"));
            ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS")));
            ss.setWorkingCopy(rs.getBoolean("WORKING_COPY"));
            ss.setWorkingUser(rs.getString("WORKING_USER"));
            ss.setDateModified(rs.getTimestamp("DATE_MODIFIED"));
            ss.setUserModified(rs.getString("USER_MODIFIED"));
            ss.setComment(rs.getString("COMMENT"));
            ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID"));
            ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED"));
            return ss;
        }
    });

    return resultList;
}

From source file:de.unisb.cs.st.javalanche.mutation.runtime.testDriver.MutationTestDriver.java

private Set<Long> getThreadIds(long[] preIds) {
    long[] allThreadIds = threadMxBean.getAllThreadIds();
    List<Long> preList = Arrays.asList(ArrayUtils.toObject(preIds));
    Set<Long> result = new HashSet<Long>();
    for (long tid : allThreadIds) {
        if (!preList.contains(tid)) {
            result.add(tid);/*w  ww  .  j  a  v  a2s.com*/
        }
    }
    return result;
}

From source file:eionet.meta.dao.mysql.SchemaDAOImpl.java

/**
 * @see eionet.meta.dao.ISchemaDAO#getSchemaVersions(String, java.lang.String, int...)
 *//*  w ww .  jav  a  2s  .c om*/
@Override
public List<Schema> getSchemaVersions(String userName, String continuityId, int... excludeIds) {

    if (StringUtils.isBlank(continuityId)) {
        throw new IllegalArgumentException("Continuity id must not be blank!");
    }

    String sql = "select * from T_SCHEMA where (SCHEMA_SET_ID is null or SCHEMA_SET_ID<=0) and WORKING_COPY=false"
            + " and CONTINUITY_ID=:continuityId";
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("continuityId", continuityId);

    if (StringUtils.isBlank(userName)) {
        sql += " and REG_STATUS=:regStatus";
        params.put("regStatus", RegStatus.RELEASED.toString());
    }

    if (excludeIds != null && excludeIds.length > 0) {
        sql += " and SCHEMA_ID not in (:excludeIds)";
        params.put("excludeIds", Arrays.asList(ArrayUtils.toObject(excludeIds)));
    }
    sql += " order by SCHEMA_ID desc";

    List<Schema> resultList = getNamedParameterJdbcTemplate().query(sql, params, new RowMapper<Schema>() {
        @Override
        public Schema mapRow(ResultSet rs, int rowNum) throws SQLException {
            Schema ss = new Schema();
            ss.setId(rs.getInt("SCHEMA_ID"));
            ss.setSchemaSetId(rs.getInt("SCHEMA_SET_ID"));
            ss.setFileName(rs.getString("FILENAME"));
            ss.setContinuityId(rs.getString("CONTINUITY_ID"));
            ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS")));
            ss.setWorkingCopy(rs.getBoolean("WORKING_COPY"));
            ss.setWorkingUser(rs.getString("WORKING_USER"));
            ss.setDateModified(rs.getTimestamp("DATE_MODIFIED"));
            ss.setUserModified(rs.getString("USER_MODIFIED"));
            ss.setComment(rs.getString("COMMENT"));
            ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID"));
            ss.setOtherDocument(rs.getBoolean("OTHER_DOCUMENT"));
            return ss;
        }
    });

    return resultList;
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.rdata.RDATAFileReader.java

/**
  * Create UNF from Tabular File// w w w  .j ava2s .  c  o  m
  * This methods iterates through each column of the supplied data table and
  * invoked the 
  * @param DataTable table a rectangular data table
  * @return void
  */
private void createUNF(DataTable table) throws IOException {
    List<Integer> variableTypeList = getVariableTypeList(mDataTypes);
    String[] dateFormats = new String[mCaseQuantity];
    String[] unfValues = new String[mVarQuantity];
    String fileUNFvalue = null;

    // Set variable types
    // smd.setVariableTypeMinimal(ArrayUtils.toPrimitive(variableTypeList.toArray(new Integer[variableTypeList.size()])));

    int[] x = ArrayUtils.toPrimitive(variableTypeList.toArray(new Integer[variableTypeList.size()]));

    for (int k = 0; k < mVarQuantity; k++) {
        String unfValue, name = variableNameList.get(k);
        int varType = variableTypeList.get(k);

        Object[] varData = table.getData()[k];

        LOG.fine(String.format("RDATAFileReader: Column \"%s\" = %s", name, Arrays.deepToString(varData)));

        try {
            switch (varType) {
            case 0:
                Long[] integerEntries = new Long[varData.length];

                LOG.fine(k + ": " + name + " is numeric (integer)");

                if (smd.isBooleanVariable()[k]) {
                    // This is not a regular integer - but a boolean!
                    LOG.fine(k + ": " + name + " is NOT a simple integer - it's a logical (boolean)!");
                    Boolean[] booleanEntries = new Boolean[varData.length];
                    for (int i = 0; i < varData.length; i++) {
                        if (varData[i] == null || varData[i].equals("")) {
                            // Missing Value: 
                            booleanEntries[i] = null;
                        } else if (((String) varData[i]).equals("0")) {
                            booleanEntries[i] = false;
                        } else if (((String) varData[i]).equals("1")) {
                            booleanEntries[i] = true;
                        } else {
                            // Treat it as a missing value? 
                            booleanEntries[i] = null;
                            // TODO: 
                            // Should we throw an exception here instead? 
                        }

                        // We'll also need the integer values, to calculate
                        // the summary statistics: 
                        try {
                            integerEntries[i] = new Long((String) varData[i]);
                        } catch (Exception ex) {
                            integerEntries[i] = null;
                        }
                    }

                    unfValue = UNF5Util.calculateUNF(booleanEntries);
                    // TODO: 
                    // we've never calculated UNFs for Booleans before - 
                    // need to QA and verify that the values produced are correct.
                    // -- L.A.

                } else {
                    // Regular integer;
                    // Treat it as an array of Longs:
                    LOG.fine(k + ": " + name + " is a simple integer.");

                    for (int i = 0; i < varData.length; i++) {
                        try {
                            integerEntries[i] = new Long((String) varData[i]);
                        } catch (Exception ex) {
                            integerEntries[i] = null;
                        }
                    }

                    unfValue = UNF5Util.calculateUNF(integerEntries);

                    // UNF5Util.cal
                }

                // Summary/category statistics
                smd.getSummaryStatisticsTable().put(k,
                        ArrayUtils.toObject(StatHelper.calculateSummaryStatistics(integerEntries)));
                Map<String, Integer> catStat = StatHelper.calculateCategoryStatistics(integerEntries);
                smd.getCategoryStatisticsTable().put(variableNameList.get(k), catStat);
                smd.getNullValueCounts().put(variableNameList.get(k),
                        StatHelper.countNullValues(integerEntries));

                break;

            // If double
            case 1:
                LOG.fine(k + ": " + name + " is numeric (double)");
                // Convert array of Strings to array of Doubles
                Double[] doubleEntries = new Double[varData.length];

                for (int i = 0; i < varData.length; i++) {
                    try {
                        // Check for the special case of "NaN" - this is the R and DVN
                        // notation for the "Not A Number" value:
                        if (varData[i] != null && ((String) varData[i]).equals("NaN")) {
                            doubleEntries[i] = Double.NaN;
                            // "Inf" is another special case, notation for infinity, 
                            // positive and negative:
                        } else if (varData[i] != null && (((String) varData[i]).equals("Inf")
                                || ((String) varData[i]).equals("+Inf"))) {

                            doubleEntries[i] = Double.POSITIVE_INFINITY;
                        } else if (varData[i] != null && ((String) varData[i]).equals("-Inf")) {

                            doubleEntries[i] = Double.NEGATIVE_INFINITY;
                        } else {
                            // Missing Values don't need to be treated separately; these 
                            // are represented as empty strings in the TAB file; so 
                            // attempting to create a Double object from one will 
                            // throw an exception - which we are going to intercept 
                            // below. For the UNF and Summary Stats purposes, missing
                            // values are represented as NULLs. 
                            doubleEntries[i] = new Double((String) varData[i]);
                        }
                    } catch (Exception ex) {
                        LOG.fine(k + ": " + name + " dropping value " + (String) varData[i] + " (" + i
                                + "); replacing with null");
                        doubleEntries[i] = null;
                    }
                }

                LOG.fine("sumstat:double case=" + Arrays.deepToString(ArrayUtils
                        .toObject(StatHelper.calculateSummaryStatisticsContDistSample(doubleEntries))));

                // Save summary statistics:
                smd.getSummaryStatisticsTable().put(k, ArrayUtils
                        .toObject(StatHelper.calculateSummaryStatisticsContDistSample(doubleEntries)));

                unfValue = UNF5Util.calculateUNF(doubleEntries);

                break;

            case -1:
                LOG.fine(k + ": " + name + " is string");

                String[] stringEntries = new String[varData.length];//Arrays.asList(varData).toArray(new String[varData.length]);

                LOG.fine("string array passed to calculateUNF: " + Arrays.deepToString(stringEntries));

                //
                if (mFormatTable[k] == FORMAT_DATE || mFormatTable[k] == FORMAT_DATETIME) {
                    DateFormatter dateFormatter = new DateFormatter();

                    dateFormatter.setDateFormats(DATE_FORMATS);
                    dateFormatter.setTimeFormats(TIME_FORMATS);

                    for (int i = 0; i < varData.length; i++) {
                        DateWithFormatter entryDateWithFormat;

                        // If data is missing, treat this entry as just that - 
                        // a missing value. Just like for all the other data types, 
                        // this is represented by a null:
                        if (dateFormats[i] != null && (varData[i].equals("") || varData[i].equals(" "))) {
                            stringEntries[i] = dateFormats[i] = null;
                        } else {
                            entryDateWithFormat = dateFormatter.getDateWithFormat((String) varData[i]);
                            if (entryDateWithFormat == null) {
                                LOG.fine("ATTENTION: the supplied date/time string could not be parsed ("
                                        + (String) varData[i]);
                                throw new IOException(
                                        "Could not parse supplied date/time string: " + (String) varData[i]);
                            }
                            // Otherwise get the pattern
                            // entryDateWithFormat = dateFormatter.getDateWithFormat(stringEntries[i]);
                            stringEntries[i] = (String) varData[i];
                            dateFormats[i] = entryDateWithFormat.getFormatter().toPattern();

                        }
                    }

                    // Compute UNF
                    try {
                        LOG.fine("RDATAFileReader: strdata = " + Arrays.deepToString(stringEntries));
                        LOG.fine("RDATAFileReader: dateFormats = " + Arrays.deepToString(dateFormats));

                        unfValue = UNF5Util.calculateUNF(stringEntries, dateFormats);
                    } catch (Exception ex) {
                        LOG.warning("RDATAFileReader: UNF for variable " + name + " could not be computed!");
                        //unfValue = UNF5Util.calculateUNF(stringEntries);
                        //ex.printStackTrace();
                        throw ex;
                    }
                } else {
                    for (int i = 0; i < varData.length; i++) {
                        if (varData[i] == null) {
                            // Missing Value
                            stringEntries[i] = null;
                        } else {
                            stringEntries[i] = (String) varData[i];
                        }
                    }

                    unfValue = UNF5Util.calculateUNF(stringEntries);
                }

                smd.getSummaryStatisticsTable().put(k, StatHelper.calculateSummaryStatistics(stringEntries));
                Map<String, Integer> StrCatStat = StatHelper.calculateCategoryStatistics(stringEntries);
                smd.getCategoryStatisticsTable().put(variableNameList.get(k), StrCatStat);
                smd.getNullValueCounts().put(variableNameList.get(k),
                        StatHelper.countNullValues(stringEntries));

                break;

            default:
                unfValue = null;

            }

            //LOG.fine(String.format("RDATAFileReader: Column \"%s\" (UNF) = %s", name, unfValue));

            // Store UNF value
            unfValues[k] = unfValue;
        } catch (Exception ex) {
            LOG.fine("Exception caught while calculating UNF! " + ex.getMessage());
            ex.printStackTrace();
            throw new IOException("Exception caught while calculating UNF! " + ex.getMessage());
        }
        LOG.fine(String.format("RDATAFileReader: Column \"%s\" (UNF) = %s", name, unfValues[k]));

    }

    try {
        fileUNFvalue = UNF5Util.calculateUNF(unfValues);
    } catch (Exception ex) {
        ex.printStackTrace();
        LOG.fine("Exception caught while calculating the combined UNF for the data set! " + ex.getMessage());
        throw new IOException(
                "Exception caught while calculating the combined UNF for the data set! " + ex.getMessage());
    }
    mCsvDataTable.setUnf(unfValues);
    mCsvDataTable.setFileUnf(fileUNFvalue);

    // Set meta-data to make it look like a SAV file
    // smd.setVariableStorageType(null);
    // smd.setDecimalVariables(mDecimalVariableSet);

    boolean[] b = smd.isContinuousVariable();

    for (int k = 0; k < b.length; k++) {
        String s = b[k] ? "True" : "False";
        LOG.fine(k + " = " + s);
    }

    smd.setVariableUNF(unfValues);
    smd.getFileInformation().put("fileUNF", fileUNFvalue);
}

From source file:com.flexive.core.storage.genericSQL.GenericTreeStorageSpreaded.java

/**
 * {@inheritDoc}/*from  w w w  . ja va2s .c o  m*/
 */
@Override
public void activateNode(Connection con, SequencerEngine seq, ContentEngine ce, FxTreeMode mode,
        final long nodeId, boolean activateContents) throws FxApplicationException {
    if (mode == FxTreeMode.Live) //Live tree can not be activated!
        return;
    long ids[] = getIdChain(con, mode, nodeId); //all id's up to the root node
    acquireLocksForUpdate(con, mode, Arrays.asList(ArrayUtils.toObject(ids)));
    try {
        // lock node in live tree including all children (which *can* be removed if they were removed in the edit tree)
        acquireLocksForUpdate(con, FxTreeMode.Live,
                selectDirectChildNodeIds(con, FxTreeMode.Live, nodeId, true));
    } catch (SQLException e) {
        throw new FxDbException(e);
    }

    for (long id : ids) {
        if (id == ROOT_NODE)
            continue;
        FxTreeNode srcNode = getNode(con, mode, id);
        //check if the node already exists in the live tree
        if (exists(con, FxTreeMode.Live, id)) {
            //Move and setData will not do anything if the node is already in its correct place and
            move(con, seq, FxTreeMode.Live, id, srcNode.getParentNodeId(), srcNode.getPosition());
            setData(con, FxTreeMode.Live, id, srcNode.getData());
        } else {
            createNode(con, seq, ce, FxTreeMode.Live, srcNode.getId(), srcNode.getParentNodeId(),
                    srcNode.getName(), srcNode.getLabel(), srcNode.getPosition(), srcNode.getReference(),
                    srcNode.getData(), activateContents);
        }

        // Remove all deleted direct child nodes
        Statement stmt = null;
        Statement stmt2 = null;
        try {
            stmt = con.createStatement();
            stmt2 = con.createStatement();
            if (StorageManager.isDisableIntegrityTransactional()) {
                stmt2.execute(StorageManager.getReferentialIntegrityChecksStatement(false));
            }
            try {
                ResultSet rs = stmt.executeQuery(
                        "SELECT DISTINCT tl.ID FROM " + getTable(FxTreeMode.Live) + " tl " + "LEFT JOIN "
                                + getTable(FxTreeMode.Edit) + " te ON tl.ID=te.ID WHERE te.ID=null AND "
                                + "te.PARENT=" + nodeId + " AND tl.PARENT=" + nodeId);
                while (rs != null && rs.next()) {
                    long deleteId = rs.getLong(1);
                    //                        System.out.println("==> deleted:"+deleteId);
                    acquireLocksForUpdate(con, FxTreeMode.Live, Arrays.asList(deleteId));
                    stmt2.addBatch("DELETE FROM " + getTable(FxTreeMode.Live) + " WHERE ID=" + deleteId);

                }
                stmt2.addBatch("UPDATE " + getTable(FxTreeMode.Live) + " SET MODIFIED_AT="
                        + System.currentTimeMillis());
                stmt2.executeBatch();
            } finally {
                if (StorageManager.isDisableIntegrityTransactional()) {
                    stmt2.execute(StorageManager.getReferentialIntegrityChecksStatement(true));
                }
            }
        } catch (SQLException e) {
            throw new FxTreeException("ex.tree.activate.failed", nodeId, false, e.getMessage());
        } finally {
            try {
                if (stmt != null)
                    stmt.close();
            } catch (Exception exc) {
                //ignore
            }
            try {
                if (stmt2 != null)
                    stmt2.close();
            } catch (Exception exc) {
                //ignore
            }
        }
        clearDirtyFlag(con, mode, nodeId);
    }
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.spss.SPSSFileReader.java

private String getUNF(Object[] varData, String[] dateFormats, int variableType, String unfVersionNumber,
        int variablePosition)
        throws NumberFormatException, UnfException, IOException, NoSuchAlgorithmException {
    String unfValue = null;//from  w w  w.  j av  a 2s .co  m

    dbgLog.fine("variableType=" + variableType);
    dbgLog.finer("unfVersionNumber=" + unfVersionNumber);
    dbgLog.fine("variablePosition=" + variablePosition);
    dbgLog.fine("variableName=" + variableNameList.get(variablePosition));

    switch (variableType) {
    case 0:
        // Integer (Long):

        dbgLog.fine("Integer case");

        // Convert array of Strings to array of Longs
        Long[] ldata = new Long[varData.length];
        for (int i = 0; i < varData.length; i++) {
            //if (varData[i] != null) {
            try {
                ldata[i] = new Long((String) varData[i]);
            } catch (Exception ex) {
                ldata[i] = null;
            }
            //}
        }
        unfValue = UNF5Util.calculateUNF(ldata);
        dbgLog.finer("integer:unfValue=" + unfValue);

        //dbgLog.finer("sumstat:long case=" + Arrays.deepToString(
        //        ArrayUtils.toObject(StatHelper.calculateSummaryStatistics(ldata))));

        smd.getSummaryStatisticsTable().put(variablePosition,
                ArrayUtils.toObject(StatHelper.calculateSummaryStatistics(ldata)));

        Map<String, Integer> catStat = StatHelper.calculateCategoryStatistics(ldata);
        smd.getCategoryStatisticsTable().put(variableNameList.get(variablePosition), catStat);

        break;

    case 1:
        // Double:

        dbgLog.finer("double case");

        // Convert array of Strings to array of Doubles
        Double[] ddata = new Double[varData.length];
        for (int i = 0; i < varData.length; i++) {
            //if (varData[i]!=null) {
            try {
                ddata[i] = new Double((String) varData[i]);
            } catch (Exception ex) {
                ddata[i] = null;
            }
            //}
        }
        unfValue = UNF5Util.calculateUNF(ddata);
        dbgLog.finer("double:unfValue=" + unfValue);
        smd.getSummaryStatisticsTable().put(variablePosition,
                ArrayUtils.toObject(StatHelper.calculateSummaryStatisticsContDistSample(ddata)));

        break;
    case -1:
        // String:
        //
        // i.e., this is something *stored* as string; it may still be
        // a more complex data type than just a string of characters.
        // Namely, it can be some date or time type that we support.
        // These should be handled differently when calculating the
        // UNFs.

        dbgLog.finer("string case");

        String[] strdata = Arrays.asList(varData).toArray(new String[varData.length]);
        dbgLog.finer("string array passed to calculateUNF: " + Arrays.deepToString(strdata));

        if (dateFormats != null) {

            for (int i = 0; i < varData.length; i++) {
                if (dateFormats[i] != null && (strdata[i].equals("") || strdata[i].equals(" "))) {
                    strdata[i] = null;
                    dateFormats[i] = null;
                }
            }

            unfValue = UNF5Util.calculateUNF(strdata, dateFormats);
        } else {
            unfValue = UNF5Util.calculateUNF(strdata);
        }

        dbgLog.finer("string:unfValue=" + unfValue);

        smd.getSummaryStatisticsTable().put(variablePosition, StatHelper.calculateSummaryStatistics(strdata));

        Map<String, Integer> StrCatStat = StatHelper.calculateCategoryStatistics(strdata);
        //out.println("catStat="+StrCatStat);

        smd.getCategoryStatisticsTable().put(variableNameList.get(variablePosition), StrCatStat);

        break;
    default:
        dbgLog.fine("unknown variable type found");
        String errorMessage = "unknow variable Type found at varData section";
        throw new IllegalArgumentException(errorMessage);

    } // switch

    dbgLog.fine("unfvalue(last)=" + unfValue);
    return unfValue;
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.ddi.DDIFileReader.java

private String getUNF(Object[] varData, String[] dateFormats, int variableType, String unfVersionNumber,
        int variablePosition)
        throws NumberFormatException, UnfException, IOException, NoSuchAlgorithmException {
    String unfValue = null;//from  w  ww.j  a va 2 s.c om

    dbgLog.fine("variableType=" + variableType);
    dbgLog.finer("unfVersionNumber=" + unfVersionNumber);
    dbgLog.fine("variablePosition=" + variablePosition);
    //dbgLog.fine("variableName="+variableNameList.get(variablePosition));

    switch (variableType) {
    case 0:
        // Integer (Long):

        dbgLog.fine("Integer case");

        // Convert array of Strings to array of Longs
        Long[] ldata = new Long[varData.length];
        for (int i = 0; i < varData.length; i++) {
            //if (varData[i] != null) {
            try {
                ldata[i] = new Long((String) varData[i]);
            } catch (Exception ex) {
                ldata[i] = null;
            }
            //}
        }
        unfValue = UNF5Util.calculateUNF(ldata);
        dbgLog.finer("integer:unfValue=" + unfValue);

        //dbgLog.finer("sumstat:long case=" + Arrays.deepToString(
        //        ArrayUtils.toObject(StatHelper.calculateSummaryStatistics(ldata))));

        smd.getSummaryStatisticsTable().put(variablePosition,
                ArrayUtils.toObject(StatHelper.calculateSummaryStatistics(ldata)));

        Map<String, Integer> catStat = StatHelper.calculateCategoryStatistics(ldata);
        smd.getCategoryStatisticsTable().put(variableNameList.get(variablePosition), catStat);

        break;

    case 1:
        // Double:

        dbgLog.finer("double case");

        // Convert array of Strings to array of Doubles
        Double[] ddata = new Double[varData.length];
        for (int i = 0; i < varData.length; i++) {
            //if (varData[i]!=null) {
            try {
                ddata[i] = new Double((String) varData[i]);
            } catch (Exception ex) {
                ddata[i] = null;
            }
            //}
        }
        unfValue = UNF5Util.calculateUNF(ddata);
        dbgLog.finer("double:unfValue=" + unfValue);
        smd.getSummaryStatisticsTable().put(variablePosition,
                ArrayUtils.toObject(StatHelper.calculateSummaryStatisticsContDistSample(ddata)));

        break;
    case -1:
        // String:
        //
        // i.e., this is something *stored* as string; it may still be
        // a more complex data type than just a string of characters.
        // Namely, it can be some date or time type that we support.
        // These should be handled differently when calculating the
        // UNFs.

        dbgLog.finer("string case");

        String[] strdata = Arrays.asList(varData).toArray(new String[varData.length]);
        dbgLog.finer("string array passed to calculateUNF: " + Arrays.deepToString(strdata));

        if (dateFormats != null) {

            for (int i = 0; i < varData.length; i++) {
                if (dateFormats[i] != null && (strdata[i].equals("") || strdata[i].equals(" "))) {
                    strdata[i] = null;
                    dateFormats[i] = null;
                }
            }

            unfValue = UNF5Util.calculateUNF(strdata, dateFormats);
        } else {
            unfValue = UNF5Util.calculateUNF(strdata);
        }

        dbgLog.finer("string:unfValue=" + unfValue);

        smd.getSummaryStatisticsTable().put(variablePosition, StatHelper.calculateSummaryStatistics(strdata));

        Map<String, Integer> StrCatStat = StatHelper.calculateCategoryStatistics(strdata);
        //out.println("catStat="+StrCatStat);

        smd.getCategoryStatisticsTable().put(variableNameList.get(variablePosition), StrCatStat);

        break;
    default:
        dbgLog.fine("unknown variable type found");
        String errorMessage = "unknow variable Type found at varData section";
        throw new IllegalArgumentException(errorMessage);

    } // switch

    dbgLog.fine("unfvalue(last)=" + unfValue);
    return unfValue;
}

From source file:com.opengamma.analytics.financial.curve.CurveConstructionXCcyTest.java

private static Pair<YieldCurveBundle, Double[]> makeUnit(InstrumentDerivative[] instruments, double[] initGuess,
        LinkedHashMap<String, GeneratorYDCurve> curveGenerators, YieldCurveBundle knownData,
        final AbstractInstrumentDerivativeVisitor<YieldCurveBundle, Double> calculator,
        final AbstractInstrumentDerivativeVisitor<YieldCurveBundle, InterestRateCurveSensitivity> sensitivityCalculator) {
    final MultipleYieldCurveFinderGeneratorDataBundle data = new MultipleYieldCurveFinderGeneratorDataBundle(
            instruments, knownData, curveGenerators);
    final Function1D<DoubleMatrix1D, DoubleMatrix1D> curveCalculator = new MultipleYieldCurveFinderGeneratorFunction(
            calculator, data);//from   w  w  w.  j a v  a  2  s  .c o m
    final Function1D<DoubleMatrix1D, DoubleMatrix2D> jacobianCalculator = new MultipleYieldCurveFinderGeneratorJacobian(
            new ParameterSensitivityCalculator(sensitivityCalculator), data);
    final double[] parameters = ROOT_FINDER
            .getRoot(curveCalculator, jacobianCalculator, new DoubleMatrix1D(initGuess)).getData();
    final YieldCurveBundle newCurves = data.getBuildingFunction().evaluate(new DoubleMatrix1D(parameters));
    return new ObjectsPair<YieldCurveBundle, Double[]>(newCurves, ArrayUtils.toObject(parameters));
}

From source file:com.flexive.ejb.beans.AccountEngineBean.java

/**
 * Helper function./*from  w w w .  j  a va2s .co m*/
 *
 * @param ticket      the ticket of the calling user
 * @param name        the name filter
 * @param loginName   the login name filter
 * @param email       the email filter
 * @param isActive    the is active filter
 * @param isConfirmed the is confirmed filter
 * @param mandatorId  the mandator id filter
 * @param isInRole    the role filter
 * @param isInGroup   the group filter
 * @param isCountOnly the "count only" option
 * @return the sql filter String
 * @throws FxNoAccessException if the user does not have access
 */
private String _buildSearchStmt(UserTicket ticket, String name, String loginName, String email,
        Boolean isActive, Boolean isConfirmed, Long mandatorId, int[] isInRole, long[] isInGroup,
        boolean isCountOnly) throws FxNoAccessException {

    // Do no filter GROUP_UNDEFINED (=null value)
    if (isInGroup != null) {
        isInGroup = ArrayUtils.removeElement(isInGroup, UserGroup.GROUP_UNDEFINED);
    }

    // Determine if group/role filter options are enabled
    final boolean filterByGrp = (isInGroup != null && isInGroup.length > 0);
    final boolean filterByRole = (isInRole != null && isInRole.length > 0);

    // Determine the mandator, and check its security
    long _mandatorId = (mandatorId == null) ? ticket.getMandatorId() : mandatorId;
    if (_mandatorId < 0 && !ticket.isGlobalSupervisor())
        throw new FxNoAccessException(LOG, "ex.account.loadFailed.wrongMandator");

    // Do case insensitive search
    if (email != null)
        email = email.toUpperCase();
    if (name != null)
        name = name.toUpperCase();
    if (loginName != null)
        loginName = loginName.toUpperCase();

    final String TRUE = StorageManager.getBooleanTrueExpression();
    String curSql = "SELECT " + "" + (isCountOnly ? "COUNT(*)" :
    //   1      2         3              4            5        6
            "usr.ID,usr.EMAIL,usr.CONTACT_ID,usr.MANDATOR,usr.LANG,usr.VALID_FROM," +
            //   7            8               9            10             11
                    "usr.VALID_TO,usr.DESCRIPTION,usr.USERNAME,usr.LOGIN_NAME,usr.IS_ACTIVE," +
                    //   12               13                   14
                    "usr.IS_VALIDATED,usr.ALLOW_MULTILOGIN,usr.UPDATETOKEN," +
                    //   15             16             17              18
                    "usr.CREATED_BY,usr.CREATED_AT,usr.MODIFIED_BY,usr.MODIFIED_AT," +
                    // 19           20
                    "usr.REST_TOKEN,usr.REST_EXPIRES")
            + " FROM " + TBL_ACCOUNTS + " usr WHERE ID!=" + Account.NULL_ACCOUNT + " "
            + ((_mandatorId == -1) ? ""
                    : " AND (usr.MANDATOR=" + _mandatorId + " OR usr.ID<=" + Account.USER_GLOBAL_SUPERVISOR
                            + ")")
            + ((name != null && name.length() > 0) ? " AND UPPER(usr.USERNAME) LIKE '%" + name + "%'" : "")
            + ((loginName != null && loginName.length() > 0)
                    ? " AND UPPER(usr.LOGIN_NAME) LIKE '%" + loginName + "%'"
                    : "")
            + ((email != null && email.length() > 0) ? " AND UPPER(usr.EMAIL) LIKE '%" + email + "%'" : "")
            + ((isActive != null) ? " AND usr.IS_ACTIVE" + (isActive ? "=" : "<>") + TRUE : "")
            + ((isConfirmed != null) ? " AND usr.IS_VALIDATED" + (isConfirmed ? "=" : "<>") + TRUE : "") +

            // Group link
            ((!filterByGrp) ? ""
                    : " AND EXISTS (SELECT 1 FROM " + TBL_ASSIGN_GROUPS
                            + " grp WHERE grp.ACCOUNT=usr.ID AND grp.USERGROUP IN ("
                            + StringUtils.join(ArrayUtils.toObject(isInGroup), ',') + "))")
            +

            // Role link
            ((!filterByRole) ? ""
                    : " AND (EXISTS (SELECT 1 FROM " + TBL_ROLE_MAPPING
                            + " rol WHERE rol.ACCOUNT=usr.ID and rol.ROLE IN ("
                            + StringUtils.join(ArrayUtils.toObject(isInRole), ',') + ")) OR "
                            + "EXISTS (SELECT 1 FROM " + TBL_ROLE_MAPPING + " rol, " + TBL_ASSIGN_GROUPS
                            + " grp WHERE "
                            + "grp.ACCOUNT=usr.ID AND rol.USERGROUP=grp.USERGROUP AND rol.ROLE IN ("
                            + StringUtils.join(ArrayUtils.toObject(isInRole), ',') + ")))")
            +

            // Order
            (isCountOnly ? "" : " ORDER by usr.LOGIN_NAME");
    if (LOG.isDebugEnabled())
        LOG.debug(curSql);
    return curSql;
}

From source file:de.minigameslib.mclib.api.config.ConfigurationValueInterface.java

@Override
default boolean[] getBooleanList() {
    final List<Boolean> list = ConfigurationTool.calculate(this, ConfigurationBoolList.class,
            ConfigurationTool.boolListPath(),
            (val, configs, config, lib, minigame, path) -> minigame.getConfig(configs.file())
                    .getBooleanList(path),
            (val, configs, config, lib, minigame, path) -> Arrays
                    .asList(ArrayUtils.toObject(config.defaultValue())));
    final boolean[] result = new boolean[list.size()];
    for (int i = 0; i < result.length; i++) {
        result[i] = list.get(i);//from  ww w  . jav  a 2 s .c  o m
    }
    return result;
}