Example usage for org.apache.commons.lang3 ArrayUtils toPrimitive

List of usage examples for org.apache.commons.lang3 ArrayUtils toPrimitive

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ArrayUtils toPrimitive.

Prototype

public static boolean[] toPrimitive(final Boolean[] array) 

Source Link

Document

Converts an array of object Booleans to primitives.

This method returns null for a null input array.

Usage

From source file:edu.stanford.slac.archiverappliance.PB.data.StatusSeverityTest.java

private DBR getJCASampleValue(ArchDBRTypes type, int value, int severity, int status) {
    switch (type) {
    case DBR_SCALAR_STRING:
        DBR_TIME_String retvalss = new DBR_TIME_String(new String[] { Integer.toString(value) });
        retvalss.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvalss.setSeverity(severity);/*from w  w  w  .j a va  2 s .  c o m*/
        retvalss.setStatus(status);
        return retvalss;
    case DBR_SCALAR_SHORT:
        DBR_TIME_Short retvalsh;
        if (0 <= value && value < 1000) {
            // Check for some numbers around the minimum value
            retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MIN_VALUE + value) });
        } else if (1000 <= value && value < 2000) {
            // Check for some numbers around the maximum value
            retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MAX_VALUE - (value - 1000)) });
        } else {
            // Check for some numbers around 0
            retvalsh = new DBR_TIME_Short(new short[] { (short) (value - 2000) });
        }
        retvalsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvalsh.setSeverity(severity);
        retvalsh.setStatus(status);
        return retvalsh;
    case DBR_SCALAR_FLOAT:
        DBR_TIME_Float retvalfl;
        if (0 <= value && value < 1000) {
            // Check for some numbers around the minimum value
            retvalfl = new DBR_TIME_Float(new float[] { Float.MIN_VALUE + value });
        } else if (1000 <= value && value < 2000) {
            // Check for some numbers around the maximum value
            retvalfl = new DBR_TIME_Float(new float[] { Float.MAX_VALUE - (value - 1000) });
        } else {
            // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits
            retvalfl = new DBR_TIME_Float(new float[] { (value - 2000.0f) / value });
        }
        retvalfl.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvalfl.setSeverity(severity);
        retvalfl.setStatus(status);
        return retvalfl;
    case DBR_SCALAR_ENUM:
        DBR_TIME_Enum retvalen;
        retvalen = new DBR_TIME_Enum(new short[] { (short) (value) });
        retvalen.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvalen.setSeverity(severity);
        retvalen.setStatus(status);
        return retvalen;
    case DBR_SCALAR_BYTE:
        DBR_TIME_Byte retvalby;
        retvalby = new DBR_TIME_Byte(new byte[] { ((byte) (value % 255)) });
        retvalby.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvalby.setSeverity(severity);
        retvalby.setStatus(status);
        return retvalby;
    case DBR_SCALAR_INT:
        DBR_TIME_Int retvalint;
        if (0 <= value && value < 1000) {
            // Check for some numbers around the minimum value
            retvalint = new DBR_TIME_Int(new int[] { Integer.MIN_VALUE + value });
        } else if (1000 <= value && value < 2000) {
            // Check for some numbers around the maximum value
            retvalint = new DBR_TIME_Int(new int[] { Integer.MAX_VALUE - (value - 1000) });
        } else {
            // Check for some numbers around 0
            retvalint = new DBR_TIME_Int(new int[] { (value - 2000) });
        }
        retvalint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvalint.setSeverity(severity);
        retvalint.setStatus(status);
        return retvalint;
    case DBR_SCALAR_DOUBLE:
        DBR_TIME_Double retvaldb;
        if (0 <= value && value < 1000) {
            // Check for some numbers around the minimum value
            retvaldb = new DBR_TIME_Double(new double[] { (Double.MIN_VALUE + value) });
        } else if (1000 <= value && value < 2000) {
            // Check for some numbers around the maximum value
            retvaldb = new DBR_TIME_Double(new double[] { (Double.MAX_VALUE - (value - 1000)) });
        } else {
            // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits
            retvaldb = new DBR_TIME_Double(new double[] { ((value - 2000.0) / (value * 1000000)) });
        }
        retvaldb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvaldb.setSeverity(severity);
        retvaldb.setStatus(status);
        return retvaldb;
    case DBR_WAVEFORM_STRING:
        DBR_TIME_String retvst;
        // Varying number of copies of a typical value
        retvst = new DBR_TIME_String(
                Collections.nCopies(value, Integer.toString(value)).toArray(new String[0]));
        retvst.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvst.setSeverity(severity);
        retvst.setStatus(status);
        return retvst;
    case DBR_WAVEFORM_SHORT:
        DBR_TIME_Short retvsh;
        retvsh = new DBR_TIME_Short(
                ArrayUtils.toPrimitive(Collections.nCopies(1, (short) value).toArray(new Short[0])));
        retvsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvsh.setSeverity(severity);
        retvsh.setStatus(status);
        return retvsh;
    case DBR_WAVEFORM_FLOAT:
        DBR_TIME_Float retvf;
        // Varying number of copies of a typical value
        retvf = new DBR_TIME_Float(ArrayUtils.toPrimitive(
                Collections.nCopies(value, (float) Math.cos(value * Math.PI / 3600)).toArray(new Float[0])));
        retvf.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvf.setSeverity(severity);
        retvf.setStatus(status);
        return retvf;
    case DBR_WAVEFORM_ENUM:
        DBR_TIME_Enum retven;
        retven = new DBR_TIME_Enum(
                ArrayUtils.toPrimitive(Collections.nCopies(1024, (short) value).toArray(new Short[0])));
        retven.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retven.setSeverity(severity);
        retven.setStatus(status);
        return retven;
    case DBR_WAVEFORM_BYTE:
        DBR_TIME_Byte retvb;
        // Large number of elements in the array
        retvb = new DBR_TIME_Byte(ArrayUtils
                .toPrimitive(Collections.nCopies(65536 * value, ((byte) (value % 255))).toArray(new Byte[0])));
        retvb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvb.setSeverity(severity);
        retvb.setStatus(status);
        return retvb;
    case DBR_WAVEFORM_INT:
        DBR_TIME_Int retvint;
        // Varying number of copies of a typical value
        retvint = new DBR_TIME_Int(
                ArrayUtils.toPrimitive(Collections.nCopies(value, value * value).toArray(new Integer[0])));
        retvint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvint.setSeverity(severity);
        retvint.setStatus(status);
        return retvint;
    case DBR_WAVEFORM_DOUBLE:
        DBR_TIME_Double retvd;
        // Varying number of copies of a typical value
        retvd = new DBR_TIME_Double(ArrayUtils.toPrimitive(
                Collections.nCopies(value, Math.sin(value * Math.PI / 3600)).toArray(new Double[0])));
        retvd.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value));
        retvd.setSeverity(severity);
        retvd.setStatus(status);
        return retvd;
    case DBR_V4_GENERIC_BYTES:
        throw new RuntimeException("Currently don't support " + type + " when generating sample data");
    default:
        throw new RuntimeException("We seemed to have missed a DBR type when generating sample data");
    }
}

From source file:com.github.jessemull.microflex.util.IntegerUtil.java

/**
 * Converts a list of integers to an array of shorts.
 * @param    List<Integer>    list of integers
 * @return                    array of shorts
 *//*from www . jav  a  2s.c  om*/
public static short[] toShortArray(List<Integer> list) {

    for (Integer val : list) {
        if (!OverFlowUtil.shortOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
    }

    return ArrayUtils.toPrimitive(list.toArray(new Short[list.size()]));

}

From source file:net.larry1123.elec.util.test.config.AbstractConfigTest.java

public void FloatArrayListTest(String fieldName, Field testField) {
    try {//from  w  w  w  .  j  av  a 2s  .  co  m
        //noinspection unchecked,unchecked
        float[] testFieldValue = ArrayUtils.toPrimitive(((ArrayList<Float>) testField.get(getConfigBase()))
                .toArray(new Float[((ArrayList<Float>) testField.get(getConfigBase())).size()]));
        Assert.assertTrue(ArrayUtils.isEquals(getPropertiesFile().getFloatArray(fieldName), testFieldValue));
    } catch (IllegalAccessException e) {
        assertFailFieldError(fieldName);
    }
}

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Converts a list of doubles to an array of integers.
 * @param    List<Double>    list of doubles
 * @return                   array of integers
 *///from w  w w. ja v a2s .c om
public static int[] toIntArray(List<Double> list) {

    for (Double val : list) {
        if (!OverFlowUtil.intOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
    }

    return ArrayUtils.toPrimitive(list.toArray(new Integer[list.size()]));

}

From source file:Query8Servlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w  w w .j  a v a 2 s.  c  o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Connection connection = null;
    Statement stmt = null;

    String patientswithAllSqlStat = null;
    String patientswithoutAllSqlStat = null;

    ResultSet rsetForALL = null;
    ResultSet rsetForNOTALL = null;

    String patientID = null;
    double expValue = 0;
    List<Double> exprValuesForPatientID = null;

    Map<String, List<Double>> patientToExpValueALL = new HashMap<String, List<Double>>();
    Map<String, List<Double>> patientToExpValueNOTALL = new HashMap<String, List<Double>>();

    //Variables for average correlation
    int i, j;
    double correlation = 0;

    Set<String> patientsForALLSet = null;
    String[] patientsForALL = null;
    Set<String> patientsForNOTALLSet = null;
    String[] patientsForNOTALL = null;

    Set<String> patientsForTestCaseSet = null;
    String[] patientsForTestCase = null;

    List<Double> patientAllExprValues = null;
    Double[] patientAllExprValuesArr = null;
    List<Double> patientNotAllExprValues = null;
    Double[] patientNotAllExprValuesArr = null;
    List<Double> testPatientExprValues = null;
    Double[] testPatientExprValuesArr = null;

    JSONObject diseaseClassification = new JSONObject();
    JSONArray testResults = new JSONArray();

    response.setContentType("application/json");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        Class.forName("oracle.jdbc.driver.OracleDriver");

        connection = DriverManager.getConnection("jdbc:oracle:thin:@VIVEK:1521/ORCL", "system", "vivek");

        stmt = connection.createStatement();

        patientswithAllSqlStat = "SELECT C.P_ID, M.EXPRESSION FROM MICROARRAY_FACT M, PROBE P, "
                + "CLINICAL_FACT C WHERE M.PB_ID = P.PB_ID AND M.S_ID = C.S_ID "
                + "AND C.P_ID IN (SELECT P_ID FROM CLINICAL_FACT, DISEASE "
                + "WHERE CLINICAL_FACT.DS_ID = DISEASE.DS_ID AND NAME = 'ALL') "
                + "AND P.USER_ID IN(65772884,17144710,31997186,85557586,11333636,"
                + "41333415,45926811,13947282,83398521,23552119,"
                + "74496827,24984526,28863379,88257558,31308500,"
                + "41464216,43866587,60661836,37998407,94113401,"
                + "88596261,48199244,69156037,4826120,1433276,"
                + "16073088,75492172,58672549,87592194,38422427,"
                + "58792011,15295292,21633757,89697658,97606543,"
                + "18493181,75434512,72920004,52948490,53478188,40567338)";

        patientswithoutAllSqlStat = "SELECT C.P_ID, M.EXPRESSION FROM MICROARRAY_FACT M, PROBE P, "
                + "CLINICAL_FACT C WHERE M.PB_ID = P.PB_ID AND M.S_ID = C.S_ID "
                + "AND C.P_ID IN (SELECT P_ID FROM CLINICAL_FACT, DISEASE "
                + "WHERE CLINICAL_FACT.DS_ID = DISEASE.DS_ID AND NAME <> 'ALL') "
                + "AND P.USER_ID IN(65772884,17144710,31997186,85557586,11333636,"
                + "41333415,45926811,13947282,83398521,23552119,"
                + "74496827,24984526,28863379,88257558,31308500,"
                + "41464216,43866587,60661836,37998407,94113401,"
                + "88596261,48199244,69156037,4826120,1433276,"
                + "16073088,75492172,58672549,87592194,38422427,"
                + "58792011,15295292,21633757,89697658,97606543,"
                + "18493181,75434512,72920004,52948490,53478188,40567338)";

        //Executing the query for ALL
        rsetForALL = stmt.executeQuery(patientswithAllSqlStat);

        //Converting the result set for "ALL" to the map
        while (rsetForALL.next()) {
            patientID = rsetForALL.getString(1);
            expValue = rsetForALL.getDouble(2);

            if (patientToExpValueALL.get(patientID) != null) {
                exprValuesForPatientID = patientToExpValueALL.get(patientID);
            } else {
                exprValuesForPatientID = new ArrayList<Double>();
            }

            exprValuesForPatientID.add(expValue);
            patientToExpValueALL.put(patientID, exprValuesForPatientID);
        }

        //Executing the query for NOT ALL
        rsetForNOTALL = stmt.executeQuery(patientswithoutAllSqlStat);

        //Converting the result set for "NOT ALL" to the map
        while (rsetForNOTALL.next()) {
            patientID = rsetForNOTALL.getString(1);
            expValue = rsetForNOTALL.getDouble(2);

            if (patientToExpValueNOTALL.get(patientID) != null) {
                exprValuesForPatientID = patientToExpValueNOTALL.get(patientID);
            } else {
                exprValuesForPatientID = new ArrayList<Double>();
            }

            exprValuesForPatientID.add(expValue);
            patientToExpValueNOTALL.put(patientID, exprValuesForPatientID);
        }

        //Getting the information of test cases from the file
        Map<String, List<Double>> testPatientsToExprValues = getTestCaseInformation();

        //Getting the data structures ready for calculating P value
        patientsForALLSet = patientToExpValueALL.keySet();
        patientsForALL = new String[patientsForALLSet.size()];
        patientsForALLSet.toArray(patientsForALL);

        patientsForNOTALLSet = patientToExpValueNOTALL.keySet();
        patientsForNOTALL = new String[patientsForNOTALLSet.size()];
        patientsForNOTALLSet.toArray(patientsForNOTALL);

        patientsForTestCaseSet = testPatientsToExprValues.keySet();
        patientsForTestCase = new String[patientsForTestCaseSet.size()];
        patientsForTestCaseSet.toArray(patientsForTestCase);

        //Iterating through the test patients to calculate ra's and rb's
        for (i = 0; i < patientsForTestCase.length; i++) {

            testPatientExprValues = testPatientsToExprValues.get(patientsForTestCase[i]);
            testPatientExprValuesArr = new Double[testPatientExprValues.size()];
            testPatientExprValues.toArray(testPatientExprValuesArr);

            //Initializing the test patient's correlation array with the two groups
            double[] correlation_ra = new double[patientsForALL.length];
            double[] correlation_rb = new double[patientsForNOTALL.length];

            //Calculating the correlation for between ALL
            for (j = 0; j < patientsForALL.length; j++) {

                patientAllExprValues = patientToExpValueALL.get(patientsForALL[j]);
                patientAllExprValuesArr = new Double[patientAllExprValues.size()];
                ;
                patientAllExprValues.toArray(patientAllExprValuesArr);

                correlation = new PearsonsCorrelation().correlation(
                        ArrayUtils.toPrimitive(patientAllExprValuesArr),
                        ArrayUtils.toPrimitive(testPatientExprValuesArr));
                correlation_ra[j] = correlation;
            }

            //Calculating the correlation for between ALL and AML
            for (j = 0; j < patientsForNOTALL.length; j++) {
                patientNotAllExprValues = patientToExpValueNOTALL.get(patientsForNOTALL[j]);
                patientNotAllExprValuesArr = new Double[patientNotAllExprValues.size()];
                ;
                patientNotAllExprValues.toArray(patientNotAllExprValuesArr);
                correlation = new PearsonsCorrelation().correlation(
                        ArrayUtils.toPrimitive(patientNotAllExprValuesArr),
                        ArrayUtils.toPrimitive(testPatientExprValuesArr));
                correlation_rb[j] = correlation;
            }

            //Calculating the p value of the two correlation arrays ra and rb
            double p_value = new TTest().tTest(correlation_ra, correlation_rb);

            if (p_value < 0.01) {
                diseaseClassification.put(patientsForTestCase[i], "ALL");
            } else {
                diseaseClassification.put(patientsForTestCase[i], "NOT ALL");
            }
        }

        testResults.put(diseaseClassification);
        out.print(diseaseClassification);

        //Closing the statement and connection
        stmt.close();
        connection.close();

    } catch (SQLException e) {
        System.out.println("Connection Failed! Check output console");
        e.printStackTrace();
        return;
    } catch (ClassNotFoundException e) {
        System.out.println("Where is your Oracle JDBC Driver?");
        e.printStackTrace();
        return;
    } catch (JSONException e) {
        System.out.println("Where is your Oracle JDBC Driver?");
        e.printStackTrace();
        return;
    }
}

