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 void setText(TextView textView, String text) {
    if (textView != null) {
        if (text == null)
            text = "";
        textView.setText(text);/*  w w  w  .j a  v a2s  .c o m*/
    } else {
        throw new IllegalArgumentException("A view is null in your parameters.");
    }
}

From source file:StringUtilities.java

/**
 * Capicalizes the first letter of a string
 * @param str the string to be capitalized
 * @return a capitalized version of {@code str}
 *//*from  w  w w.java  2 s. c  o  m*/
public static String capitalize(final String str) {
    if (str == null) {
        throw new IllegalArgumentException("str is null");
    }
    if (str.isEmpty()) {
        return str;
    }
    final String firstLetterUppercase = str.substring(0, 1).toUpperCase();
    final String theRest = str.substring(1);
    return firstLetterUppercase + theRest;
}

From source file:Main.java

static Throwable checkedException(Throwable ex)
/*  46:    */ {/*from  w  w  w  . j  a v  a2 s.c  om*/
    /*  47:144 */if ((ex != null) && (!(ex instanceof RuntimeException)) && (!(ex instanceof Error))) {
        /*  48:146 */return ex;
        /*  49:    */}
    /*  50:148 */throw new IllegalArgumentException("Not a checked exception: " + ex);
    /*  51:    */}

From source file:Main.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public synchronized static void sortTwoLists(List<Integer> queryList, List secondList) {
    if (queryList.size() != secondList.size()) {
        throw new IllegalArgumentException("The lists have to be of equal size!");
    }//ww  w . jav a2s.  c o  m
    int n = queryList.size();
    for (int i = 0; i < n; i++) {
        for (int j = n - 1; j > i; j--) {
            int one = ((Number) queryList.get(j - 1)).intValue();
            int two = ((Number) queryList.get(j)).intValue();
            if (one > two) {
                queryList.set(j - 1, two);
                queryList.set(j, one);

                Object temp = secondList.get(j - 1);
                secondList.set(j - 1, secondList.get(j));
                secondList.set(j, temp);
            }
        }
    }
}

From source file:Main.java

public static ImageIcon iconFromStream(final InputStream in) throws IOException {
    if (in == null) {
        throw new IllegalArgumentException("Stream must not be null");
    }// w  w  w .j  a v  a  2  s  .  c  o  m
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final byte[] buffer = new byte[1024];
    int read;
    while ((read = in.read(buffer)) > 0) {
        out.write(buffer, 0, read);
    }
    in.close();
    return new ImageIcon(out.toByteArray());
}

From source file:Main.java

public static ContentValues objectToContentValues(Object object) {
    if (object == null) {
        throw new IllegalArgumentException("please check your argument");
    }/*from  w  w  w  . j  a va2  s .  c  om*/
    ContentValues contentValues = new ContentValues();
    try {
        Field[] fields = object.getClass().getDeclaredFields();
        for (Field field : fields) {
            String fieldName = field.getName();
            Type type = field.getType();
            field.setAccessible(true);
            if (type.equals(String.class)) {
                contentValues.put(fieldName, field.get(object).toString());
            } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
                contentValues.put(fieldName, field.getInt(object));
            } else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
                contentValues.put(fieldName, field.getFloat(object));
            } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
                contentValues.put(fieldName, field.getLong(object));
            } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
                contentValues.put(fieldName, field.getDouble(object));
            } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
                contentValues.put(fieldName, field.getBoolean(object));
            }
        }
    } catch (IllegalAccessException | IllegalArgumentException e) {
        e.printStackTrace();
    }
    return contentValues;
}

From source file:Main.java

public static void require(boolean requirement, String message) {
    if (!requirement) {
        throw (message != null) ? new IllegalArgumentException(message) : new IllegalArgumentException();
    }/*from w w w  . ja  va2 s .c  o m*/
}

From source file:Main.java

public static void validateDirection(int direction) {
    if (direction != SwingConstants.NORTH && direction != SwingConstants.EAST
            && direction != SwingConstants.SOUTH && direction != SwingConstants.WEST) {
        throw new IllegalArgumentException("invalid direction");
    }/*from  w w w  .j  a v  a 2 s.  co m*/
}

From source file:Main.java

public static String utf8Encoding(String value, String sourceCharsetName) {
    try {//from   www .  j a v a 2  s.  c  o m
        return new String(value.getBytes(sourceCharsetName), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:Main.java

private static String safeInstanceIdFolderName(String instanceId) {
    if (instanceId != null && instanceId.length() != 0) {
        String instanceFolder = instanceId.replaceAll("(\\p{P}|\\p{Z})", "_");
        return instanceFolder;
    } else {/*from w w  w .  j a v  a2  s. com*/
        throw new IllegalArgumentException("getInstanceFolder: instanceId is null or the empty string!");
    }
}