/*
 * * Copyright (C) 2013-2015 Matt Baxter http://kitteh.org
 *
 * 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.kitteh.irc.client.library.util;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * Do you know the definition of sanity?
 */
public final class Sanity {
    private Sanity() {
    }

    /**
     * Checks if an object is null.
     *
     * @param object object to check
     * @param failMessage message to throw
     * @throws IllegalArgumentException if the object is null
     */
    public static void nullCheck(@Nullable Object object, @Nullable String failMessage) {
        if (object == null) {
            throw new IllegalArgumentException(failMessage);
        }
    }

    /**
     * Checks if an array is null or contains null elements.
     *
     * @param array array to check
     * @param failMessage message to throw
     * @throws IllegalArgumentException if null or contains null elements
     */
    public static void nullCheck(@Nullable Object[] array, @Nullable String failMessage) {
        Sanity.nullCheck((Object) array, failMessage);
        for (Object element : array) {
            Sanity.nullCheck(element, failMessage);
        }
    }

    /**
     * Checks if a boolean is true.
     *
     * @param bool value to test
     * @param failMessage message to throw
     * @throws IllegalArgumentException if false
     */
    public static void truthiness(boolean bool, @Nullable String failMessage) {
        if (!bool) {
            throw new IllegalArgumentException(failMessage);
        }
    }

    /**
     * Checks if a message contains CR, LF, or NUL.
     *
     * @param message message to check
     * @throws IllegalArgumentException if found
     */
    public static void safeMessageCheck(@Nonnull String message) {
        Sanity.safeMessageCheck(message, "message");
    }

    /**
     * Checks if a string contains CR, LF, or NUL.
     *
     * @param message string to check
     * @param name name of the string
     * @throws IllegalArgumentException if found
     */
    public static void safeMessageCheck(@Nonnull String message, @Nonnull String name) {
        Sanity.nullCheck(message, name + " cannot be null");
        for (char ch : message.toCharArray()) {
            if ((ch == '\n') || (ch == '\r') || (ch == '\0')) {
                throw new IllegalArgumentException(name + " cannot contain CR, LF, or NUL");
            }
        }
    }
}
@@ -1483,32 +1483,63 @@
 essage to throw%0A
+     * @return the sane object%0A
      * @throws I
@@ -1602,36 +1602,37 @@
   public static 
-void
+%3CT%3E T
  nullCheck(@Null
@@ -1636,22 +1636,17 @@
 ullable 
-Object
+T
  object,
@@ -1771,32 +1771,55 @@
 age);%0A        %7D%0A
+        return object;%0A
     %7D%0A%0A    /**%0A 
@@ -1955,32 +1955,63 @@
 essage to throw%0A
+     * @return the sane object%0A
      * @throws I
@@ -2094,20 +2094,23 @@
  static 
-void
+%3CT%3E T%5B%5D
  nullChe
@@ -2122,22 +2122,17 @@
 ullable 
-Object
+T
 %5B%5D array
@@ -2313,32 +2313,54 @@
 age);%0A        %7D%0A
+        return array;%0A
     %7D%0A%0A    /**%0A 
@@ -2811,32 +2811,64 @@
 essage to check%0A
+     * @return the safe message%0A
      * @throws I
@@ -2918,36 +2918,38 @@
   public static 
-void
+String
  safeMessageChec
@@ -2981,24 +2981,31 @@
 ) %7B%0A        
+return 
 Sanity.safeM
@@ -3186,16 +3186,48 @@
  string%0A
+     * @return the safe message%0A
      * @
@@ -3293,20 +3293,22 @@
  static 
-void
+String
  safeMes
@@ -3652,19 +3652,43 @@
 %7D%0A        %7D%0A
+        return message;%0A
     %7D%0A%7D

Return safe objects in Sanity