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 sleep(int milliseconds) {
    try {/*from   w  w  w. j  a  va 2  s  .com*/
        Thread.sleep(milliseconds);
    } catch (InterruptedException e) {
        throw new IllegalStateException(e);
    }
}

From source file:Main.java

public static void delay(int milliseconds) {
    try {/*from  w w w. j a  v a  2s  .  c  o  m*/
        TimeUnit.MILLISECONDS.sleep(milliseconds);
    } catch (InterruptedException e) {
        throw new IllegalStateException(e);
    }
}

From source file:Utils.java

public static String stripCDATA(String s) {
    s = s.trim();//  ww  w  . j a va 2 s.c o m
    if (s.startsWith("<![CDATA[")) {
        s = s.substring(9);
        int i = s.indexOf("]]&gt;");
        if (i == -1) {
            throw new IllegalStateException("argument starts with <![CDATA[ but cannot find pairing ]]&gt;");
        }
        s = s.substring(0, i);
    }
    return s;
}

From source file:Main.java

static int getKeySize(String algorithm) {
    if (!KEYSIZES.containsKey(algorithm)) {
        throw new IllegalStateException("no key size for algorithm: " + algorithm);
    }//ww  w . ja  v  a 2  s  . c o m

    return ((Integer) KEYSIZES.get(algorithm)).intValue();
}

From source file:Main.java

public static int getRingtoneVolume() {
    if (audio != null) {
        return audio.getStreamVolume(android.media.AudioManager.STREAM_RING);
    } else {/* w  ww.  j  ava2s  .c om*/
        throw new IllegalStateException(
                "POITrackingUtil has not been initialized." + " First call POITrackingUtil.initialize()");
    }
}

From source file:Main.java

public static <T> T checkAndReturnOnlyElement(Collection<T> collection) {
    if (collection == null || collection.size() == 0) {
        return null;
    } else if (collection.size() != 1) {
        throw new IllegalStateException("collection size is " + collection.size());
    }//from www .  ja  v  a  2  s  .c  o m
    return collection.iterator().next();
}

From source file:Main.java

public static String requiredAttribute(String attributeName, Element node) {
    String attribute = node.getAttribute(attributeName);
    if (attribute == null || attribute.trim().isEmpty()) {
        throw new IllegalStateException(
                String.format("Required attribute by name '%s' is null or empty", attributeName));
    }//from  w  ww  .  j a v a 2  s.  c  o  m
    return attribute;
}

From source file:Main.java

public static <T> T uniqueResult(final Collection<T> c) {
    switch (c.size()) {
    case 0://from   ww w  .  j ava  2  s  .  co m
        return null;
    case 1:
        return c.iterator().next();
    default:
        throw new IllegalStateException("Unexpected number of elements in collection: " + c.size());
    }
}

From source file:Main.java

private static InputStream openFileId(Context context, int fileId) {
    InputStream stream = context.getResources().openRawResource(fileId);
    if (stream == null) {
        throw new IllegalStateException("Could not find object config file with id " + fileId);
    }//from   w  w  w  . j  a v  a2 s .co  m
    return stream;
}

From source file:Main.java

public static void checkNullStateByBoolean(Context context, boolean empty, String message) {
    if (empty) {//  ww  w .  j  a  va2s .  c  o m
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        throw new IllegalStateException(message);
    }
}