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 setImageLevel(ImageView imageView, Integer level) {
    if (imageView != null) {
        if (level == null)
            level = 0;// w w  w. j  a  va2  s. c  o m
        imageView.setImageLevel(level);
    } else {
        throw new IllegalArgumentException("A view is null in your parameters.");
    }
}

From source file:Main.java

public static int getArrayDimension(Object array) {
    int dimension = 0;
    Class c = array.getClass();//from w w w  .  j a v a  2 s .  c o m
    if (!c.isArray()) {
        throw new IllegalArgumentException("Object is not  an  array");
    }
    while (c.isArray()) {
        dimension++;
        c = c.getComponentType();
    }
    return dimension;
}

From source file:Main.java

public static String getRequiredAttribute(Element element, Enum<?> attribute) {
    final String value = getAttribute(element, attribute);
    if (value != null) {
        return value;
    }/*from www. ja v a  2  s  .c o m*/
    throw new IllegalArgumentException("attribute " + getXmlName(attribute)
            + " is missing or empty in XML element " + element.getNodeName());
}

From source file:Main.java

public static URL toUrl(File file) {
    try {/*from w  ww  . j  a v  a2  s . c  o m*/
        return file.toURI().toURL();
    } catch (final MalformedURLException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:Main.java

public static String addPadding(String t, String s, int num) {
    StringBuilder retVal;//w ww  . j  a  v  a2 s.  com

    if (null == s || 0 >= num) {
        throw new IllegalArgumentException(INVALID_ARGUMENT);
    }

    if (s.length() <= num) {
        return s.concat(t);
    }

    retVal = new StringBuilder(s);

    for (int i = retVal.length(); i > 0; i -= num) {
        retVal.insert(i, t);
    }
    return retVal.toString();
}

From source file:Main.java

public static String trimStringValue(String value) {
    if (value == null) {
        return null;
    }/*from www  .  ja  v a2s . c  om*/
    String text = value;
    char initialChar = text.charAt(0);
    if (text.charAt(text.length() - 1) != initialChar) {
        throw new IllegalArgumentException("malformed string literal");
    }
    text = text.substring(1, text.length() - 1);
    if (initialChar == '\'') {
        text = text.replace("''", "'");
    } else if (initialChar == '"') {
        text = text.replace("\"\"", "\"");
    } else {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    return text;
}

From source file:Main.java

public static boolean isServerConfigExist(Context ctx) {
    if (ctx == null) {
        throw new IllegalArgumentException("Context can't null.");
    }/*w ww.  j a  v a 2  s.c  o m*/
    String sdkServerFolder = getSDKServerFolder(ctx);
    return new File(sdkServerFolder, SDK_SERVER_NAME).exists();
}

From source file:Main.java

/**
 * find the nth index of a char c in a string.  returns -1 if there aren't that many chars in the string
 * @param c/*from  w  w w  . j a va  2s . c om*/
 * @param n
 * @return
 */
public static int getNthIndexOf(char c, String str, int n) {

    if (n < 1) {
        throw new IllegalArgumentException("n must be >= 1: " + n);
    }

    int index = str.indexOf(c);
    int count = 0;
    while (index != -1 && (++count) < n) {
        index = str.indexOf(c, index + 1);
    }

    return index;
}

From source file:Main.java

public static Map<String, String> toStringMap(String... pairs) {
    Map<String, String> parameters = new HashMap<String, String>();
    if (pairs.length > 0) {
        if (pairs.length % 2 != 0) {
            throw new IllegalArgumentException("pairs must be even.");
        }/*from w w w .j a va 2  s.  c  o m*/
        for (int i = 0; i < pairs.length; i = i + 2) {
            parameters.put(pairs[i], pairs[i + 1]);
        }
    }
    return parameters;
}

From source file:Main.java

@SuppressWarnings("hiding")
public static <T> List<List<T>> seperateList(List<T> list) {
    if (list == null) {
        throw new IllegalArgumentException("list should not be null");
    }/*from w  w  w.  ja  v a 2  s.  c o  m*/
    List<List<T>> ret = new ArrayList<List<T>>();

    if (list.size() <= MAX_FRAGEMENT_SIZE) {
        ret.add(list);
    } else {
        int fragementCount = list.size() / MAX_FRAGEMENT_SIZE + 1;

        for (int i = 0; i < fragementCount; i++) {
            int start = i * MAX_FRAGEMENT_SIZE;
            int end = start + MAX_FRAGEMENT_SIZE;

            if (end > list.size()) {
                end = list.size();
            }

            List<T> subList = list.subList(start, end);
            ret.add(subList);
        }

    }

    return ret;
}