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 Bitmap decodeYUV420SP(byte[] rgbBuf, byte[] yuv420sp, int width, int height) {
    final int frameSize = width * height;
    if (rgbBuf == null)
        throw new NullPointerException("buffer 'rgbBuf' is null");
    if (rgbBuf.length < frameSize * 3)
        throw new IllegalArgumentException(
                "buffer 'rgbBuf' size " + rgbBuf.length + " < minimum " + frameSize * 3);

    if (yuv420sp == null)
        throw new NullPointerException("buffer 'yuv420sp' is null");

    if (yuv420sp.length < frameSize * 3 / 2)
        throw new IllegalArgumentException(
                "buffer 'yuv420sp' size " + yuv420sp.length + " < minimum " + frameSize * 3 / 2);

    int i = 0, y = 0;
    int uvp = 0, u = 0, v = 0;
    int y1192 = 0, r = 0, g = 0, b = 0;

    for (int j = 0, yp = 0; j < height; j++) {
        uvp = frameSize + (j >> 1) * width;
        u = 0;/*from www. j ava2s.co m*/
        v = 0;
        for (i = 0; i < width; i++, yp++) {
            y = (0xff & ((int) yuv420sp[yp])) - 16;
            if (y < 0)
                y = 0;
            if ((i & 1) == 0) {
                v = (0xff & yuv420sp[uvp++]) - 128;
                u = (0xff & yuv420sp[uvp++]) - 128;
            }

            y1192 = 1192 * y;
            r = (y1192 + 1634 * v);
            g = (y1192 - 833 * v - 400 * u);
            b = (y1192 + 2066 * u);

            if (r < 0)
                r = 0;
            else if (r > 262143)
                r = 262143;
            if (g < 0)
                g = 0;
            else if (g > 262143)
                g = 262143;
            if (b < 0)
                b = 0;
            else if (b > 262143)
                b = 262143;

            rgbBuf[yp * 3] = (byte) (r >> 10);
            rgbBuf[yp * 3 + 1] = (byte) (g >> 10);
            rgbBuf[yp * 3 + 2] = (byte) (b >> 10);
        }
    }
    return BitmapFactory.decodeByteArray(rgbBuf, 0, rgbBuf.length);
}

From source file:Main.java

/**
 * This method returns the number of Seconds in a long time format.<br>
 * @param milliseconds {@link Long} long number representing a time
 * @return {@link Long} number of Seconds from millisecond given.
 * @throws IllegalArgumentException {@link Exception} if argument given is less of zero 
 *//*from  w  ww  .  j  av  a 2  s  .  com*/
public static long getSecondsFromMillisecond(long milliseconds) throws IllegalArgumentException {
    if (milliseconds < 0)
        throw new IllegalArgumentException("Milliseconds given can not be less of zero.");

    return milliseconds / 1000;
}

From source file:Main.java

/**
 * Convert a one or two byte array of bytes to an unsigned two-byte integer.
 * /* w  w w.j  ava2 s . c  o  m*/
 * <p><b>NOTE:</b> This function mostly exists as an example of how to use 
 * twoBytesToUnsignedInt(). It is unlikely the use case it embodies
 * will occur often.</p>
 * 
 * @param ba
 * @return
 */
public static int byteArrayToUnsignedInt(byte[] byteArray) {
    if (byteArray.length > Integer.SIZE)
        throw new IllegalArgumentException("Array length must match one of the following types:\n Byte=="
                + Byte.SIZE + ", Short==" + Short.SIZE + ", Integer==" + Integer.SIZE);

    return (int) byteArrayToUnsignedLong(byteArray);
}

From source file:Main.java

/**
 * call n md5//from  ww w.  j  a  va 2  s . c o m
 * For example,
 *      if count equal 2, it will call twice md5,  md5(md5(string))
 * @param count
 * @return
 */
