Example usage for java.lang IllegalArgumentException IllegalArgumentException

List of usage examples for java.lang IllegalArgumentException IllegalArgumentException

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException IllegalArgumentException.

Prototype

public IllegalArgumentException(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:Main.java

public static int nextPowerOf2(int n) {
    if (n <= 0 || n > (1 << 30))
        throw new IllegalArgumentException("n is invalid: " + n);
    n -= 1;//from  w w  w  .  j  a  va2s  .c o  m
    n |= n >> 16;
    n |= n >> 8;
    n |= n >> 4;
    n |= n >> 2;
    n |= n >> 1;
    return n + 1;
}

From source file:Main.java

public static void checkPositiveOrZero(float number, String name) {
    if (number < 0)
        throw new IllegalArgumentException(String.format("%s %d must be positive", name, number));
}

From source file:Main.java

public static <T> T notNull(T argument, String name) {
    if (argument == null) {
        throw new IllegalArgumentException(name + " should not be null!");
    } else {/*from   ww  w. j a  va  2 s.  c o m*/
        return argument;
    }
}

From source file:Main.java

public static int factorial(int start, int end) {
    if (start < 0) {
        throw new IllegalArgumentException("x must be>=0");
    }/*from  w w w .ja  v  a 2s. c o  m*/
    if (start == end) {
        return end;
    } else if (start > end)
        return start * factorial(start - 1, end);
    else
        throw new IllegalArgumentException("start must be >= end");

}

From source file:Main.java

public static void checkReflectRorate(float degree) {
    if (degree >= 90 || degree < 0)
        throw new IllegalArgumentException("reflectDegree must be [0,90)!");
}

From source file:Main.java

public final static long getLong(byte[] buf) {
    if (buf == null) {
        throw new IllegalArgumentException("byte array is null!");
    }/*w ww  .  j ava 2  s  .  c  o  m*/
    if (buf.length > 8) {
        throw new IllegalArgumentException("byte array size > 8 !");
    }
    long r = 0;
    for (int i = 0; i < buf.length; i++) {
        r <<= 8;
        r |= (buf[i] & 0x00000000000000ff);
    }
    return r;
}

From source file:Main.java

static void checkColors(int[] colors) {
    if (colors == null || colors.length == 0) {
        throw new IllegalArgumentException("You must provide at least 1 color");
    }/*from w  w w  . j a  v a  2  s .  c  o  m*/
}

From source file:Main.java

public static void assertTrue(boolean condition, String message) {
    if (!condition) {
        throw new IllegalArgumentException(message);
    }/*from w w  w  .  j  a  va  2s .c o  m*/
}

From source file:Main.java

public static String getFilenameFromPath(String path) {
    if (path == null) {
        throw new IllegalArgumentException("path cannot be null");
    }//from w  w  w .j a  va 2s .c  o m
    int lastIndexOf = path.lastIndexOf("/");
    if (lastIndexOf == -1) {
        return path;
    }
    return path.substring(lastIndexOf + 1, path.length());
}

From source file:Main.java

public static void checkArgument(boolean expression, Object errorMsg) {
    if (!expression)
        throw new IllegalArgumentException(String.valueOf(errorMsg));
}