From source file:com.vsthost.rnd.commons.math.ext.linear.DMatrixUtils.java

/**
 * Get the order of the specified elements in descending or ascending order.
 *
 * @param values A vector of integer values.
 * @param indices The indices which will be considered for ordering.
 * @param descending Flag indicating if we go descending or not.
 * @return A vector of indices sorted in the provided order.
 *///  www . j  ava2s  . c o m
public static int[] getOrder(int[] values, int[] indices, boolean descending) {
    // Create an index series:
    Integer[] opIndices = ArrayUtils.toObject(indices);

    // Sort indices:
    Arrays.sort(opIndices, new Comparator<Integer>() {
        @Override
        public int compare(Integer o1, Integer o2) {
            if (descending) {
                return Double.compare(values[o2], values[o1]);
            } else {
                return Double.compare(values[o1], values[o2]);
            }
        }
    });

    return ArrayUtils.toPrimitive(opIndices);
}

From source file:at.bitfire.davdroid.resource.LocalGroup.java

/**
 * Lists all members of this group.//from   w w  w . j  ava  2 s .  co  m
 * @return list of all members' raw contact IDs
 * @throws ContactsStorageException on contact provider errors
 */
protected long[] getMembers() throws ContactsStorageException {
    assertID();
    List<Long> members = new LinkedList<>();
    try {
        @Cleanup
        Cursor cursor = addressBook.provider.query(
                addressBook.syncAdapterURI(ContactsContract.Data.CONTENT_URI),
                new String[] { Data.RAW_CONTACT_ID },
                GroupMembership.MIMETYPE + "=? AND " + GroupMembership.GROUP_ROW_ID + "=?",
                new String[] { GroupMembership.CONTENT_ITEM_TYPE, String.valueOf(id) }, null);
        while (cursor != null && cursor.moveToNext())
            members.add(cursor.getLong(0));
    } catch (RemoteException e) {
        throw new ContactsStorageException("Couldn't list group members", e);
    }
    return ArrayUtils.toPrimitive(members.toArray(new Long[members.size()]));
}

From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java

/**
 * Converts a list of BigIntegers to an array of longs.
 * @param    List<BigInteger>    list of longs
 * @return                       array of longs
 *//* w ww .  j  a  v a 2  s.  c  o  m*/
public static long[] toLongArray(List<BigInteger> list) {

    for (BigInteger val : list) {
        if (!OverFlowUtil.longOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
    }

    return ArrayUtils.toPrimitive(list.toArray(new Long[list.size()]));

}

From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java

/**
 * Converts a list of BigDecimals to an array of longs.
 * @param    List<BigDecimal>    list of longs
 * @return                       array of longs
 *//*from   www .  j  a  v a2 s  .c  o m*/
public static long[] toLongArray(List<BigDecimal> list) {

    for (BigDecimal val : list) {
        if (!OverFlowUtil.longOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
    }

    return ArrayUtils.toPrimitive(list.toArray(new Long[list.size()]));

}

From source file:com.github.jessemull.microflex.util.IntegerUtil.java

/**
 * Converts a list of integers to an array of integers.
 * @param    List<Integer>    list of integers
 * @return                    array of integers
 *///w  ww.  j  a v a 2s  .  co  m
public static int[] toIntegerArray(List<Integer> list) {
    return ArrayUtils.toPrimitive(list.toArray(new Integer[list.size()]));
}