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

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

Introduction

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

Prototype

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

Source Link

Document

Converts an array of object Booleans to primitives.

Usage

From source file:edu.harvard.iq.dataverse.util.SumStatCalculator.java

/**
 * Returns a new double array of nulls and non-Double.NaN values only
 *
 *///from  ww w  . ja  va2  s . com
// TODO: 
// implement this in some way that does not require allocating a new 
// ArrayList for the values of every vector. -- L.A. Aug. 11 2014
private static double[] removeInvalidValues(Double[] x) {
    List<Double> dl = new ArrayList<Double>();
    for (Double d : x) {
        if (d != null && !Double.isNaN(d)) {
            dl.add(d);
        }
    }
    return ArrayUtils.toPrimitive(dl.toArray(new Double[dl.size()]));
}

From source file:com.palantir.ptoss.cinch.swing.JListWiringHarness.java

private static void updateListModel(JList list, List<?> newContents) {
    if (newContents == null) {
        newContents = ImmutableList.of();
    }/*from   ww  w  . ja  v  a2  s .  c o m*/
    ListModel oldModel = list.getModel();
    List<Object> old = Lists.newArrayListWithExpectedSize(oldModel.getSize());
    for (int i = 0; i < oldModel.getSize(); i++) {
        old.add(oldModel.getElementAt(i));
    }
    if (old.equals(newContents)) {
        return;
    }
    Object[] selected = list.getSelectedValues();
    DefaultListModel listModel = new DefaultListModel();
    for (Object obj : newContents) {
        listModel.addElement(obj);
    }
    list.setModel(listModel);
    List<Integer> newIndices = Lists.newArrayListWithCapacity(selected.length);
    Set<Object> selectedSet = Sets.newHashSet(selected);
    for (int i = 0; i < listModel.size(); i++) {
        if (selectedSet.contains(listModel.elementAt(i))) {
            newIndices.add(i);
        }
    }
    list.setSelectedIndices(ArrayUtils.toPrimitive(newIndices.toArray(new Integer[0])));
}

From source file:com.naver.template.social.TwitterBO.java

public List<TwitterProfile> getFriendListParallel(String userId) {
    // get chunked id list
    CursoredList<Long> friendIdList = getFriendIdList(userId);
    List<List<Long>> chunkedList = ChunkUtils.chunk(friendIdList, 100);

    Twitter twitter = getTwitterConnection(userId);

    List<Future<List<TwitterProfile>>> futureList = new ArrayList<Future<List<TwitterProfile>>>();

    // call parallel
    for (List<Long> eachList : chunkedList) {
        Long[] array = eachList.toArray(new Long[0]);
        long[] ids = ArrayUtils.toPrimitive(array);
        futureList.add(pool.submit(new TwitterFriendsCallable(twitter, ids)));
    }/*from w ww .j  a va  2  s  .c o m*/

    // async get result and merge
    List<TwitterProfile> twitterFriends = new ArrayList<TwitterProfile>();
    for (Future<List<TwitterProfile>> future : futureList) {
        List<TwitterProfile> resultList = null;
        try {
            resultList = future.get(3000, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            //
        } catch (ExecutionException e) {
            //
        } catch (TimeoutException e) {
            //
        }

        if (CollectionUtils.isNotEmpty(resultList)) {
            twitterFriends.addAll(resultList);
        }
    }

    return twitterFriends;
}

From source file:mil.jpeojtrs.sca.util.PrimitiveArrayUtils.java

public static char[] convertToCharArray(final Object array) {
    if (array == null) {
        return null;
    }//  ww  w .  j av a  2  s. c  o m
    if (array instanceof char[]) {
        return (char[]) array;
    }
    if (array instanceof Character[]) {
        return ArrayUtils.toPrimitive((Character[]) array);
    }
    final char[] newArray = new char[Array.getLength(array)];
    for (int i = 0; i < newArray.length; i++) {
        final Object obj = Array.get(array, i);
        if (obj instanceof Character) {
            newArray[i] = (Character) Array.get(array, i);
        } else {
            newArray[i] = (char) ((Number) Array.get(array, i)).byteValue();
        }
    }
    return newArray;
}

From source file:com.opengamma.analytics.math.interpolation.Interpolator1D.java

public Interpolator1DDataBundle getDataBundle(final Map<Double, Double> data) {
    Validate.notNull(data, "Backing data for interpolation must not be null.");
    Validate.notEmpty(data, "Backing data for interpolation must not be empty.");
    if (data instanceof SortedMap) {
        final double[] keys = ArrayUtils
                .toPrimitive(data.keySet().toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY));
        final double[] values = ArrayUtils
                .toPrimitive(data.values().toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY));
        return getDataBundleFromSortedArrays(keys, values);
    }//  ww  w .  j a  v a 2s  .  co  m
    final double[] keys = new double[data.size()];
    final double[] values = new double[data.size()];
    int i = 0;
    for (final Map.Entry<Double, Double> entry : data.entrySet()) {
        keys[i] = entry.getKey();
        values[i] = entry.getValue();
        i++;
    }
    return getDataBundle(keys, values);
}

From source file:de.atomfrede.tools.evalutation.evaluator.AbstractEvaluator.java

public double[] list2DoubleArray(List<Double> values) {
    return ArrayUtils.toPrimitive(values.toArray(new Double[values.size()]));
}

From source file:com.opengamma.util.timeseries.fast.longint.AbstractFastLongDoubleTimeSeries.java

@Override
public DoubleTimeSeries<Long> newInstance(final Long[] times, final Double[] values) {
    return newInstanceFast(ArrayUtils.toPrimitive(times), ArrayUtils.toPrimitive(values));
}

From source file:com.opengamma.util.timeseries.fast.longint.object.AbstractFastLongObjectTimeSeries.java

@Override
public ObjectTimeSeries<Long, T> newInstance(final Long[] times, final T[] values) {
    return (ObjectTimeSeries<Long, T>) newInstanceFast(ArrayUtils.toPrimitive(times), values);
}

From source file:de.atomfrede.tools.evalutation.evaluator.AbstractEvaluator.java

public int[] list2IntArray(List<Integer> values) {
    return ArrayUtils.toPrimitive(values.toArray(new Integer[values.size()]));
}

From source file:mil.jpeojtrs.sca.util.PrimitiveArrayUtils.java

public static boolean[] convertToBooleanArray(final Object array) {
    if (array == null) {
        return null;
    }//from   w ww .  j  a  va  2 s  .co m
    if (array instanceof boolean[]) {
        return (boolean[]) array;
    }
    if (array instanceof Boolean[]) {
        return ArrayUtils.toPrimitive((Boolean[]) array);
    }
    final boolean[] newArray = new boolean[Array.getLength(array)];
    for (int i = 0; i < newArray.length; i++) {
        final Object obj = Array.get(array, i);
        if (obj instanceof Boolean) {
            newArray[i] = (Boolean) Array.get(array, i);
        } else {
            newArray[i] = ((Number) Array.get(array, i)).byteValue() != 0;
        }
    }
    return newArray;
}