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

net.jqwik.engine.properties.arbitraries.exhaustive.WithSamplesExhaustiveGenerator Maven / Gradle / Ivy

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

import java.util.*;
import java.util.concurrent.atomic.*;

import net.jqwik.api.*;

public class WithSamplesExhaustiveGenerator implements ExhaustiveGenerator {
	private final T[] samples;
	private final ExhaustiveGenerator base;

	public WithSamplesExhaustiveGenerator(ExhaustiveGenerator base, T[] samples) {
		this.samples = samples;
		this.base = base;
	}

	@Override
	public boolean isUnique() {
		return base.isUnique();
	}

	@Override
	public long maxCount() {
		return base.maxCount() + samples.length;
	}

	@Override
	public Iterator iterator() {
		return new Iterator() {

			private final AtomicInteger countDeliveredSamples = new AtomicInteger(0);
			Iterator iterator = base.iterator();

			@Override
			public boolean hasNext() {
				if (samplesAvailable()) {
					return true;
				}
				return iterator.hasNext();
			}

			private boolean samplesAvailable() {
				return countDeliveredSamples.get() < samples.length;
			}

			@Override
			public T next() {
				if (samplesAvailable()) {
					return samples[countDeliveredSamples.getAndIncrement()];
				}
				return iterator.next();
			}
		};
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy