209 * constructors with multiple parameters, as demonstrated below:
210 * <blockquote><pre>
211 * public Foo(Bar bar, Baz baz) {
212 * this.bar = Objects.requireNonNull(bar, "bar must not be null");
213 * this.baz = Objects.requireNonNull(baz, "baz must not be null");
214 * }
215 * </pre></blockquote>
216 *
217 * @param obj the object reference to check for nullity
218 * @param message detail message to be used in the event that a {@code
219 * NullPointerException} is thrown
220 * @param <T> the type of the reference
221 * @return {@code obj} if not {@code null}
222 * @throws NullPointerException if {@code obj} is {@code null}
223 */
224 public static <T> T requireNonNull(T obj, String message) {
225 if (obj == null)
226 throw new NullPointerException(message);
227 return obj;
228 }
229 }
|
209 * constructors with multiple parameters, as demonstrated below:
210 * <blockquote><pre>
211 * public Foo(Bar bar, Baz baz) {
212 * this.bar = Objects.requireNonNull(bar, "bar must not be null");
213 * this.baz = Objects.requireNonNull(baz, "baz must not be null");
214 * }
215 * </pre></blockquote>
216 *
217 * @param obj the object reference to check for nullity
218 * @param message detail message to be used in the event that a {@code
219 * NullPointerException} is thrown
220 * @param <T> the type of the reference
221 * @return {@code obj} if not {@code null}
222 * @throws NullPointerException if {@code obj} is {@code null}
223 */
224 public static <T> T requireNonNull(T obj, String message) {
225 if (obj == null)
226 throw new NullPointerException(message);
227 return obj;
228 }
229
230 /**
231 * Returns {@code true} if the provided reference is {@code null} otherwise
232 * returns {@code false}.
233 *
234 * @apiNote This method exists to be used as a
235 * {@link java.util.function.Predicate}, {@code filter(Objects::isNull)}
236 *
237 * @param obj a reference to be checked against {@code null}
238 * @return {@code true} if the provided reference is {@code null} otherwise
239 * {@code false}
240 *
241 * @see java.util.function.Predicate
242 * @since 1.8
243 */
244 public static boolean isNull(Object obj) {
245 return obj == null;
246 }
247
248 /**
249 * Returns {@code true} if the provided reference is non-{@code null}
250 * otherwise returns {@code false}.
251 *
252 * @apiNote This method exists to be used as a
253 * {@link java.util.function.Predicate}, {@code filter(Objects::nonNull)}
254 *
255 * @param obj a reference to be checked against {@code null}
256 * @return {@code true} if the provided reference is non-{@code null}
257 * otherwise {@code false}
258 *
259 * @see java.util.function.Predicate
260 * @since 1.8
261 */
262 public static boolean nonNull(Object obj) {
263 return obj != null;
264 }
265 }
|