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

spock.genesis.generators.SequentialMultisourceGenerator.groovy Maven / Gradle / Ivy

Go to download

Mostly lazy data generators for property based testing using the Spock test framework

The newest version!
package spock.genesis.generators

import groovy.transform.CompileStatic

@CompileStatic
class SequentialMultisourceGenerator extends Generator implements Closeable {

    private final List> generators

    SequentialMultisourceGenerator(Generator... iterables) {
        this.generators = iterables.toList()
    }

    UnmodifiableIterator iterator() {
        new UnmodifiableIterator() {
            private Iterator current
            private final Iterator iterators = generators.collect { it.iterator() }.iterator()

            boolean hasNext() {
                setupIterator()
                current.hasNext()
            }

            private void setupIterator() {
                while (!current?.hasNext() && iterators.hasNext()) {
                    current = iterators.next()
                }
            }

            E next() {
                setupIterator()
                current.next()
            }
        }
    }

    void close() {
        generators.each { it.close() }
    }

    boolean isFinite() {
        generators.every { it.finite }
    }

    SequentialMultisourceGenerator seed(Long seed) {
        generators.each { it.seed(seed) }
        super.seed(seed)
        this
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy