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

org.jhotdraw8.collection.spliterator.SpliteratorIterable Maven / Gradle / Ivy

The newest version!
/*
 * @(#)SpliteratorIterable.java
 * Copyright © 2023 The authors and contributors of JHotDraw. MIT License.
 */

package org.jhotdraw8.collection.spliterator;


import java.util.Iterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * An Iterable which takes a Spliterator supplier to implement the
 * Iterable methods.
 *
 * @param  the element type
 * @author Werner Randelshofer
 */
public class SpliteratorIterable implements Iterable {
    private final Supplier> factory;

    public SpliteratorIterable(Supplier> factory) {
        this.factory = factory;
    }

    @Override
    public void forEach(Consumer action) {
        factory.get().forEachRemaining(action);
    }

    @Override
    public Iterator iterator() {
        return Spliterators.iterator(factory.get());
    }

    @Override
    public Spliterator spliterator() {
        return factory.get();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy