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:drpc.BptiEnsembleQuery.java

public static void main(final String[] args) throws IOException, TException, DRPCExecutionException {
    if (args.length < 3) {
        System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder");
        return;/*w  w w  .  j a v  a  2 s . c  o m*/
    }

    final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/);
    final Queue<String> featureFiles = new ArrayDeque<String>();
    SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles);

    Scanner scanner = new Scanner(featureFiles.peek());
    int i = 0;
    while (scanner.hasNextLine() && i++ < 1) {
        List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine());
        for (Map<String, List<Double>> map : dict) {
            final Double[] features = map.get("chi1").toArray(new Double[0]);
            final Double[] moreFeatures = map.get("chi2").toArray(new Double[0]);
            final Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures);
            final String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both));
            Logger.getAnonymousLogger().log(Level.INFO, runQuery(args[1], parameters, client));
        }
    }
    client.close();
}

From source file:drpc.KMeansDrpcQuery.java

public static void main(final String[] args)
        throws IOException, TException, DRPCExecutionException, DecoderException, ClassNotFoundException {
    if (args.length < 3) {
        System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder");
        return;//from w ww  .  j ava  2 s  .  c o m
    }

    final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/);
    final Queue<String> featureFiles = new ArrayDeque<String>();
    SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles);

    Scanner scanner = new Scanner(featureFiles.peek());
    int i = 0;
    while (scanner.hasNextLine() && i++ < 10) {
        List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine());
        for (Map<String, List<Double>> map : dict) {
            i++;

            Double[] features = map.get("chi2").toArray(new Double[0]);
            Double[] moreFeatures = map.get("chi1").toArray(new Double[0]);
            Double[] rmsd = map.get("rmsd").toArray(new Double[0]);
            Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures);
            String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both));

            String centroidsSerialized = runQuery(args[1], parameters, client);

            Gson gson = new Gson();
            Object[] deserialized = gson.fromJson(centroidsSerialized, Object[].class);

            for (Object obj : deserialized) {
                // result we get is of the form List<result>
                List l = ((List) obj);
                centroidsSerialized = (String) l.get(0);

                String[] centroidSerializedArrays = centroidsSerialized
                        .split(MlStormClustererQuery.KmeansClustererQuery.CENTROID_DELIM);
                List<double[]> centroids = new ArrayList<double[]>();
                for (String centroid : centroidSerializedArrays) {
                    centroids.add(MlStormFeatureVectorUtils.deserializeToFeatureVector(centroid));
                }

                double[] rmsdPrimitive = ArrayUtils.toPrimitive(both);
                double[] rmsdKmeans = new double[centroids.size()];

                for (int k = 0; k < centroids.size(); k++) {
                    System.out.println("centroid        -- " + Arrays.toString(centroids.get(k)));
                    double[] centroid = centroids.get(k);
                    rmsdKmeans[k] = computeRootMeanSquare(centroid);
                }

                System.out.println("1 rmsd original -- " + Arrays.toString(rmsd));
                System.out.println("2 rmsd k- Means -- " + Arrays.toString(rmsdKmeans));
                System.out.println();
            }

        }
    }
    client.close();
}

From source file:com.naver.template.common.ChunkUtils.java

public static long[] toPrimitiveArray(List<Long> list) {
    Long[] array = list.toArray(new Long[0]);
    return ArrayUtils.toPrimitive(array);
}

From source file:de.weltraumschaf.registermachine.convert.ByteArray.java

/**
 * Converts array of boxed bytes to unboxed native bytes.
 *
 * @param in boxed bytes//  ww  w .  ja v  a 2s  . c  om
 * @return unboxed bytes
 * @deprecated Use ArrayUtils.toPrimitive().
 */
@Deprecated
public static byte[] toNative(final Byte[] in) {
    return ArrayUtils.toPrimitive(in);
}

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

public static short[] convertToShortArray(final Object array) {
    if (array == null) {
        return null;
    }/*from w ww  .  j ava2 s .  c  om*/
    if (array instanceof short[]) {
        return (short[]) array;
    }
    if (array instanceof Short[]) {
        return ArrayUtils.toPrimitive((Short[]) array);
    }
    final short[] newArray = new short[Array.getLength(array)];
    for (int i = 0; i < newArray.length; i++) {
        final Number val = (Number) Array.get(array, i);
        newArray[i] = val.shortValue();
    }
    return newArray;
}

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

public static byte[] convertToByteArray(final Object array) {
    if (array == null) {
        return null;
    }// w w  w .j  ava 2s  .co m
    if (array instanceof byte[]) {
        return (byte[]) array;
    }
    if (array instanceof Byte[]) {
        return ArrayUtils.toPrimitive((Byte[]) array);
    }
    final byte[] newArray = new byte[Array.getLength(array)];
    for (int i = 0; i < newArray.length; i++) {
        final Number val = (Number) Array.get(array, i);
        newArray[i] = val.byteValue();
    }
    return newArray;
}

From source file:de.alpharogroup.wicket.base.util.WicketImageExtensions.java

/**
 * Gets the image.//  w  w  w  .  j  av a 2 s .c o  m
 * 
 * @param wicketId
 *            the id from the image for the html template.
 * @param contentType
 *            the content type
 * @param data
 *            the data
 * @return the image
 */
public static Image getImage(final String wicketId, final String contentType, final Byte[] data) {
    final byte[] byteArrayData = ArrayUtils.toPrimitive(data);
    return getImage(wicketId, contentType, byteArrayData);
}

From source file:co.turnus.analysis.util.AnalysisUtil.java

public static double[] linspaced(double min, double max, int points) {
    Set<Double> values = new LinkedHashSet<Double>();
    double current = min;
    double delta = (max - min) / ((double) points - 1);
    do {//from  w  ww. ja v  a 2s. com
        values.add(current);
        current += delta;

    } while (current < (max + delta / 2));
    return ArrayUtils.toPrimitive(values.toArray(new Double[0]));
}

From source file:edu.utah.further.core.api.collections.ArrayUtil.java

/**
 * @param list/*from www  .  j av  a2s .c o m*/
 * @return
 */
public static byte[] byteListToPrimitiveArray(final List<Byte> list) {
    return ArrayUtils.toPrimitive(list.toArray(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY));
}

From source file:com.compomics.cell_coord.utils.JFreeChartUtils.java

/**
 * Generate a series for a (x, y) plot, a 2D array containing both x and y
 * double values./*from   ww  w .ja  v a2  s.c  o  m*/
 *
 * @param coordinatesToPlot
 * @return the series
 */
public static XYSeries generateXYSeries(Double[][] coordinatesToPlot) {
    // transpose the matrix
    Double[][] transposed = ComputationUtils.transpose2DArray(coordinatesToPlot);
    // take first row: x coordinates
    double[] xCoordinates = ArrayUtils.toPrimitive(ComputationUtils.excludeNullValues(transposed[0]));
    // take second row: y coordinates
    double[] yCoordinates = ArrayUtils.toPrimitive(ComputationUtils.excludeNullValues(transposed[1]));
    // generate xy series for the plot
    return JFreeChartUtils.generateXYSeries(xCoordinates, yCoordinates);
}