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

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

From source file:Main.java

public static String escapeSingleQuotes(final String inputString) {
    if (inputString == null) {
        throw new IllegalArgumentException("null inputString");
    }/*ww w  .j  av  a 2 s.  c om*/

    return inputString.replace("'", "\\'");

}

From source file:Main.java

public static int sum(List<Integer> list) {

    if (list == null) {
        throw new IllegalArgumentException("Can't sum values for NULL list");
    }/*from   w ww. ja v  a 2s .com*/

    return list.stream().parallel().reduce(0, (sum, val) -> sum + val);

}

From source file:Main.java

public static <T> void validateScriptInterface(Class<T> service) {
    if (!service.isInterface()) {
        throw new IllegalArgumentException("API declarations must be interfaces.");
    }/*from  www  .  j a  v  a 2s  .c  om*/
    if (service.getInterfaces().length > 0) {
        throw new IllegalArgumentException("Script interfaces must not extend other interfaces.");
    }
}

From source file:Main.java

static void checkNotNull(Object o, String name) {
    if (o == null)
        throw new IllegalArgumentException(String.format("%s must be not null", name));
}

From source file:Main.java

public static int bytesToInt(byte[] inBytes, int offset) {
    if (inBytes.length - offset < 4) {
        throw new IllegalArgumentException(inBytes.length + " " + offset);
    }/*from w  ww .  j a  va2  s .  c  o  m*/

    return inBytes[offset + 3] & 0xFF | (inBytes[offset + 2] & 0xFF) << 8 | (inBytes[offset + 1] & 0xFF) << 16
            | (inBytes[offset] & 0xFF) << 24;
}

From source file:Main.java

public static int[] range(int from, int to) {
    if (to < from)
        throw new IllegalArgumentException("to must be larger than from");
    int[] out = new int[to - from];
    for (int i = 0; i < out.length; i++)
        out[i] = from + i;//from ww  w.  java 2s  .c o  m
    return out;
}

From source file:Main.java

static void checkAngle(int angle) {
    if (angle < 0 || angle > 360)
        throw new IllegalArgumentException(String.format("Illegal angle %d: must be >=0 and <= 360", angle));
}

From source file:Main.java

public static byte[] createZeroBytes(int length) {
    if (length <= 0)
        throw new IllegalArgumentException("length must be gt 0");

    byte[] bytes = new byte[length];
    Arrays.fill(bytes, (byte) 0);
    return bytes;
}

From source file:Main.java

public static int getMeasuredHeight(View view) {
    if (view == null) {
        throw new IllegalArgumentException("view is null");
    }//from   w w  w.j a v a 2 s . com

    view.measure(0, 0);
    return view.getMeasuredHeight();
}