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

com.github.dakusui.pcond.Ensures Maven / Gradle / Ivy

package com.github.dakusui.pcond;

import com.github.dakusui.pcond.validator.Validator;

import java.util.function.Predicate;

/**
 * A class that offers entry-points for checking "postconditions" with a normal
 * conditional statement of Java language.
 * That is, `if` or ternary operator, not an `assert` statement.
 * This means, the user of your product is not able to disable the checks you
 * write at runtime, unlike ones written using `assert` statements.
 *
 * The author of library thinks these methods should be used in "public facing"
 * methods, when you should claim that the "external" party introduced the bug.
 *
 * The author of library thinks these methods should be used in "public facing"
 * context when the provider of the value to be examined introduced
 * a bug, which makes the condition `false`.
 *
 * For instance, it is an intended use-case, where you call `ensure` at the end of
 * your method in order to express a condition to be satisfied by the value returned
 * from your method.
 */
public enum Ensures {
  ;

  public static  T ensureNonNull(T value) {
    return Validator.INSTANCE.ensureNonNull(value);
  }

  public static  T ensureState(T value, Predicate cond) {
    return Validator.INSTANCE.ensureState(value, cond);
  }

  public static  T ensure(T value, Predicate cond) {
    return Validator.INSTANCE.ensure(value, cond);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy