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() 

Source Link

Document

Constructs an IllegalArgumentException with no detail message.

Usage

From source file:Main.java

public static double dot(float[] v1, float[] v2) {
    if (v1.length != v2.length) {
        throw new IllegalArgumentException();
    }/*from   w ww  .  j a  va  2  s .  co  m*/
    double dot = 0.0;
    for (int i = 0; i < v1.length; i++) {
        dot += v1[i] * v2[i];
    }
    return dot;
}

From source file:Main.java

private static byte[] hex2byte(byte[] b) {
    if ((b.length % 2) != 0)
        throw new IllegalArgumentException();
    byte[] b2 = new byte[b.length / 2];
    for (int n = 0; n < b.length; n += 2) {
        String item = new String(b, n, 2);
        b2[n / 2] = (byte) Integer.parseInt(item, 16);
    }/*from   www.j  a  v  a  2  s. c om*/
    return b2;
}

From source file:Main.java

public static double round(double value, int places) {
    if (places < 0) {
        throw new IllegalArgumentException();
    }//from w w  w. j a  v a  2s . com

    long factor = (long) Math.pow(10, places);
    value = value * factor;
    long tmp = Math.round(value);
    return (double) tmp / factor;
}

From source file:Main.java

public static long bytes2long(byte[] bytes, int offset) {
    if (bytes == null || bytes.length < (offset + 7)) {
        throw new IllegalArgumentException();
    }/*from  w  w  w  .  j a  v  a 2 s  .  co m*/
    long l = 0l;
    l = bytes[offset] & 0xFF;
    l = (l << 8) | (bytes[offset + 1] & 0xff);
    l = (l << 8) | (bytes[offset + 2] & 0xff);
    l = (l << 8) | (bytes[offset + 3] & 0xff);
    l = (l << 8) | (bytes[offset + 4] & 0xff);
    l = (l << 8) | (bytes[offset + 5] & 0xff);
    l = (l << 8) | (bytes[offset + 6] & 0xff);
    l = (l << 8) | (bytes[offset + 7] & 0xff);
    return l;
}

From source file:Main.java

public static int nextPowerOf2(int n) {
    if (n <= 0 || n > (1 << 30)) {
        throw new IllegalArgumentException();
    }/* w  ww.  j a v a  2s .c o m*/
    n -= 1;
    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 Object copyArray(final Object input) {
    final Class type = input.getClass();
    if (!type.isArray()) {
        throw new IllegalArgumentException();
    }/*from   www.  ja  v  a 2 s  . c  om*/
    final int length = Array.getLength(input);
    final Class componentType = type.getComponentType();

    final Object result = Array.newInstance(componentType, length);
    for (int idx = 0; idx < length; idx++) {
        Array.set(result, idx, Array.get(input, idx));
    }
    return result;
}

From source file:Main.java

private static double round(double value, int places) {
    if (places < 0)
        throw new IllegalArgumentException();

    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(places, RoundingMode.HALF_UP);
    return bd.doubleValue();
}

From source file:Main.java

public static float round(double value, int places) {
    if (places < 0)
        throw new IllegalArgumentException();

    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(places, RoundingMode.HALF_UP);
    return bd.floatValue();
}

From source file:Main.java

public static ByteBuffer makeByteBuffer(byte[] array) {
    if (array == null)
        throw new IllegalArgumentException();

    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length);
    byteBuffer.order(ByteOrder.nativeOrder());
    byteBuffer.put(array);/*  w w w  .  java 2s  . c o  m*/
    byteBuffer.position(0);
    return byteBuffer;
}

From source file:Main.java

static void checkNotPrimitive(Type paramType) {
    if (((paramType instanceof Class)) && (((Class) paramType).isPrimitive()))
        throw new IllegalArgumentException();
}