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

net.jqwik.api.arbitraries.ArbitraryDecorator Maven / Gradle / Ivy

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

import java.util.*;

import org.apiguardian.api.*;

import net.jqwik.api.*;

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

/**
 * Use this superclass if you want to provide a specialized type of arbitrary.
 *
 * @param  The type of object to be generated by this arbitrary
 *
 * @see Arbitrary
 * @see Arbitraries
 */
@API(status = EXPERIMENTAL, since = "1.4.0")
public abstract class ArbitraryDecorator  implements Cloneable, Arbitrary {

	/**
	 * Implement by calling jqwik's standard DSL for building arbitraries.
	 *
	 * @return a new arbitrary instance
	 */
	abstract protected Arbitrary arbitrary();

	@Override
	public RandomGenerator generator(int genSize) {
		return arbitrary().generator(genSize);
	}

	@Override
	public RandomGenerator generatorWithEmbeddedEdgeCases(int genSize) {
		return arbitrary().generatorWithEmbeddedEdgeCases(genSize);
	}

	@Override
	public Optional> exhaustive(long maxNumberOfSamples) {
		return arbitrary().exhaustive(maxNumberOfSamples);
	}

	@Override
	public EdgeCases edgeCases(int maxEdgeCases) {
		return arbitrary().edgeCases(maxEdgeCases);
	}

	@Override
	public String toString() {
		return String.format("Decorated:%s", super.toString());
	}

	/**
	 * Use to clone current instance with its interface type
	 *
	 * @param  The special interface type of this arbitrary
	 * @return A cloned instance of this arbitrary
	 */
	@SuppressWarnings("unchecked")
	protected > A typedClone() {
		try {
			return (A) this.clone();
		} catch (CloneNotSupportedException e) {
			throw new JqwikException(e.getMessage());
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy