/** * A specialized version of {@link #checkPrecondition(Object, boolean, * Function)} that does not mention an input value. * * @param condition The predicate * @param message The predicate description * * @throws PreconditionViolationException Iff {@code predicate == false} */ public static void checkPrecondition( final boolean condition, final String message) throws PreconditionViolationException { if (!condition) { throw failed("<unspecified>", singleViolation(message)); } }
/** * A specialized version of {@link #checkPrecondition(Object, boolean, * Function)} that does not mention an input value. * * @param condition The predicate * @param message The predicate description * * @throws PreconditionViolationException Iff {@code predicate == false} */ public static void checkPrecondition( final boolean condition, final String message) throws PreconditionViolationException { if (!condition) { throw failed("<unspecified>", singleViolation(message)); } }
/** * A {@code double} specialized version of {@link #checkPreconditions(Object, * ContractConditionType[])} * * @param value The value * @param conditions The conditions the value must obey * * @return value * * @throws PreconditionViolationException If any of the conditions are false */ public static double checkPreconditionsD( final double value, final ContractDoubleConditionType... conditions) throws PreconditionViolationException { final Violations violations = innerCheckAllDouble(value, conditions); if (violations != null) { throw failed(Double.valueOf(value), violations); } return value; }
/** * A {@code long} specialized version of {@link #checkPreconditions(Object, * ContractConditionType[])} * * @param value The value * @param conditions The conditions the value must obey * * @return value * * @throws PreconditionViolationException If any of the conditions are false */ public static long checkPreconditionsL( final long value, final ContractLongConditionType... conditions) throws PreconditionViolationException { final Violations violations = innerCheckAllLong(value, conditions); if (violations != null) { throw failed(Long.valueOf(value), violations); } return value; }
/** * An {@code int} specialized version of {@link #checkPreconditions(Object, * ContractConditionType[])} * * @param value The value * @param conditions The conditions the value must obey * * @return value * * @throws PreconditionViolationException If any of the conditions are false */ public static int checkPreconditionsI( final int value, final ContractIntConditionType... conditions) throws PreconditionViolationException { final Violations violations = innerCheckAllInt(value, conditions); if (violations != null) { throw failed(Integer.valueOf(value), violations); } return value; }
/** * An {@code int} specialized version of {@link #checkPreconditions(Object, * ContractConditionType[])} * * @param value The value * @param conditions The conditions the value must obey * * @return value * * @throws PreconditionViolationException If any of the conditions are false */ public static int checkPreconditionsI( final int value, final ContractIntConditionType... conditions) throws PreconditionViolationException { final Violations violations = innerCheckAllInt(value, conditions); if (violations != null) { throw failed(Integer.valueOf(value), violations); } return value; }
/** * A {@code long} specialized version of {@link #checkPreconditions(Object, * ContractConditionType[])} * * @param value The value * @param conditions The conditions the value must obey * * @return value * * @throws PreconditionViolationException If any of the conditions are false */ public static long checkPreconditionsL( final long value, final ContractLongConditionType... conditions) throws PreconditionViolationException { final Violations violations = innerCheckAllLong(value, conditions); if (violations != null) { throw failed(Long.valueOf(value), violations); } return value; }
private static double innerCheckD( final double value, final boolean condition, final DoubleFunction<String> describer) { if (!condition) { throw failed( Double.valueOf(value), singleViolation(applyDescriberDChecked(value, describer))); } return value; }
/** * A {@code double} specialized version of {@link #checkPreconditions(Object, * ContractConditionType[])} * * @param value The value * @param conditions The conditions the value must obey * * @return value * * @throws PreconditionViolationException If any of the conditions are false */ public static double checkPreconditionsD( final double value, final ContractDoubleConditionType... conditions) throws PreconditionViolationException { final Violations violations = innerCheckAllDouble(value, conditions); if (violations != null) { throw failed(Double.valueOf(value), violations); } return value; }
private static double innerCheckD( final double value, final boolean condition, final DoubleFunction<String> describer) { if (!condition) { throw failed( Double.valueOf(value), singleViolation(applyDescriberDChecked(value, describer))); } return value; }
private static int innerCheckI( final int value, final boolean condition, final IntFunction<String> describer) { if (!condition) { throw failed( Integer.valueOf(value), singleViolation(applyDescriberIChecked(value, describer))); } return value; }
private static int innerCheckI( final int value, final boolean condition, final IntFunction<String> describer) { if (!condition) { throw failed( Integer.valueOf(value), singleViolation(applyDescriberIChecked(value, describer))); } return value; }
private static long innerCheckL( final long value, final boolean condition, final LongFunction<String> describer) { if (!condition) { throw failed( Long.valueOf(value), singleViolation(applyDescriberLChecked(value, describer))); } return value; }
private static long innerCheckL( final long value, final boolean condition, final LongFunction<String> describer) { if (!condition) { throw failed( Long.valueOf(value), singleViolation(applyDescriberLChecked(value, describer))); } return value; }
private static <T> T innerCheck( final T value, final boolean condition, final Function<T, String> describer) { if (!condition) { throw failed( value, singleViolation(applyDescriberChecked(value, describer))); } return value; }
private static <T> T innerCheck( final T value, final boolean condition, final Function<T, String> describer) { if (!condition) { throw failed( value, singleViolation(applyDescriberChecked(value, describer))); } return value; }
/** * A specialized version of {@link #checkPrecondition(Object, boolean, * Function)} that does not mention an input value. * * @param condition The predicate * @param message The predicate description supplier * * @throws PreconditionViolationException Iff {@code predicate == false} */ public static void checkPrecondition( final boolean condition, final Supplier<String> message) throws PreconditionViolationException { if (!condition) { throw failed( "<unspecified>", singleViolation(applySupplierChecked(message))); } }
/** * A specialized version of {@link #checkPrecondition(Object, boolean, * Function)} that does not mention an input value. * * @param condition The predicate * @param message The predicate description supplier * * @throws PreconditionViolationException Iff {@code predicate == false} */ public static void checkPrecondition( final boolean condition, final Supplier<String> message) throws PreconditionViolationException { if (!condition) { throw failed( "<unspecified>", singleViolation(applySupplierChecked(message))); } }
/** * <p>Evaluate the given {@code predicate} using {@code value} as input.</p> * * <p>The function throws {@link PreconditionViolationException} if the * predicate is false.</p> * * @param value The value * @param predicate The predicate * @param describer A describer for the predicate * @param <T> The type of values * * @return value * * @throws PreconditionViolationException If the predicate is false */ public static <T> T checkPrecondition( final T value, final Predicate<T> predicate, final Function<T, String> describer) { final boolean ok; try { ok = predicate.test(value); } catch (final Throwable e) { throw failed(value, singleViolation(failedPredicate(e))); } return innerCheck(value, ok, describer); }
/** * A {@code double} specialized version of {@link #checkPrecondition(Object, * Predicate, Function)} * * @param value The value * @param predicate The predicate * @param describer The describer of the predicate * * @return value * * @throws PreconditionViolationException If the predicate is false */ public static double checkPreconditionD( final double value, final DoublePredicate predicate, final DoubleFunction<String> describer) { final boolean ok; try { ok = predicate.test(value); } catch (final Throwable e) { throw failed( Double.valueOf(value), singleViolation(failedPredicate(e))); } return innerCheckD(value, ok, describer); }