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

net.jqwik.api.stateful.Action Maven / Gradle / Ivy

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

import org.apiguardian.api.*;

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

/**
 * An action class represents a state change that can be preformed
 * on a stateful {@code S}.
 *
 * At runtime the execution of an action is regulated by a precondition.
 *
 * @param  Type of the state object
 */
@API(status = MAINTAINED, since = "1.0")
public interface Action {

	/**
	 * If this method returns false, the action will not be performed.
	 *
	 * @param state the current state
	 * @return true if the precondition holds
	 */
	default boolean precondition(S state) {
		return true;
	}

	/**
	 * Perform an action on state {@code S} and return the same state (if it has state)
	 * or a new one representing the new state.
	 *
	 * @param state the current state
	 * @return the new state, which may or may not be the same object
	 */
	S run(S state);
}