Search in sources :

Example 1 with FloatBuffer

use of one.util.streamex.Internals.FloatBuffer in project streamex by amaembo.

the class DoubleStreamEx method toFloatArray.

/**
 * Returns a {@code float[]} array containing the elements of this stream
 * which are converted to floats using {@code (float)} cast operation.
 *
 * <p>
 * This is a terminal operation.
 *
 * @return an array containing the elements of this stream
 * @since 0.3.0
 */
public float[] toFloatArray() {
    if (isParallel())
        return collect(DoubleCollector.toFloatArray());
    java.util.Spliterator.OfDouble spliterator = spliterator();
    int size = intSize(spliterator);
    FloatBuffer buf;
    if (size >= 0) {
        buf = new FloatBuffer(size);
        spliterator.forEachRemaining((DoubleConsumer) buf::addUnsafe);
    } else {
        buf = new FloatBuffer();
        spliterator.forEachRemaining((DoubleConsumer) buf::add);
    }
    return buf.toArray();
}
Also used : FloatBuffer(one.util.streamex.Internals.FloatBuffer) Spliterator(java.util.Spliterator)

Aggregations

Spliterator (java.util.Spliterator)1 FloatBuffer (one.util.streamex.Internals.FloatBuffer)1