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:org.drools.core.io.impl.ByteArrayResourceToStringTest.java

@Test
public void testToString() {
    byte[] byteArray = ArrayUtils.toPrimitive(bytes.toArray(new Byte[0]));
    ByteArrayResource byteArrayResource = new ByteArrayResource(byteArray, encoding);
    Assert.assertEquals(expectedString, byteArrayResource.toString());
}

From source file:org.dussan.vaadin.dcharts.renderers.series.BubbleRenderer.java

public int[] getRadii() {
    return ArrayUtils.toPrimitive(radii);
}

From source file:org.dussan.vaadin.dcharts.renderers.series.MeterGaugeRenderer.java

public float[] getTicks() {
    return ArrayUtils.toPrimitive(ticks);
}

From source file:org.dussan.vaadin.dcharts.renderers.series.MeterGaugeRenderer.java

public float[] getIntervals() {
    return ArrayUtils.toPrimitive(intervals);
}

From source file:org.dussan.vaadin.dcharts.renderers.series.MeterGaugeRenderer.java

public float[] getTickPositions() {
    return ArrayUtils.toPrimitive(tickPositions);
}

From source file:org.exist.security.EffectiveSubject.java

@Override
public int[] getGroupIds() {
    if (group != null) {
        final Set<Integer> groupIds = new HashSet<Integer>(
                Arrays.asList(ArrayUtils.toObject(account.getGroupIds())));
        groupIds.add(group.getId());/* w  w w . j  av  a  2s . c  om*/
        return ArrayUtils.toPrimitive(groupIds.toArray(new Integer[groupIds.size()]));
    } else {
        return account.getGroupIds();
    }
}

From source file:org.goko.core.common.GkUtils.java

public static String toString(List<Byte> data) {
    StringBuffer buffer = new StringBuffer(data.size());
    byte[] byteArray = ArrayUtils.toPrimitive(data.toArray(new Byte[] {}));

    for (byte b : byteArray) {
        buffer.append((char) b);
    }//from w  ww . ja v a  2s  .c  o m
    return buffer.toString();
}

From source file:org.goko.tools.serial.jssc.service.JsscSender.java

/** (inheritDoc)
 * @see java.lang.Runnable#run()/* ww  w. jav a  2  s . co m*/
 */
@Override
public void run() {

    while (!stopped) {
        if (jsscService.getSerialPort().isOpened()) {
            List<Byte> lst = null;
            try {
                waitDataAvailableToSend();
                if (CollectionUtils.isNotEmpty(queue)) {
                    lst = queue.take();
                } else if (CollectionUtils.isNotEmpty(importantQueue)) {
                    lst = importantQueue.take();
                }
            } catch (InterruptedException e) {
                LOG.error(e);
            } catch (GkException e) {
                LOG.error(e);
            }

            if (lst != null) {
                try {
                    Byte[] bytes = lst.toArray(new Byte[lst.size()]);
                    jsscService.getSerialPort().writeBytes(ArrayUtils.toPrimitive(bytes));
                    jsscService.notifyOutputListeners(lst);
                } catch (SerialPortException e) {
                    LOG.error(e);
                }
            }
        } else {
            stop();
        }
    }
}

From source file:org.grouplens.lenskit.eval.metrics.predict.LastFmEvaluation.java