public static String md5N(final String string, final int count) {
    if (count <= 0)
        throw new IllegalArgumentException("count can't < 0");
    String result = null;
    for (int i = 0; i < count; i++) {
        result = md5(string);
    }
    return result;
}

From source file:Main.java

/**
 * @Description drawable - > bitmap//from  w w w .  ja v  a  2s  .  c o  m
 * @param drawable
 * @return
 */
public static Bitmap Drawable2Bitmap(Drawable drawable) {
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    if (width <= 0 || height <= 0) {
        throw new IllegalArgumentException("error argument: the argument drawable's width or height is 0.");
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);
    return bitmap;
}

From source file:Main.java

@SafeVarargs
public static <E> Collection<Collection<E>> cartesianProduct(Collection<E>... collections) {
    // Convert collections to Lists to safely iterate
    List<List<E>> lists = new ArrayList<>(collections.length);
    for (int i = 0; i < collections.length; i++) {
        if (collections[i].isEmpty()) {
            throw new IllegalArgumentException("Input collections must not be empty");
        }/*from  w w w.  j a  va  2s  .  c  om*/
        lists.add(new ArrayList<E>(collections[i]));
    }

    List<Collection<E>> result = new ArrayList<>();
    int[] indexes = new int[collections.length]; // Indexes are initilized to 0 according to the spec
    boolean finished;
    do {
        finished = true;
        List<E> combination = new ArrayList<>();
        for (int i = 0; i < lists.size(); i++) {
            combination.add(lists.get(i).get(indexes[i]));
        }
        result.add(combination);
        for (int i = 0; i < indexes.length; i++) {
            if (indexes[i] < collections[i].size() - 1) {
                indexes[i]++;
                finished = false;
                break;
            }
        }
    } while (!finished);
    return result;
}

From source file:Main.java

public static boolean isIsracardValid(String cardNumber) {
    int sum = 0;/*from   w w w .  j  a v a  2  s.c  o  m*/
    int len = cardNumber.length();

    // If the number is less than 9 digits
    if (len == 8) {
        cardNumber = "0" + cardNumber;
        len++;
    }

    for (int i = 0; i < len; i++) {
        final char c = cardNumber.charAt(i);
        if (!Character.isDigit(c)) {
            throw new IllegalArgumentException(String.format("Not a digit: '%s'", c));
        }

        final int digit = Character.digit(c, 10);
        sum = sum + (digit * (9 - i));
    }
    return sum % 11 == 0;
}

From source file:ReflectionUtils.java

public static Field getPropertyField(Class<?> beanClass, String property) throws NoSuchFieldException {
    if (beanClass == null)
        throw new IllegalArgumentException("beanClass cannot be null");

    Field field = null;/*from  w w w. j ava 2  s  .c o m*/
    try {
        field = beanClass.getDeclaredField(property);
    } catch (NoSuchFieldException e) {
        if (beanClass.getSuperclass() == null)
            throw e;
        // look for the field in the superClass
        field = getPropertyField(beanClass.getSuperclass(), property);
    }
    return field;
}

From source file:Main.java

private static View checkView(View v) {
    if (v == null) {
        throw new IllegalArgumentException("View doesn't exist");
    }//from  www. j  a  v a  2s .  c  o m
    return v;
}

From source file:Main.java

/**
 * Parse func ref from server/*from  ww w.ja va  2s.  c o m*/
 * @param ref form FUNC(Table.Col)
 * @return String[] {Table, Col, FUNC}
 */
public static String[] getFuncTableColRef(String ref) throws IllegalArgumentException {
    String[] res = null;
    String regex = "[" + FUNC_DELIMS + "\\" + DOT + "]";
    res = ref.split(regex);
    if (res.length != 3)
        throw new IllegalArgumentException("Wrong ref " + ref);
    String[] temp = new String[3];
    temp[0] = res[1];
    temp[1] = res[2];
    temp[2] = res[0];
    return temp;
}