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 <T> T getMapOnlyValue(Map<? extends Object, T> map) {
    if (map.size() != 1) {
        throw new IllegalArgumentException("Can't get map only value, it has " + map.size() + " elements");
    }/*from w w  w  .j  a v a2  s  .co m*/
    return map.values().iterator().next();
}

From source file:Main.java

static void checkColors(int[] colors) {
    if (colors == null || colors.length == 0)
        throw new IllegalArgumentException("You must provide at least 1 color");
}

From source file:Main.java

public static void isTrue(boolean condition, String message) {
    if (!condition) {
        throw new IllegalArgumentException(message);
    }// ww w  .j av a  2s .  co  m
}

From source file:Main.java

static void checkPositiveOrZero(float number, String name) {
    if (number < 0.0F)
        throw new IllegalArgumentException(
                String.format("%s %d must be positive", new Object[] { name, Float.valueOf(number) }));
}

From source file:Main.java

public static int getDaysInMonth(int month, int year) {
    switch (month) {
    default://from   w  w w.  j  a  v a  2  s .com
        throw new IllegalArgumentException("Invalid Month");
    case 0:
    case 2:
    case 4:
    case 6:
    case 7:
    case 9:
    case 11:
        return 31;
    case 3:
    case 5:
    case 8:
    case 10:
        return 30;
    case 1:
        if (year % 4 == 0)
            return 29;
        return 28;
    }
}

From source file:Main.java

static void assertValidEventType(String eventType) throws IllegalArgumentException {
    if (eventType == null || eventType == "") {
        throw new IllegalArgumentException("Event Type is invalid");
    }//from www  . ja v a 2s. c  om
}

From source file:Main.java

static void checkColors(int[] colors) {
    if ((colors == null) || (colors.length == 0))
        throw new IllegalArgumentException("You must provide at least 1 color");
}

From source file:Main.java

public static float roundFloat(Float v, int scale) {

    if (scale < 0) {

        throw new IllegalArgumentException(

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

    }//from  w  w w  .ja va2s . c  o m

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

    BigDecimal one = new BigDecimal("1");

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

}

From source file:Main.java

public static Context getContext() {
    if (context == null)
        throw new IllegalArgumentException("context cannot be null!");
    return context;
}

From source file:Main.java

public static boolean isSameDay(Calendar cal1, Calendar cal2) {
    if (cal1 == null || cal2 == null)
        throw new IllegalArgumentException("The dates must not be null");
    return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
            && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
}