summaryrefslogtreecommitdiffstats
blob: f9bc87acbabb72d876cd4ad57a0c88f3d31d2a7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * Copyright (c) 2012, Isode Limited, London, England.
 * All rights reserved.
 */

package com.isode.stroke.base;

/**
 * Helper to check for nulls.
 */
public class NotNull {

    /**
     * Throws a NullPointerException if null.
     * @param o Object to check for non-nullness
     */
    public static void exceptIfNull(Object o) {
        if (o == null) {
            throw new NullPointerException();
        }
    }

    /**
     * Throws a NullPointerException if null.
     * @param o Object to check for non-nullness
     * @param name Variable name to include in error.
     */
    public static void exceptIfNull(Object o, String name) {
        if (name == null) {
            throw new NullPointerException("Variable name passed to exceptIfNull must not be null");
        }
        if (o == null) {
            throw new NullPointerException(name + " must not be null");
        }
    }
}