1 package com.atlassian.sal.core.util;
2
3 public class Assert {
4 /**
5 * Check that {@code reference} is not {@code null}. If it is, throw a
6 * {@code IllegalArgumentException}.
7 *
8 * @param reference reference to check is {@code null} or not
9 * @return {@code reference} so it may be used
10 * @throws IllegalArgumentException if {@code reference} is {@code null}
11 */
12 public static <T> T notNull(final T reference) {
13 if (reference == null) {
14 throw new IllegalArgumentException();
15 }
16 return reference;
17 }
18
19 /**
20 * Check that {@code reference} is not {@code null}. If it is, throw a
21 * {@code IllegalArgumentException}.
22 *
23 * @param reference reference to check is {@code null} or not
24 * @param errorMessage message passed to the {@code IllegalArgumentException} constructor
25 * to give more context when debugging
26 * @return {@code reference} so it may be used
27 * @throws IllegalArgumentException if {@code reference} is {@code null}
28 */
29 public static <T> T notNull(final T reference, final Object errorMessage) {
30 if (reference == null) {
31 throw new IllegalArgumentException(String.valueOf(errorMessage));
32 }
33 return reference;
34 }
35 }