Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2010-2013 the original author or authors
  * 
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
  * "Software"), to deal in the Software without restriction, including
  * without limitation the rights to use, copy, modify, merge, publish,
  * distribute, sublicense, and/or sell copies of the Software, and to
  * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 */
package org.jmxtrans.embedded.util;
import  javax.annotation.Nullable;

Inspired by com.google.common.base.Preconditions

Author(s):
Cyrille Le Clerc
public class Preconditions {
    private Preconditions() {
    }

    
Check the nullity of the given reference.

Parameters:
reference reference to check
Returns:
the given reference
Throws:
NullPointerException if the given reference is null
    public static <T> T checkNotNull(T referencethrows NullPointerException {
        return checkNotNull(referencenull);
    }

    
Check the nullity of the given reference.

Parameters:
reference reference to check
message exception message, can be null
Returns:
the given reference
Throws:
NullPointerException if the given reference is null
    public static <T> T checkNotNull(T reference, @Nullable String messagethrows NullPointerException {
        if (reference == null) {
            throw new NullPointerException(message == null ? "" : message);
        }
        return reference;
    }

    
Check the nullity and emptiness of the given reference.

Parameters:
reference reference to check
Returns:
the given reference
Throws:
IllegalArgumentException if the given reference is null
    public static String checkNotEmpty(String referencethrows IllegalArgumentException {
        return checkNotEmpty(referencenull);
    }

    
Check the nullity and emptiness of the given reference.

Parameters:
reference reference to check
message exception message, can be null
Returns:
the given reference
Throws:
IllegalArgumentException if the given reference is null
    public static String checkNotEmpty(String reference, @Nullable String messagethrows IllegalArgumentException {
        if (reference == null || reference.isEmpty()) {
            throw new IllegalArgumentException(message == null ? "Null or empty value" : message);
        }
        return reference;
    }
New to GrepCode? Check out our FAQ X