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 int getWidth(View view) {
    if (view == null) {
        throw new IllegalArgumentException("view is null");
    }/*from   w  w  w . jav  a 2  s  .  c  om*/

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

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", new Object[] { name }));
}

From source file:Main.java

static void checkPositive(int number, String name) {
    if (number <= 0)
        throw new IllegalArgumentException(String.format("%s must not be null", name));
}

From source file:Main.java

public static double getAspectRatio(Bitmap bitmap) {
    if (bitmap == null)
        throw new IllegalArgumentException("bitmap is null");

    return (double) bitmap.getWidth() / (double) bitmap.getHeight();
}

From source file:Main.java

public static boolean isSameType(Object array1, Object array2) {
    if ((array1 == null) || (array2 == null)) {
        throw new IllegalArgumentException("The Array must not be null");
    }/*from   w w  w  .  j  a v  a 2  s. co  m*/
    return array1.getClass().getName().equals(array2.getClass().getName());
}

From source file:Main.java

public static void isLegalHttpUrl(String url) {
    int idx = url.indexOf("://");
    if (idx == -1) {
        throw new IllegalArgumentException(url + " is not an right http url,no '://'");
    }//from   w w w  .  ja v  a 2s.  c  o m
    if (!url.startsWith("http")) {
        throw new IllegalArgumentException(url + " is not an right http url,no \"http\"");
    }

}

From source file:Main.java

static void checkPositive(int number, String name) {
    if (number <= 0)
        throw new IllegalArgumentException(String.format("%s must not be null", new Object[] { name }));
}

From source file:Main.java

public static double div(double v1, double v2, int scale) {
    if (scale < 0) {
        throw new IllegalArgumentException("The scale must be a positive integer or zero");
    }//from www  .j  a  va  2s  . com
    BigDecimal b1 = new BigDecimal(Double.toString(v1));
    BigDecimal b2 = new BigDecimal(Double.toString(v2));
    return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}

From source file:Main.java

public static String padWithZerosToMaxIntWidth(int paramInt) {
    if (paramInt < 0) {
        throw new IllegalArgumentException("value must be zero or greater");
    }/*from  w w w  .  j ava2s  . c  om*/
    return String.format(Locale.US, "%1$10s", new Object[] { Integer.valueOf(paramInt) }).replace(' ', '0');
}

From source file:Main.java

public static final double round(double v, int scale) {
    if (scale < 0) {
        throw new IllegalArgumentException("The scale must be a positive integer or zero");
    }/*  w w w  .ja  v a  2  s. com*/
    BigDecimal b = new BigDecimal(Double.toString(v));
    BigDecimal one = new BigDecimal("1");
    return (b.divide(one, scale, BigDecimal.ROUND_HALF_UP)).doubleValue();
}