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 byte[] tranformTextNodeToByteArray(Node node) {
    String text = node.getTextContent();
    if (text != null) {
        try {/*from  w  w  w  . ja  v a  2s . c o m*/
            return text.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            // should not happen
            throw new IllegalStateException(e);
        }
    } else {
        return null;
    }
}

From source file:Main.java

public static String getNoNamespacePath(Stack<QName> stack, NamespaceContext ctx) {
    StringBuilder ret = new StringBuilder();
    for (QName q : stack) {
        if (q == null)
            throw new IllegalStateException("q is null");
        ret.append("/");
        ret.append(q.getLocalPart());/*from  ww  w  .  ja va  2  s .c  om*/
    }
    return ret.toString();
}

From source file:Main.java

private static void skipStartCode(ByteBuffer prefixedSpsBuffer) {
    byte[] prefix3 = new byte[3];
    prefixedSpsBuffer.get(prefix3);/*from w w  w .  ja v  a  2  s .  c o m*/
    if (Arrays.equals(prefix3, AVC_START_CODE_3))
        return;

    byte[] prefix4 = Arrays.copyOf(prefix3, 4);
    prefix4[3] = prefixedSpsBuffer.get();
    if (Arrays.equals(prefix4, AVC_START_CODE_4))
        return;
    throw new IllegalStateException("AVC NAL start code does not found in csd.");
}

From source file:Main.java

/**
 * @return a new document builder (never null)
 *///w ww. j ava  2  s  .c  o m
public static final DocumentBuilder getDocumentBuilder() {
    // factory.setNamespaceAware(true);
    try {
        return factory.newDocumentBuilder();
    } catch (ParserConfigurationException ex) {
        throw new IllegalStateException(ex);
    }
}

From source file:Main.java

public static <T, K, U> Collector<T, ?, LinkedHashMap<K, U>> toLinkedHashMap(
        Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) {
    return Collectors.toMap(keyMapper, valueMapper, (u, v) -> {
        throw new IllegalStateException(String.format("Duplicate key %s", u));
    }, LinkedHashMap::new);
}

From source file:Main.java

/**
 * Retrieve the data type of the [i] field in the Cursor.
 * /*from w w  w.  j a va 2  s .  c  o  m*/
 * @param c
 * @param i
 * @return
 */
public static final Class<?> getIndexDataType(Cursor c, int i) {
    switch (c.getType(i)) {
    case Cursor.FIELD_TYPE_STRING:
        return String.class;
    case Cursor.FIELD_TYPE_FLOAT:
        return Double.class;
    case Cursor.FIELD_TYPE_INTEGER:
        return Long.class;
    case Cursor.FIELD_TYPE_NULL:
        return String.class;
    default:
    case Cursor.FIELD_TYPE_BLOB:
        throw new IllegalStateException("Unexpected data type in SQLite table");
    }
}

From source file:com.leanengine.JsonEncode.java

static JSONObject entityToJson(LeanEntity entity) throws LeanException {
    try {/*from w w  w. j  a v  a2 s  . c o  m*/
        JSONObject json = new JSONObject();
        if (entity.id != null)
            json.put("_id", entity.id);
        json.put("_kind", entity.kind);
        // no need to put in '_account` as this is automatically set on server from current users accountID
        for (Map.Entry<String, Object> prop : entity.properties.entrySet()) {
            addTypedNode(json, prop.getKey(), prop.getValue());
        }
        return json;
    } catch (JSONException e) {
        // this should not happen under normal circumstances
        throw new IllegalStateException(e);
    }
}

From source file:Main.java

/**
 * Check that the name of root element of the given {@code document} matches the given {@code expectedRootElementName}
 *
 * @param document//from   w  ww  . j av  a  2s  .  c  o m
 * @param expectedRootElementName
 */
public static void checkRootElement(@Nonnull Document document, @Nullable String expectedRootElementName) {
    if (document.getDocumentElement() == null || expectedRootElementName == null) {
        return;
    } else if (!expectedRootElementName.equals(document.getDocumentElement().getNodeName())) {
        throw new IllegalStateException("Invalid root element '" + document.getDocumentElement().getNodeName()
                + "', expected '" + expectedRootElementName + "'");

    }
}

From source file:aiai.ai.utils.EnvProperty.java

public static int minMax(String prop, int min, int max, Integer defForBlank) {
    if (StringUtils.isBlank(prop)) {
        if (defForBlank == null) {
            throw new IllegalStateException("prop and defForBlank both are null");
        }/*from  www  . j ava  2 s . co m*/
        if (defForBlank > max || defForBlank < min) {
            throw new IllegalStateException(
                    "misconfiguration: min: " + min + ", max: " + max + ", def: " + defForBlank);
        }
        return defForBlank;
    }
    int i = Integer.parseInt(prop);
    if (i >= min && i <= max) {
        return i;
    } else if (i < min) {
        return min;
    }
    return max;
}

From source file:com.jostrobin.battleships.view.theme.ConfigurableTheme.java

public static ConfigurableTheme getInstance() {
    if (INSTANCE == null) {
        throw new IllegalStateException("Class has not been initialized by the spring container");
    }//from   w  w w.java2  s.  c o  m
    return INSTANCE;
}