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 boolean delServerConfig(Context ctx) {
    if (ctx == null) {
        throw new IllegalArgumentException("Context can't null.");
    }/*from  w w  w . ja va 2 s  . co  m*/
    String sdkServerFolder = getSDKServerFolder(ctx);
    File file = new File(sdkServerFolder, SDK_SERVER_NAME);
    if (file.exists()) {
        file.delete();
    }
    return true;
}

From source file:Main.java

public static void addAction(JComponent component, String keyStroke, AbstractAction action) {
    KeyStroke ks = KeyStroke.getKeyStroke(keyStroke);
    if (ks == null)
        throw new IllegalArgumentException("invalid key stroke: " + keyStroke);
    Object key = ks + "-" + System.currentTimeMillis();
    component.getActionMap().put(key, action);
    component.getInputMap().put(ks, key);

}

From source file:Main.java

/**
 * Check if the Cell is in the size of the manager.
 * Throw exception if it is not.//from w w  w  .  j  a v a  2s  .com
 *
 * @param row
 * @param column
 */
public static void checkRange(int row, int column) {
    if (row < 0) {
        throw new IllegalArgumentException("row must be in range 0-" + (row - 1));
    }
    if (column < 0) {
        throw new IllegalArgumentException("column must be in range 0-" + (row - 1));
    }
}

From source file:Main.java

private static int parseHex(byte b) {
    if (b >= '0' && b <= '9')
        return (b - '0');
    if (b >= 'A' && b <= 'F')
        return (b - 'A' + 10);
    if (b >= 'a' && b <= 'f')
        return (b - 'a' + 10);

    throw new IllegalArgumentException("Invalid hex char '" + b + "'");
}

From source file:Main.java

/**
 * sleep until timeout.//ww w  .j a v a  2s.c om
 * 
 * @param nanos
 */
public final static void deepSleep(long sleepFor, TimeUnit unit) {
    if (sleepFor < 0) {
        throw new IllegalArgumentException("sleepFor can't be minus.");
    }
    long startTimeInNanos = System.nanoTime();
    long leftNanos = unit.toNanos(sleepFor);
    boolean isInterrupted = false;
    while (leftNanos > 0) {
        try {
            TimeUnit.NANOSECONDS.sleep(leftNanos);
            leftNanos = 0;
        } catch (InterruptedException e) {
            isInterrupted = true;
            leftNanos -= (System.nanoTime() - startTimeInNanos);
        }
    }

    if (isInterrupted) {
        Thread.currentThread().interrupt();
    }
}

From source file:Main.java

public static <T> Iterable<T> asIterable(final Iterator<T> iterator) {
    return new Iterable<T>() {
        boolean called = false;

        @Override/*from   w ww. ja va 2s .  com*/
        public Iterator<T> iterator() {
            if (called) {
                throw new IllegalArgumentException("wrapped iterable twice iterator call");
            }
            called = true;

            return iterator;
        }
    };
}

From source file:Main.java

public static final String getAttributeOrThrow(final Attributes pAttributes, final String pAttributeName) {
    final String value = pAttributes.getValue("", pAttributeName);
    if (value != null) {
        return value;
    } else {/*from   ww  w. j a v  a 2 s  .  c  o m*/
        throw new IllegalArgumentException("No value found for attribute: '" + pAttributeName + "'");
    }
}

From source file:Main.java

public static final void checkArray(final byte[] array) {
    if (array == null) {
        throw new IllegalArgumentException("array == null");
    }/*www . j  a va 2  s.c om*/
}

From source file:Main.java

public static boolean hasCamera(Context context) {
    if (context == null || context.getPackageManager() == null) {
        throw new IllegalArgumentException("Context and package manager must not be null");
    }/*w ww. j a  va  2s .co m*/
    PackageManager pm = context.getPackageManager();
    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        return true;
    } else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
    } else {
        return false;
    }
}

From source file:Main.java

public static Object getDeclaredField(Object obj, Class<?> cls, String fieldName) throws NoSuchFieldException {
    if (obj == null || cls == null || fieldName == null) {
        throw new IllegalArgumentException("parameter can not be null!");
    }//from w  ww .ja  va  2 s  .co  m
    try {
        Field declaredField = cls.getDeclaredField(fieldName);
        declaredField.setAccessible(true);
        return declaredField.get(obj);
    } catch (Exception e) {
        throw new NoSuchFieldException(fieldName);
    }
}