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

private static String getSafePrintChars(byte[] byteArray) {
    if (byteArray == null) {
        // return "" instead?
        throw new IllegalArgumentException("Argument 'byteArray' cannot be null");
    }/*  w  w w  . j  a  v a 2s. c o m*/
    return getSafePrintChars(byteArray, 0, byteArray.length);
}

From source file:Main.java

public static void assertNotNull(Object o, String errMsg) {
    if (o == null) {
        throw new IllegalArgumentException(errMsg);
    }/*from   ww w . j  a  va 2  s . com*/
}

From source file:Main.java

public static int countMatches(String res, String findString) {
    if (res == null) {
        return 0;
    }// ww w.  j a v  a  2 s.  c  o m

    if (findString == null || findString.length() == 0) {
        throw new IllegalArgumentException("The param findString cannot be null or 0 length.");
    }

    return (res.length() - res.replace(findString, "").length()) / findString.length();
}

From source file:Main.java

public static Object get(Context context, String name) {
    if (context == null || name == null) {
        throw new IllegalArgumentException("Context and key must not be null");
    }/*from   w ww . j a  v a 2 s  .com*/
    Object systemService = context.getSystemService(name);
    if (systemService == null) {
        context = context.getApplicationContext();
        systemService = context.getSystemService(name);
    }
    if (systemService == null) {
        throw new IllegalStateException(name + " not available");
    }
    return systemService;
}

From source file:Main.java

public static <T> Stream<List<T>> batches(List<T> source, int length) {
    if (length <= 0)
        throw new IllegalArgumentException("length = " + length);
    int size = source.size();
    if (size <= 0)
        return Stream.empty();
    int fullChunks = (size - 1) / length;
    return IntStream.range(0, fullChunks + 1)
            .mapToObj(n -> source.subList(n * length, n == fullChunks ? size : (n + 1) * length));
}

From source file:Main.java

public static byte[] uint32ToByteArray(long src) throws IllegalArgumentException {
    if (src < 0 || src > UINT32_MAX) {
        throw new IllegalArgumentException("the input value " + src + " is out of the range of uint32");
    }//w ww  .  j a v  a 2  s.c o m

    byte[] dest = new byte[4];
    int mask = 0xff;

    for (int i = 0; i < 4; i++) {
        dest[i] = (byte) ((src >> (i * 8)) & mask);
    }

    return dest;
}

From source file:Main.java

/**
 * Converts absolute command's byte array an argb color integer
 *///from w  w  w.java 2 s.  c  o m
public static int bufferToInt(byte[] buffer, int size) {
    if (null == buffer || buffer.length != size) {
        throw new IllegalArgumentException("Buffer must be of size: " + size);
    }
    return (0xFF << 24) | (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
}

From source file:Main.java

public static Color toColor(Node n) {
    if (!n.getNodeName().equals("color")) {
        throw new IllegalArgumentException(n.getNodeName());
    }/*from  w w w.  j a v a 2  s.c  om*/
    NamedNodeMap map = n.getAttributes();
    String s = map.getNamedItem("name").getNodeValue();
    if (s.equals("white")) {
        return Color.WHITE;
    } else if (s.equals("green")) {
        return Color.GREEN;
    } else if (s.equals("pink")) {
        return Color.PINK;
    } else if (s.equals("cyan")) {
        return Color.CYAN;
    } else if (s.equals("yellow")) {
        return Color.YELLOW;
    } else {
        return Color.WHITE;
    }
}

From source file:Main.java

public static Number getNumber(Collection<?> list) {
    Object obj = getUnique(list);
    if (obj instanceof Number)
        return ((Number) obj);
    throw new IllegalArgumentException("list result is not instanceof Number");
}

From source file:Main.java

public static void mapAction(JComponent c, int condition, KeyStroke keyStroke, Action action) {
    Object key = action.getValue(Action.NAME);
    if (key == null)
        throw new IllegalArgumentException("The provided action must " + "have a name defined");
    mapAction(c, condition, key, keyStroke, action);
}