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

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

Introduction

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

Prototype

null EMPTY_BOOLEAN_ARRAY

To view the source code for org.apache.commons.lang ArrayUtils EMPTY_BOOLEAN_ARRAY.

Click Source Link

Document

An empty immutable boolean array.

Usage

From source file:gov.nih.nci.caarray.util.CaArrayUtilsTest.java

@Test
public void testSplitValues() {
    assertTrue(/* w w  w.  j  a  v a2 s . c  om*/
            Arrays.equals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, CaArrayUtils.splitIntoBooleans(EMPTY_STRING, " ")));
    assertTrue(Arrays.equals(new boolean[] { true }, CaArrayUtils.splitIntoBooleans("true", ",")));
    assertTrue(Arrays.equals(new boolean[] { true, false, true },
            CaArrayUtils.splitIntoBooleans("true;false;true", ";")));

    assertTrue(Arrays.equals(ArrayUtils.EMPTY_SHORT_ARRAY, CaArrayUtils.splitIntoShorts(EMPTY_STRING, " ")));
    assertTrue(Arrays.equals(new short[] { 0 }, CaArrayUtils.splitIntoShorts("0", ",")));
    assertTrue(Arrays.equals(new short[] { 3, 1, 2 }, CaArrayUtils.splitIntoShorts("3;1;2", ";")));

    assertTrue(Arrays.equals(ArrayUtils.EMPTY_LONG_ARRAY, CaArrayUtils.splitIntoLongs(EMPTY_STRING, " ")));
    assertTrue(Arrays.equals(new long[] { 5L }, CaArrayUtils.splitIntoLongs("5", ",")));
    assertTrue(Arrays.equals(new long[] { 15L, 19L, 13L }, CaArrayUtils.splitIntoLongs("15/19/13", "/")));

    assertTrue(Arrays.equals(ArrayUtils.EMPTY_INT_ARRAY, CaArrayUtils.splitIntoInts(EMPTY_STRING, " ")));
    assertTrue(Arrays.equals(new int[] { 1001 }, CaArrayUtils.splitIntoInts("1001", ",")));
    assertTrue(Arrays.equals(new int[] { -1, 0, -2 }, CaArrayUtils.splitIntoInts("-1 0 -2", " ")));

    assertTrue(Arrays.equals(ArrayUtils.EMPTY_FLOAT_ARRAY, CaArrayUtils.splitIntoFloats(EMPTY_STRING, " ")));
    assertTrue(Arrays.equals(new float[] { 1.65f }, CaArrayUtils.splitIntoFloats("1.65", ",")));
    assertTrue(Arrays.equals(new float[] { 0f, 0.33f, -3.76f },
            CaArrayUtils.splitIntoFloats("0 0.33 -3.76", " ")));

    assertTrue(Arrays.equals(ArrayUtils.EMPTY_DOUBLE_ARRAY, CaArrayUtils.splitIntoDoubles(EMPTY_STRING, " ")));
    assertTrue(Arrays.equals(new double[] { 1.0 / 3.0 },
            CaArrayUtils.splitIntoDoubles("0.3333333333333333", ",")));
    assertTrue(Arrays.equals(new double[] { 0, -5.0 / 7.0, 11.0 / 13.0 },
            CaArrayUtils.splitIntoDoubles("0.0;-0.7142857142857143;0.8461538461538461", ";")));

    assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, CaArrayUtils.splitFromCsv(EMPTY_STRING)));
    assertTrue(Arrays.equals(new String[] { "Iam,Dan" }, CaArrayUtils.splitFromCsv("Iam\\,Dan")));
    assertTrue(Arrays.equals(new String[] { "I", "m,e", "mi ne" }, CaArrayUtils.splitFromCsv("I,m\\,e,mi ne")));
}

From source file:org.bdval.DistributionDifferenceByFeatureMode.java

/**
 * Retrieve the data from the table into Map[column_name, double[]].
 *
 * @param table                the input Table which contains the data
 * @param conditionIdentifiers maps sample ids to their class
 * @param classToKeep          data class to read values for, if mergeClasses is true this will
 *                             be ignored
 *                             all classes (mergedClasses)
 * @return data in map form//from  w  w  w  . j  a v  a 2  s.  c o m
 */
private Map<String, double[]> retrieveDataAsMap(final Table table,
        final ConditionIdentifiers conditionIdentifiers, final String classToKeep) {
    final Map<String, double[]> data = new Object2ObjectLinkedOpenHashMap<String, double[]>();
    boolean[] keepRowValues = ArrayUtils.EMPTY_BOOLEAN_ARRAY;
    final DoubleList keptValues = new DoubleArrayList();
    int numKeptValues = 0;
    for (int col = 0; col < table.getColumnNumber(); col++) {
        final String colName = table.getIdentifier(col);
        try {
            if (col == 0) {
                // Column 0 will determine which values we keep
                final String[] samplesIds = table.getStrings(colName);
                final int numRows = samplesIds.length;
                keepRowValues = new boolean[numRows];
                for (int i = 0; i < numRows; i++) {
                    final String sampleId = samplesIds[i];

                    // Obtain class for the sample in two ways, compare them.
                    final String sampleTrueLabel = conditionIdentifiers.conditionForIdentifier(sampleId);

                    if (sampleTrueLabel == null) {
                        // NEVER keep if the sampleId isn't in the true-labels file
                        keepRowValues[i] = false;
                    } else {
                        if (mergeClasses || sampleTrueLabel.equals(classToKeep)) {
                            keepRowValues[i] = true;
                        }
                        if (keepRowValues[i]) {
                            numKeptValues++;
                        }
                    }
                }
            } else {
                keptValues.clear();
                if (numKeptValues > 0) {
                    final double[] allValues = table.getDoubles(colName);
                    for (int i = 0; i < keepRowValues.length; i++) {
                        if (keepRowValues[i]) {
                            keptValues.add(allValues[i]);
                        }
                    }
                }
                data.put(table.getIdentifier(col), keptValues.toDoubleArray());
            }
        } catch (InvalidColumnException e) {
            LOG.error(e);
        }
    }
    return data;
}