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

net.jqwik.engine.properties.arbitraries.randomized.CollectGenerator Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.engine.properties.arbitraries.randomized;

import java.util.*;
import java.util.function.*;

import net.jqwik.api.*;
import net.jqwik.engine.properties.shrinking.*;

public class CollectGenerator implements RandomGenerator> {
	private final RandomGenerator elementGenerator;
	private final Predicate> until;

	public CollectGenerator(RandomGenerator elementGenerator, Predicate> until) {
		this.elementGenerator = elementGenerator;
		this.until = until;
	}

	@Override
	public Shrinkable> next(Random random) {
		List base = new ArrayList<>();
		List> shrinkables = new ArrayList<>();
		while (!until.test(base)) {
			Shrinkable shrinkable = elementGenerator.next(random);
			base.add(shrinkable.value());
			shrinkables.add(shrinkable);
		}
		return new CollectShrinkable<>(shrinkables, until);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy