package com.nilhcem.droidcontn.utils;

/**
 * Preconditions inspired by
 * https://github.com/google/guava/blob/master/guava/src/com/google/common/base/Preconditions.java
 */
public final class Preconditions {

    private Preconditions() {
        throw new UnsupportedOperationException();
    }

    /**
     * Ensures the truth of an expression involving one or more parameters to the calling method.
     *
     * @param expression a boolean expression
     * @throws IllegalArgumentException if {@code expression} is false
     */
    public static void checkArgument(boolean expression) {
        if (!expression) {
            throw new IllegalArgumentException();
        }
    }
}

package com.nilhcem.droidcontn.utils;

import android.os.Looper;

import com.nilhcem.droidcontn.BuildConfig;

/**
 * Preconditions inspired by
 * https://github.com/google/guava/blob/master/guava/src/com/google/common/base/Preconditions.java
 */
public final class Preconditions {

    private Preconditions() {
        throw new UnsupportedOperationException();
    }

    /**
     * Ensures the truth of an expression involving one or more parameters to the calling method.
     *
     * @param expression a boolean expression
     * @throws IllegalArgumentException if {@code expression} is false
     */
    public static void checkArgument(boolean expression) {
        if (!expression) {
            throw new IllegalArgumentException();
        }
    }

    public static void checkOnMainThread() {
        if (BuildConfig.DEBUG) {
            if (!isOnMainThread()) {
                throw new IllegalStateException("This method should be called from the main thread");
            }
        }
    }

    public static void checkNotOnMainThread() {
        if (BuildConfig.DEBUG) {
            if (isOnMainThread()) {
                throw new IllegalStateException("This method must not be called on the main thread");
            }
        }
    }

    private static boolean isOnMainThread() {
        return Thread.currentThread() == Looper.getMainLooper().getThread();
    }
}

Add thread preconditions to ensure call is/is not on the main thread
Add thread preconditions to ensure call is/is not on the main thread
