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:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.EvalHelper.java

public static File[] listSubFolders(File folder) {
    File[] subFolders = folder.listFiles(new FileFilter() {
        @Override//from  w w w.ja  va  2 s .c o  m
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    });

    if (subFolders.length == 0) {
        throw new IllegalStateException("No sub-folders found in " + folder.getAbsolutePath());
    }

    return subFolders;
}

From source file:Main.java

/**
 * Partition a list into <code>num</code> sub-lists.  If the list does
 * not divide evenly, the extra 'n' elements are split across the
 * first 'n' lists.  There will be no more lists than elements returned (i.e. no empty lists tacked on to the end)
 *///from  w  w w  .  j ava2 s.c  o  m
public static <T> List<List<T>> partition(List<T> list, int num) {
    if (num < 1) {
        throw new IllegalArgumentException("Number of sub-lists must be greater than zero");
    }
    List<List<T>> result = new ArrayList<List<T>>();
    int index = 0;
    int listsRemaining = num;
    int elementsRemaining = list.size();
    while (elementsRemaining > 0) {
        int size = (int) Math.ceil(elementsRemaining / (listsRemaining + 0.0));
        List<T> subList = list.subList(index, index + size);
        result.add(subList);
        listsRemaining--;
        elementsRemaining -= size;
        index += size;
    }
    if (elementsRemaining != 0) {
        throw new IllegalStateException(
                String.format("Loop exited with %d elements still remaining", elementsRemaining));
    }
    return result;
}

From source file:com.wisemapping.security.Utils.java

@NotNull
public static User getUser(boolean forceCheck) {
    User result = null;/*from  w  w w  .j a  v  a2s  . co  m*/
    final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth != null && auth.getDetails() != null) {
        final Object principal = auth.getPrincipal();
        if (principal != null && principal instanceof UserDetails) {
            result = ((UserDetails) principal).getUser();
        }
    }

    if (result == null && forceCheck) {
        throw new IllegalStateException("User could not be retrieved");
    }
    return result;
}

From source file:com.sonnychen.aviationhk.utils.SimpleCache.java

public static synchronized SimpleCache open(File dir, int appVersion, long maxSize) throws IOException {
    if (usedDirs.contains(dir)) {
        throw new IllegalStateException("Cache dir " + dir.getAbsolutePath() + " was used before.");
    }// w  ww .  j ava  2  s.  c o  m

    usedDirs.add(dir);

    return new SimpleCache(dir, appVersion, maxSize);
}

From source file:com.clicktravel.cheddar.event.AbstractEvent.java

public static <T extends Event> T newEvent(final Class<T> eventClass, final String serializedEvent) {
    try {//w w w.j a  v  a2 s .com
        final T event = eventClass.newInstance();
        event.deserializeAndApply(serializedEvent);
        return event;
    } catch (InstantiationException | IllegalAccessException e) {
        throw new IllegalStateException("Could not instantiate event " + eventClass.getName());
    }
}

From source file:io.orchestrate.client.itest.BaseClientTest.java

@BeforeClass
public static void setUpClass() {
    final String apiKey = System.getProperty("orchestrate.apiKey");
    if (apiKey == null || apiKey.length() < 1) {
        throw new IllegalStateException("Cannot run integration tests, 'apiKey' is blank.");
    }/*ww  w.  jav a  2  s .  c  om*/

    URI uri = URI.create(System.getProperty("orchestrate.host", OrchestrateClient.Builder.DEFAULT_HOST));

    String host = uri.getScheme() + "://" + uri.getHost();
    int port = uri.getPort();
    if (port == -1) {
        if (uri.getScheme().equals("https")) {
            port = 443;
        } else {
            port = 80;
        }
    }
    boolean ssl = uri.getScheme().equals("https");

    client = OrchestrateClient.builder(apiKey).host(host).port(port).useSSL(ssl).build();
}

From source file:ContextLog.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    String yourMessage = request.getParameter("mine");
    //Call the two ServletContext.log methods
    //the javax.servlet.GenericServlet.getServletContext method
    ServletContext context = getServletContext();
    if (yourMessage == null || yourMessage.equals(""))
        //log version with Throwable parameter
        context.log("No message received:", new IllegalStateException("Missing parameter"));
    else// w  w  w  .jav  a2 s  .c  om
        context.log("Here is the visitor's message: " + yourMessage);

    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    //logging servlets probably want to display more HTML; this is 'lazy
    // HTML'
    out.println("<html><head><title>ServletContext logging</title></head><body>");
    out.println("<h2>Messages sent</h2>");
    out.println("</body></html>");
}

From source file:Main.java

public static NodeList getNodes(String expression, Document document) {
    XPath xpath = xPathFactory.newXPath();
    try {/*from w  ww .j a v  a  2  s . co  m*/
        NodeList list = (NodeList) xpath.evaluate(expression, document, XPathConstants.NODESET);
        return list;
    } catch (XPathExpressionException xpe) {
        throw new IllegalStateException(xpe);
    }
}

From source file:com.relicum.ipsum.Utils.Profiler.java

public static long getCurrentDelta(String id) {
    final long nanos = System.nanoTime();
    Validate.notNull(id, "ID should not be null");
    synchronized (startTimes) {
        if (!startTimes.containsKey(id)) {
            throw new IllegalStateException("This ID is not being profiled!");
        }/*from w  w  w  .  ja v a  2s. c  o  m*/
        return nanos - startTimes.get(id);
    }
}

From source file:com.eviware.loadui.impl.statistics.db.util.TypeConverter.java

public static byte[] imageToByteArray(BufferedImage bufferedImage) {
    if (bufferedImage != null) {
        BufferedImage image = bufferedImage;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {/* w  ww  .j a va2 s. c  o  m*/
            ImageIO.write(image, "png", baos);
        } catch (IOException e) {
            throw new IllegalStateException(e.toString());
        }
        return baos.toByteArray();
    }
    return new byte[0];
}