All Downloads are FREE. Search and download functionalities are using the official Maven repository.

solid.converters.ToPrimitiveDoubleArray Maven / Gradle / Ivy

Go to download

Solid is an Android library, which provides lightweight data streams and immutable+parcelable collections.

There is a newer version: 1.0.14
Show newest version
package solid.converters;

import java.util.List;

import solid.functions.SolidFunc1;
import solid.stream.Copy;

public class ToPrimitiveDoubleArray implements SolidFunc1, double[]> {

    private static final SolidFunc1, double[]> TO_PRIMITIVE_DOUBLE_ARRAY = new ToPrimitiveDoubleArray();

    /**
     * Returns a method that can be used with {@link solid.stream.Stream#collect(SolidFunc1)}
     * to convert an iterable stream of {@link Double} type into a primitive double[] array.
     *
     * @return a method that converts an iterable stream of {@link Double} type into a primitive double[] array.
     */
    public static SolidFunc1, double[]> toPrimitiveDoubleArray() {
        return TO_PRIMITIVE_DOUBLE_ARRAY;
    }

    @Override
    public double[] call(Iterable value) {
        List objects = new Copy<>(value).collect(ToList.toList());
        double[] primitives = new double[objects.size()];
        int i = 0;
        for (Double object : objects)
            primitives[i++] = object;
        return primitives;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy