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 checkSocketAddress(final InetSocketAddress socketAddress) {
    if (socketAddress == null) {
        throw new IllegalArgumentException("socketAddress can't be null");
    }/*from   ww  w  .j  a v  a2 s  .com*/
    /** can not use in JNI ; internal InetAddress field is null */
    if (socketAddress.isUnresolved()) {
        throw new IllegalArgumentException(
                "socketAddress is unresolved : " + socketAddress + " : check your DNS settings");
    }
}

From source file:Main.java

public static <K, V> Map<K, V> map(K[] keys, V[] values) {
    if (keys.length == values.length) {
        HashMap<K, V> result = new HashMap<K, V>(keys.length);

        for (int i = 0; i < keys.length; i++) {
            result.put(keys[i], values[i]);
        }//  w w w.j  a va 2s.co m

        return result;
    } else {
        throw new IllegalArgumentException("arrays must have equal length");
    }
}

From source file:Main.java

/**
 * Parse ref//  w w w  .j  a  v  a2s  . com
 *
 * @param ref form Table.Col
 * @return String[] {Table, Col}
 */
public static String[] getTableColRef(String ref) throws IllegalArgumentException {
    String[] res = null;
    String dot = "\\" + DOT;
    res = ref.split(dot);
    if (res.length != 2)
        throw new IllegalArgumentException("Wrong ref " + ref);
    return res;
}

From source file:Main.java

/**
 * @throws IllegalArgumentException if {@code typeUrl} is in invalid format.
 *///  w  w w.ja v  a  2s. c  o m
public static void validate(String typeUrl) throws IllegalArgumentException {
    if (!typeUrl.startsWith(TYPE_URL_PREFIX)) {
        throw new IllegalArgumentException(String
                .format("Error: type URL %s is invalid; it must start with %s\n", typeUrl, TYPE_URL_PREFIX));
    }
}

From source file:Main.java

/**
 * Will throw IllegalArgumentException if provided object is null on runtime
 *
 * @param argument object that should be asserted as not null
 * @param name     name of the object asserted
 * @throws java.lang.IllegalArgumentException
 *///from w ww . j  a  v  a  2 s. c om
public static <T> T notNull(final T argument, final String name) {
    if (argument == null) {
        throw new IllegalArgumentException(name + " should not be null!");
    }
    return argument;
}

From source file:Main.java

public static <T> T getUnique(Collection<T> list) {
    if (list == null)
        throw new IllegalArgumentException(" collection is null! collection must be not null");
    else if (list.size() != 1)
        throw new IllegalArgumentException(
                list.size() + " collection must be unique : " + list.iterator().next().toString());
    else/* ww w .j a  v  a2  s. c  o m*/
        return list.iterator().next();
}

From source file:Main.java

/**
 * get random elements from a collection
 *
 * @param <T>// ww w .  j a  v  a 2 s . c o  m
 * @param elements
 * @return
 */
public static <T> T getRandomElement(Collection<T> elements) {
    if (elements == null || elements.isEmpty()) {
        throw new IllegalArgumentException(" collection must have element!");
    }
    random.setSeed(System.currentTimeMillis());
    int offset = random.nextInt() % elements.size();
    for (T element : elements) {
        if (offset == 0) {
            return element;
        }
        offset--;
    }

    return null;
}

From source file:Main.java

private static void printNotMatchErrorMessage() {
    String errorMessage = "Please check your ProxyClassName,the " + mCustomProxyClassName
            + " is not match the rule.";
    Log.e(TAG, "printNotMatchErrorMessage: " + errorMessage);
    throw new IllegalArgumentException(errorMessage);
}

From source file:Main.java

public static byte[] unwrapkB(byte[] unwrapkB, byte[] wrapkB) {
    if (unwrapkB == null) {
        throw new IllegalArgumentException("unwrapkB must not be null");
    }/* www. j a  v  a2s. c om*/
    if (wrapkB == null) {
        throw new IllegalArgumentException("wrapkB must not be null");
    }
    if (unwrapkB.length != CRYPTO_KEY_LENGTH_BYTES || wrapkB.length != CRYPTO_KEY_LENGTH_BYTES) {
        throw new IllegalArgumentException(
                "unwrapkB and wrapkB must be " + CRYPTO_KEY_LENGTH_BYTES + " bytes long");
    }
    byte[] kB = new byte[CRYPTO_KEY_LENGTH_BYTES];
    for (int i = 0; i < wrapkB.length; i++) {
        kB[i] = (byte) (wrapkB[i] ^ unwrapkB[i]);
    }
    return kB;
}

From source file:Main.java

/**
 * Append a collection of strings and delimiter.
 *
 * @param c A collection of strings.//from w  w  w  . j a v a 2  s. com
 * @param delimiter A delimiter string.
 * @return The new string.
 */
public static String join(Collection<String> c, String delimiter) {
    if (c == null || delimiter == null) {
        throw new IllegalArgumentException("Collections and delimiters given to join cannot be null!");
    }
    StringBuilder builder = new StringBuilder("");
    Iterator<String> iter = c.iterator();
    while (iter.hasNext()) {
        builder.append(iter.next());
        if (iter.hasNext()) {
            builder.append(delimiter);
        }
    }
    return builder.toString();
}