public static void main(String[] args) {

    String csvFile = "/home/user/Desktop/LastFM_exps/newresultssets/LastFM_1_of_5_20140613-1938.csv";
    //        String csvFile = "/home/user/Desktop/LastFM_exps/reresultset1of5fold/LastFM_1_of_5_20140606-0338.csv";
    BufferedReader br = null;/*  ww  w  . j ava  2 s  .com*/
    String sCurrentLine = "";
    String cvsSplitBy = ",";

    try {

        TreeMap<Integer, ArrayList<Double>> golden = new TreeMap<Integer, ArrayList<Double>>();
        TreeMap<Integer, ArrayList<Double>> methodA = new TreeMap<Integer, ArrayList<Double>>();
        TreeMap<Integer, ArrayList<Double>> methodB = new TreeMap<Integer, ArrayList<Double>>();
        TreeMap<Integer, ArrayList<Double>> methodC = new TreeMap<Integer, ArrayList<Double>>();

        br = new BufferedReader(new FileReader(csvFile));
        //            String header = br.readLine();
        //            System.out.println(header);

        while ((sCurrentLine = br.readLine()) != null) {

            String[] cols = sCurrentLine.split(cvsSplitBy);
            int userId = Integer.parseInt(cols[0]);
            double goldenValue = Double.parseDouble(cols[5]);
            double methodAValue = Double.parseDouble(cols[2]);
            double methodBValue = Double.parseDouble(cols[3]);
            double methodCValue = Double.parseDouble(cols[4]);

            //Actual Values TreeMap creation
            if (!golden.containsKey(userId)) {
                golden.put(userId, new ArrayList<Double>());
                golden.get(userId).add(goldenValue);
            } else {
                golden.get(userId).add(goldenValue);
            }
            //Method A TreeMap creation
            if (!methodA.containsKey(userId)) {
                methodA.put(userId, new ArrayList<Double>());
                methodA.get(userId).add(methodAValue);
            } else {
                methodA.get(userId).add(methodAValue);
            }
            //Method B TreeMap creation
            if (!methodB.containsKey(userId)) {
                methodB.put(userId, new ArrayList<Double>());
                methodB.get(userId).add(methodBValue);
            } else {
                methodB.get(userId).add(methodBValue);
            }
            //Method C TreeMap creation
            if (!methodC.containsKey(userId)) {
                methodC.put(userId, new ArrayList<Double>());
                methodC.get(userId).add(methodCValue);
            } else {
                methodC.get(userId).add(methodCValue);
            }

        }

        uniqueUsers = golden.size();
        System.out.println("To synolo twn monadikwn xristwn sto dataset einai: " + uniqueUsers);

        nusers = 0;
        sumPearsonA = 0;
        sumPearsonB = 0;
        sumPearsonC = 0;
        for (Integer i : golden.keySet()) {

            Double[] ADoubles = new Double[methodA.get(i).size()];
            methodA.get(i).toArray(ADoubles);
            Double[] BDoubles = new Double[methodB.get(i).size()];
            methodB.get(i).toArray(BDoubles);
            Double[] CDoubles = new Double[methodC.get(i).size()];
            methodC.get(i).toArray(CDoubles);
            Double[] goldenDoubles = new Double[golden.get(i).size()];
            golden.get(i).toArray(goldenDoubles);

            if (goldenDoubles.length > 1) {

                corA = p.correlation(ArrayUtils.toPrimitive(ADoubles), ArrayUtils.toPrimitive(goldenDoubles));
                corB = p.correlation(ArrayUtils.toPrimitive(BDoubles), ArrayUtils.toPrimitive(goldenDoubles));
                corC = p.correlation(ArrayUtils.toPrimitive(CDoubles), ArrayUtils.toPrimitive(goldenDoubles));

                if (Double.isNaN(corA)) {

                    corA = 1;
                }
                if (Double.isNaN(corB)) {

                    corB = 1;
                }
                if (Double.isNaN(corC)) {

                    corC = 1;
                }

                sumPearsonA += corA;
                sumPearsonB += corB;
                sumPearsonC += corC;
                nusers++;
                //                for (int arrayCounter = 0; arrayCounter < goldenDoubles.length; arrayCounter++) {
                //
                //                    sumA += ADoubles[arrayCounter];
                //                    sumB += BDoubles[arrayCounter];
                //                    sumC += CDoubles[arrayCounter];
                //                    sumGolden += goldenDoubles[arrayCounter];
                //                    
                //                }
                //
                //                avgA = sumA / ADoubles.length;
                //                avgB = sumB / BDoubles.length;
                //                avgC = sumC / CDoubles.length;
                //                avgGolden = sumGolden / goldenDoubles.length;

                //                    System.out.println(sumPearsonA);
                //                    System.out.println(sumPearsonB);
                //                    System.out.println(sumPearsonC);
                //                    System.out.println(nusers);
                //                    System.out.println("----------------------------------");
                //                sumGolden = 0; sumA = 0; sumB = 0; sumC = 0;
            } else {
                System.out.println("User has only ONE rating!!!!! ");
                System.out.println("----------------------------------");
            }
        }

        avgA = sumPearsonA / nusers;
        avgB = sumPearsonB / nusers;
        avgC = sumPearsonC / nusers;

        System.out.println(avgA);
        System.out.println(avgB);
        System.out.println(avgC);
        System.out.println("----------------------------------");

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    System.out.println("Done");
}

From source file:org.hawkular.client.test.metrics.openshift.CollectionRateDetailTest.java

private void getData(String metricID, String testID, long start, long end, Duration timeBucket) {
    Reporter.log("Fetching large data set... may take a couple minutes", true);
    List<DataPoint<Double>> rawData = client().metrics().gauge()
            .findGaugeDataWithId(metricID, String.valueOf(start), String.valueOf(end), null, null, null)
            .getEntity();/*from w  ww . j  a v a2  s .  com*/

    Assert.assertNotNull(rawData, testID);
    Reporter.log("raw datapoints: " + rawData.size(), true);

    List<Long> zeroList = findZeroValues(rawData);

    Assert.assertTrue(zeroList == null || zeroList.size() == 0, testID);

    Map<Long, Integer> hist = OpenshiftBaseTest.makeHistogram(rawData, timeBucket);

    Double[] result = hist.entrySet().stream().map(x -> new Double(x.getValue()))
            .toArray(size -> new Double[size]);

    double[] d = ArrayUtils.toPrimitive(result);

    // drop the first and last as they are usually outliers
    double[] samples = Arrays.copyOfRange(d, 1, d.length - 1);
    DescriptiveStatistics stats = new DescriptiveStatistics(samples);

    Reporter.log(hist.toString(), true);
    Reporter.log("size: " + stats.getN(), true);
    Reporter.log("min/max: " + stats.getMin() + "/" + stats.getMax(), true);
    Reporter.log("mean: " + stats.getMean(), true);
    Reporter.log("variance: " + stats.getVariance(), true);
    Reporter.log("stddev: " + stats.getStandardDeviation(), true);
}