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

net.jqwik.api.EdgeCases Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
package net.jqwik.api;

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

import org.apiguardian.api.*;

import static org.apiguardian.api.API.Status.*;

@API(status = EXPERIMENTAL, since = "1.3.0")
public interface EdgeCases extends Iterable> {

	@API(status = INTERNAL)
	abstract class EdgeCasesFacade {
		private static final EdgeCases.EdgeCasesFacade implementation;

		static {
			implementation = FacadeLoader.load(EdgeCases.EdgeCasesFacade.class);
		}

		public abstract  EdgeCases fromSuppliers(List>> suppliers);

		public abstract  EdgeCases mapShrinkable(EdgeCases self, Function, Shrinkable> mapper);

		public abstract  EdgeCases flatMapArbitrary(EdgeCases self, Function> mapper);

		public abstract  EdgeCases filter(EdgeCases self, Predicate filterPredicate);

		public abstract  EdgeCases ignoreException(EdgeCases self, Class exceptionType);
	}

	List>> suppliers();

	default int size() {
		return suppliers().size();
	}

	default boolean isEmpty() {
		return size() == 0;
	}

	default Iterator> iterator() {
		return suppliers().stream().map(Supplier::get).iterator();
	}

	@API(status = INTERNAL)
	static  EdgeCases fromSuppliers(List>> suppliers) {
		return EdgeCasesFacade.implementation.fromSuppliers(suppliers);
	}

	@API(status = INTERNAL)
	static  EdgeCases none() {
		return fromSuppliers(Collections.emptyList());
	}

	@API(status = INTERNAL)
	static  EdgeCases fromSupplier(Supplier> supplier) {
		return fromSuppliers(Collections.singletonList(supplier));
	}

	@API(status = INTERNAL)
	default  EdgeCases map(Function mapper) {
		return mapShrinkable(tShrinkable -> tShrinkable.map(mapper));
	}

	@API(status = INTERNAL)
	default  EdgeCases mapShrinkable(Function, Shrinkable> mapper) {
		return EdgeCasesFacade.implementation.mapShrinkable(this, mapper);
	}

	@API(status = INTERNAL)
	default EdgeCases filter(Predicate filterPredicate) {
		return EdgeCasesFacade.implementation.filter(this, filterPredicate);
	}

	@API(status = INTERNAL)
	default  EdgeCases flatMapArbitrary(Function> mapper) {
		return EdgeCasesFacade.implementation.flatMapArbitrary(this, mapper);
	}

	@API(status = INTERNAL)
	default EdgeCases ignoreException(Class exceptionType) {
		return EdgeCasesFacade.implementation.ignoreException(this, exceptionType);
	}

	@API(status = INTERNAL)
	default EdgeCases dontShrink() {
		return () -> EdgeCases.this.suppliers()
								   .stream()
								   .map(supplier -> (Supplier>) () -> supplier.get().makeUnshrinkable())
								   .collect(Collectors.toList());
	}


}