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

/**
 * Returns a merge function, suitable for use in
 * {@link Map#merge(Object, Object, BiFunction) Map.merge()} or
 * {@link #toMap(Function, Function, BinaryOperator) toMap()}, which always
 * throws {@code IllegalStateException}. This can be used to enforce the
 * assumption that the elements being collected are distinct.
 *
 * @param <T>//from  w ww .ja v  a2s .co m
 *            the type of input arguments to the merge function
 * @return a merge function which always throw {@code IllegalStateException}
 */
private static <T> BinaryOperator<T> throwingMerger() {
    return (u, v) -> {
        throw new IllegalStateException(String.format("Duplicate key %s", u));
    };
}

From source file:Main.java

public static Document newDocument() {
    final DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    final DocumentBuilder docBuilder;
    try {// w w w. j  a va 2  s . co m
        docBuilder = dbfac.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }
    final Document document = docBuilder.newDocument();
    document.setXmlStandalone(true);
    return document;
}

From source file:Main.java

public static Activity getActivity(View view) {
    Context context = view.getContext();
    while (context instanceof ContextWrapper) {
        if (context instanceof Activity) {
            return (Activity) context;
        }/*from  w ww .ja  v a  2 s  .co m*/
        context = ((ContextWrapper) context).getBaseContext();
    }
    throw new IllegalStateException("View " + view + " is not attached to an Activity");
}

From source file:Main.java

private static void verifyPermission(Context context, String paramString) {
    if (!isPermissionGranted(context, paramString)) {
        throw new IllegalStateException(
                "Android Manifest Error: Missing permission in manifest: " + paramString);
    }//from w  w  w  . j  a v a  2s  .  c o m
}

From source file:Main.java

public static String nextString(XMLStreamReader reader) throws XMLStreamException {
    int type;/* ww  w  .  j  a  v  a  2 s.  c  o m*/
    StringBuilder result = new StringBuilder();
    while ((type = reader.next()) != XMLStreamReader.END_ELEMENT) {
        switch (type) {
        case XMLStreamReader.START_ELEMENT:
            throw new IllegalStateException("Found start element parsing text.");

        case XMLStreamReader.CDATA:
        case XMLStreamReader.SPACE:
        case XMLStreamReader.CHARACTERS:
            result.append(reader.getText());
        }
    }
    return result.toString();
}

From source file:Main.java

private static void print(Writer writer, char c) {
    try {/*from  ww  w .  j av a  2s  .c o m*/
        writer.write(c);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:MyObject.java

@Override
public int hashCode() {
    throw new IllegalStateException("This method must not be called");
}

From source file:com.ansorgit.plugins.bash.BashTestUtils.java

public static String getBasePath() {
    if (basePath == null) {
        basePath = computeBasePath();/*  w  w w . j a  v  a  2s. c o  m*/
    }

    if (basePath == null) {
        throw new IllegalStateException("Could not find the testData directory.");
    }

    return basePath;
}

From source file:Main.java

public static @NonNull Activity getActivity(View view) {
    Context context = view.getContext();

    while (context instanceof ContextWrapper) {
        if (context instanceof Activity) {
            return (Activity) context;
        }//from   w  w w  . j  a  va  2s . c o m
        context = ((ContextWrapper) context).getBaseContext();
    }

    throw new IllegalStateException("View " + view + " is not attached to an Activity");
}

From source file:nh.examples.springintegration.order.framework.domain.internal.ReflectionHelper.java

public static Method getAccessibleMethod(String name, Class<?> targetClass, Object parameter) {
    checkNotNull(name);/*from   w ww .  j  a va 2 s. c  o m*/
    checkNotNull(targetClass);
    checkNotNull(parameter);

    Method executeMethod = ReflectionUtils.findMethod(targetClass, name, parameter.getClass());
    if (executeMethod == null) {
        throw new IllegalStateException(format("No '%s'-method for command type %s found on class %s", name,
                parameter.getClass().getName(), targetClass.getName()));
    }
    ReflectionUtils.makeAccessible(executeMethod);

    return executeMethod;
}