Example usage for java.lang IllegalStateException IllegalStateException

List of usage examples for java.lang IllegalStateException IllegalStateException

Introduction

In this page you can find the example usage for java.lang IllegalStateException IllegalStateException.

Prototype

public IllegalStateException(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 assertBackgroundThread() {
    if (isUIThread()) {
        throw new IllegalStateException("is not background thread!!");
    }//from  w w  w .  ja va 2 s .com
}

From source file:Main.java

public static File getSDExternalPath() {
    if (mExternalCacheDir == null) {
        throw new IllegalStateException("not init Common");
    }/*from  w  w w. j  a va2s .c o  m*/
    return mExternalCacheDir;
}

From source file:Main.java

static void createParentDirs(File file) {
    File dir = file.getParentFile();
    if (dir != null && !dir.exists() && !dir.mkdirs())
        throw new IllegalStateException("Couldnt create " + dir);
}

From source file:Main.java

public static Object findSingleObject(Collection c) {
    if (c == null || c.isEmpty())
        return null;
    if (c.size() > 1)
        throw new IllegalStateException("found more than one object when single object requested");
    return c.iterator().next();
}

From source file:Main.java

public static void sleepWithoutInterruptions(long milliseconds) {
    try {/* w  ww.j a  v a 2 s .c  o m*/
        Thread.sleep(milliseconds);
    } catch (final InterruptedException e) {
        throw new IllegalStateException(e);
    }
}

From source file:Main.java

public static <T, C extends Collection<T>> void ensureAdded(C collection, T t) throws IllegalStateException {
    if (!collection.add(t)) {
        throw new IllegalStateException("duplicate entry of " + t);
    }/*from  ww  w  .java  2  s. c  o m*/
}

From source file:Main.java

public static <T> List<T> tail(List<T> list) {
    if (list.size() == 0) {
        throw new IllegalStateException("tail of empty list");
    }//from w  w w. ja v  a 2 s.  c  o m
    List<T> workList = copy(list);
    workList.remove(0);
    return Collections.unmodifiableList(workList);
}

From source file:Main.java

public static void init() {
    if (s_var.get() != null) {
        throw new IllegalStateException(
                "There is already a thread local exists, call init() already or forgot to call cleanup()???");
    } else {/*from ww w.ja  va2 s. c  o  m*/
        HashMap map = new HashMap(4);
        s_var.set(map);
        return;
    }
}

From source file:Main.java

static void sleep(int millis) {
    try {/*w  w  w.ja va 2 s  . c  o m*/
        Thread.sleep(millis);
    } catch (InterruptedException shouldNotHappen) {
        throw new IllegalStateException(shouldNotHappen);
    }
}

From source file:Main.java

public static void sleep(int seconds) {
    try {//from  w w  w.  j a v a  2  s. co m
        TimeUnit.SECONDS.sleep(seconds);
    } catch (InterruptedException e) {
        throw new IllegalStateException(e);
    }
}