/** * To ensure that the provided argument is correct. * * @see #ensureThatArg(Object, Matcher,State) * @see #ensureThatState(Object, Matcher, String) * @see #ensureThatContext(Object, Matcher) * * @throws IllegalArgumentException if matcher does not {@link Matcher#matches(Object) match}. */ public static <T> T ensureThatArg(final T object, final Matcher<T> matcher) { if (!matcher.matches(object)) { throw new IllegalArgumentException( "illegal argument, expected: " + descriptionOf(matcher)); } return object; }
/** * To ensure that the provided argument is correct. * * @see #ensureThatArg(Object, Matcher,State) * @see #ensureThatState(Object, Matcher, String) * @see #ensureThatContext(Object, Matcher) * * @throws IllegalArgumentException if matcher does not {@link Matcher#matches(Object) match}. */ public static <T> T ensureThatArg(final T object, final Matcher<T> matcher) { if (!matcher.matches(object)) { throw new IllegalArgumentException( "illegal argument, expected: " + descriptionOf(matcher)); } return object; }
/** * To ensure that the current state of this object (instance fields) is correct. * * @see #ensureThatArg(Object, Matcher) * @see #ensureThatContext(Object, Matcher) * @see #ensureThatState(Object, Matcher, String) * * @throws IllegalStateException if matcher does not {@link Matcher#matches(Object) match}. */ public static <T> T ensureThatState(final T field, final Matcher<T> matcher) { if (!matcher.matches(field)) { throw new IllegalStateException("illegal argument, expected: " + descriptionOf(matcher)); } return field; }
/** * To ensure that the current state of this object (instance fields) is correct. * * @see #ensureThatArg(Object, Matcher) * @see #ensureThatContext(Object, Matcher) * @see #ensureThatState(Object, Matcher, String) * * @throws IllegalStateException if matcher does not {@link Matcher#matches(Object) match}. */ public static <T> T ensureThatState(final T field, final Matcher<T> matcher) { if (!matcher.matches(field)) { throw new IllegalStateException("illegal argument, expected: " + descriptionOf(matcher)); } return field; }
/** * To ensure that the current context (<tt>NakedObjectsContext</tt>) is correct. * * @see #ensureThatArg(Object, Matcher) * @see #ensureThatState(Object, Matcher) * @see #ensureThatContext(Object, Matcher, String) * * @throws IllegalThreadStateException if matcher does not {@link Matcher#matches(Object) match}. */ public static <T> T ensureThatContext(final T contextProperty, final Matcher<T> matcher) { if (!matcher.matches(contextProperty)) { throw new IllegalThreadStateException("illegal argument, expected: " + descriptionOf(matcher)); } return contextProperty; }
/** * To ensure that the current context (<tt>NakedObjectsContext</tt>) is correct. * * @see #ensureThatArg(Object, Matcher) * @see #ensureThatState(Object, Matcher) * @see #ensureThatContext(Object, Matcher, String) * * @throws IllegalThreadStateException if matcher does not {@link Matcher#matches(Object) match}. */ public static <T> T ensureThatContext(final T contextProperty, final Matcher<T> matcher) { if (!matcher.matches(contextProperty)) { throw new IllegalThreadStateException("illegal argument, expected: " + descriptionOf(matcher)); } return contextProperty; }