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 double roundDouble(double v, int scale) {

    if (scale < 0) {

        throw new IllegalArgumentException(

                "The scale must be a positive integer or zero");

    }/*  ww w . ja  v  a  2 s.  c o m*/

    BigDecimal b = new BigDecimal(Double.toString(v));

    BigDecimal one = new BigDecimal("1");

    return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();

}

From source file:Main.java

public static byte[] copyOfRange(byte[] original, int from, int to) {
    int newLength = to - from;
    if (newLength < 0)
        throw new IllegalArgumentException("");
    byte[] copy = new byte[newLength];
    System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));

    return copy;//  w  w  w.jav a 2  s. c  o m

}

From source file:Main.java

public static void setNdHide(View view, Object isHide) {
    if (!(isHide instanceof Boolean)) {
        throw new IllegalArgumentException("isHide must be boolean in setNdHide(isHide)!");
    }/*from  ww w .j  av a2 s.  c o m*/
    if ((Boolean) isHide) {
        view.setVisibility(View.GONE);
    } else {
        view.setVisibility(View.VISIBLE);
    }
}

From source file:Main.java

public static byte[] copyOfRange(byte[] original, int from, int to) {
    int newLength = to - from;
    if (newLength < 0) {
        throw new IllegalArgumentException(from + " > " + to);
    } else {//ww w. j  a  v a 2s .  c om
        byte[] copy = new byte[newLength];
        System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
        return copy;
    }
}

From source file:Main.java

public static String getAsciiString(final byte[] data) {
    if (data == null) {
        throw new IllegalArgumentException("Parameter may not be null");
    }/*w ww. ja v  a  2 s  . c om*/

    try {
        return new String(data, "US-ASCII");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static long parseNumber(byte[] buf, int len, boolean bigEndian) {
    if (buf == null || buf.length == 0) {
        throw new IllegalArgumentException("byte array is null or empty!");
    }/*from w  w  w.ja v a  2  s  .co m*/

    int mlen = Math.min(len, buf.length);
    long r = 0;
    if (bigEndian)
        for (int i = 0; i < mlen; i++) {
            r <<= 8;
            r |= (buf[i] & 0xff);
        }
    else
        for (int i = mlen - 1; i >= 0; i--) {
            r <<= 8;
            r |= (buf[i] & 0xff);
        }
    return r;
}

From source file:Main.java

public static byte[] hexStringToByteArray(String s) {
    if ((s.length() % 2) != 0) {
        throw new IllegalArgumentException("Bad input string: " + s);
    }//from  w  w  w . ja v a2 s.  co m

    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
    }
    return data;
}

From source file:Main.java

public static String[] splitQName(String qualifiedName) {
    if (qualifiedName == null) {
        throw new IllegalArgumentException("Null QName");
    }/* w w w  .j  a v  a2 s  .  co m*/
    int idx = qualifiedName.indexOf(':');
    String[] parts = { null, null };
    if (idx >= 0) {
        parts[0] = qualifiedName.substring(0, idx);
        parts[1] = qualifiedName.substring(idx + 1);
    } else {
        parts[0] = XMLConstants.DEFAULT_NS_PREFIX;
        parts[1] = qualifiedName;
    }
    return parts;
}

From source file:Main.java

public static void assertDir(File candidate) {
    if (!candidate.exists()) {
        throw new IllegalArgumentException(candidate.getPath() + " does not exist.");
    }// w w w  . ja  v a 2  s .co  m
    if (!candidate.isDirectory()) {
        throw new IllegalArgumentException(candidate + " is not a directory.");
    }
}

From source file:Main.java

static <T> void validateInterface(Class<T> clientInterface) {
    if (!clientInterface.isInterface()) {
        throw new IllegalArgumentException("Monkey, debe ser una interfaz");
    }//  ww w  . ja v  a  2  s . c om

    if (clientInterface.getInterfaces().length > 0) {
        throw new IllegalArgumentException("Monkey, no debe implementar de otra interfaz");
    }
}