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 String[] range(char start, char end) {
    if (start >= end)
        throw new IllegalArgumentException("Start >= end");

    String[] charsRange = new String[end - start + 1];

    int idx = 0;/* w ww .j  a va  2 s  .  c  o  m*/
    for (char value = start; value <= end; value++) {
        charsRange[idx++] = value + "";
    }

    return charsRange;
}

From source file:Main.java

public static int safeLongToInt(long l) {
    int i = (int) l;
    if ((long) i != l) {
        throw new IllegalArgumentException(l + " cannot be cast to int without changing its value.");
    }//from   w  w  w  .  j  a  v  a  2  s  . c  o m
    return i;
}

From source file:Main.java

private static byte[] getLengthBytes(int packageLength) {
    if (packageLength > 65535) {
        throw new IllegalArgumentException("packageLength is too large");
    }//from w w w.j  av  a2  s.  co m
    byte lByte = (byte) (packageLength & 0x00ff);
    byte hByte = (byte) ((packageLength & 0xff00) >> 0x08);
    return new byte[] { lByte, hByte };
}

From source file:Main.java

public static final void assertNotNull(String name, Object object) {
    if (object == null) {
        throw new IllegalArgumentException("The argument '" + name + "' is null");
    }// w  w  w. j a  v a2s  . co  m
}

From source file:Main.java

public static double dotProd(double[] a, double[] b) {
    if (a.length != b.length) {
        throw new IllegalArgumentException("The dimensions have to be equal!");
    }/*from   w  w  w .j  a  v  a2 s  .  c  om*/
    double sum = 0;
    for (int i = 0; i < a.length; i++) {
        sum += a[i] * b[i];
    }
    return sum;
}

From source file:Main.java

static <T> void validateServiceClass(Class<T> paramClass) {
    if (!paramClass.isInterface())
        throw new IllegalArgumentException("Only interface endpoint definitions are supported.");
    if (paramClass.getInterfaces().length > 0)
        throw new IllegalArgumentException("Interface definitions must not extend other interfaces.");
}

From source file:Main.java

static void checkSpeed(float speed) {
    if (speed <= 0f)
        throw new IllegalArgumentException("Speed must be >= 0");
}

From source file:Main.java

public static int longToInt(long l) {
    if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
        throw new IllegalArgumentException(l + " cannot be cast to int without changing its value.");
    }//  www.j a  v  a 2 s.c o m
    return (int) l;
}

From source file:Main.java

public final static int getInt(byte[] buf) {
    if (buf == null) {
        throw new IllegalArgumentException("byte array is null!");
    }/*from   w  w w.j a va  2s . co m*/
    if (buf.length > 4) {
        throw new IllegalArgumentException("byte array size > 4 !");
    }
    int r = 0;
    for (int i = 0; i < buf.length; i++) {
        r <<= 8;
        r |= (buf[i] & 0x000000ff);
    }
    return r;
}

From source file:Main.java

static void checkAngle(int angle) {
    if (angle < 0 || angle > 360) {
        throw new IllegalArgumentException(
                String.format(Locale.CHINA, "Illegal angle %d: must be >=0 and <= 360", angle));
    }//w  w  w . j av  a2 s. co m
}