View Javadoc

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