+ /**
+ * Throw an instance of this exception if an expression evaluates to true. If the expression evaluates to false,
+ * this method does nothing.
+ *
+ * @param expression Expression to be evaluated
+ * @param source Statement source reference
+ * @param format Format string, according to {@link String#format(String, Object...)}.
+ * @param args Format string arguments, according to {@link String#format(String, Object...)}
+ * @throws SourceException if the expression evaluates to true.
+ */
+ public static void throwIf(final boolean expression, @Nonnull final StatementSourceReference source,
+ @Nonnull final String format, final Object... args) {
+ if (expression) {
+ throw new SourceException(source, format, args);
+ }
+ }
+
+ /**
+ * Throw an instance of this exception if an object is null. If the object is non-null, it will
+ * be returned as the result of this method.
+ *
+ * @param obj Object reference to be checked
+ * @param source Statement source reference
+ * @param format Format string, according to {@link String#format(String, Object...)}.
+ * @param args Format string arguments, according to {@link String#format(String, Object...)}
+ * @return Object if it is not null
+ * @throws SourceException if object is null
+ */
+ @Nonnull public static <T> T throwIfNull(final T obj, @Nonnull final StatementSourceReference source,
+ @Nonnull final String format, final Object... args) {
+ throwIf(obj == null, source, format, args);
+ return obj;
+ }
+