Search in sources :

Example 41 with EmptyStackException

use of java.util.EmptyStackException in project hbase by apache.

the class ParseFilter method popArguments.

/**
 * Pops an argument from the operator stack and the number of arguments required by the operator
 * from the filterStack and evaluates them
 * <p>
 * @param operatorStack the stack containing the operators
 * @param filterStack the stack containing the filters
 * @return the evaluated filter
 */
public static Filter popArguments(Stack<ByteBuffer> operatorStack, Stack<Filter> filterStack) {
    ByteBuffer argumentOnTopOfStack = operatorStack.peek();
    if (argumentOnTopOfStack.equals(ParseConstants.OR_BUFFER)) {
        // The top of the stack is an OR
        try {
            ArrayList<Filter> listOfFilters = new ArrayList<>();
            while (!operatorStack.empty() && operatorStack.peek().equals(ParseConstants.OR_BUFFER)) {
                Filter filter = filterStack.pop();
                listOfFilters.add(0, filter);
                operatorStack.pop();
            }
            Filter filter = filterStack.pop();
            listOfFilters.add(0, filter);
            Filter orFilter = new FilterList(FilterList.Operator.MUST_PASS_ONE, listOfFilters);
            return orFilter;
        } catch (EmptyStackException e) {
            throw new IllegalArgumentException("Incorrect input string - an OR needs two filters");
        }
    } else if (argumentOnTopOfStack.equals(ParseConstants.AND_BUFFER)) {
        // The top of the stack is an AND
        try {
            ArrayList<Filter> listOfFilters = new ArrayList<>();
            while (!operatorStack.empty() && operatorStack.peek().equals(ParseConstants.AND_BUFFER)) {
                Filter filter = filterStack.pop();
                listOfFilters.add(0, filter);
                operatorStack.pop();
            }
            Filter filter = filterStack.pop();
            listOfFilters.add(0, filter);
            Filter andFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL, listOfFilters);
            return andFilter;
        } catch (EmptyStackException e) {
            throw new IllegalArgumentException("Incorrect input string - an AND needs two filters");
        }
    } else if (argumentOnTopOfStack.equals(ParseConstants.SKIP_BUFFER)) {
        // The top of the stack is a SKIP
        try {
            Filter wrappedFilter = filterStack.pop();
            Filter skipFilter = new SkipFilter(wrappedFilter);
            operatorStack.pop();
            return skipFilter;
        } catch (EmptyStackException e) {
            throw new IllegalArgumentException("Incorrect input string - a SKIP wraps a filter");
        }
    } else if (argumentOnTopOfStack.equals(ParseConstants.WHILE_BUFFER)) {
        // The top of the stack is a WHILE
        try {
            Filter wrappedFilter = filterStack.pop();
            Filter whileMatchFilter = new WhileMatchFilter(wrappedFilter);
            operatorStack.pop();
            return whileMatchFilter;
        } catch (EmptyStackException e) {
            throw new IllegalArgumentException("Incorrect input string - a WHILE wraps a filter");
        }
    } else if (argumentOnTopOfStack.equals(ParseConstants.LPAREN_BUFFER)) {
        // The top of the stack is a LPAREN
        try {
            Filter filter = filterStack.pop();
            operatorStack.pop();
            return filter;
        } catch (EmptyStackException e) {
            throw new IllegalArgumentException("Incorrect Filter String");
        }
    } else {
        throw new IllegalArgumentException("Incorrect arguments on operatorStack");
    }
}
Also used : EmptyStackException(java.util.EmptyStackException) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer)

Example 42 with EmptyStackException

use of java.util.EmptyStackException in project CtCI-6th-Edition by careercup.

the class MyStack method pop.

public T pop() {
    if (top == null)
        throw new EmptyStackException();
    T item = top.getData();
    top = top.next;
    return item;
}
Also used : EmptyStackException(java.util.EmptyStackException)

Example 43 with EmptyStackException

use of java.util.EmptyStackException in project spring-roo by spring-projects.

the class DatabaseXmlUtils method readDatabase.

static Database readDatabase(final InputStream inputStream) {
    try {
        final SAXParserFactory spf = SAXParserFactory.newInstance();
        final SAXParser parser = spf.newSAXParser();
        final DatabaseContentHandler contentHandler = new DatabaseContentHandler();
        parser.parse(inputStream, contentHandler);
        return contentHandler.getDatabase();
    } catch (final EmptyStackException e) {
        throw new IllegalStateException("Unable to read database from XML file", e);
    } catch (final Exception e) {
        if (e.getMessage().contains("Invalid byte")) {
            throw new IllegalStateException("Invalid content in XML file. There may hidden characters in the file, such as the byte order mark (BOM). Try re-saving the xml in a text editor", e);
        }
        throw new IllegalStateException(e);
    }
}
Also used : EmptyStackException(java.util.EmptyStackException) SAXParser(javax.xml.parsers.SAXParser) EmptyStackException(java.util.EmptyStackException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 44 with EmptyStackException

use of java.util.EmptyStackException in project hs4j by killme2008.

the class SelectorFactory method getSelector.

/**
 * Get a exclusive <code>Selector</code>
 *
 * @return <code>Selector</code>
 */
public static final Selector getSelector() {
    synchronized (selectors) {
        Selector s = null;
        try {
            if (selectors.size() != 0) {
                s = selectors.pop();
            }
        } catch (EmptyStackException ex) {
        }
        int attempts = 0;
        try {
            while (s == null && attempts < 2) {
                selectors.wait(timeout);
                try {
                    if (selectors.size() != 0) {
                        s = selectors.pop();
                    }
                } catch (EmptyStackException ex) {
                    break;
                }
                attempts++;
            }
        } catch (InterruptedException ex) {
        }
        return s;
    }
}
Also used : EmptyStackException(java.util.EmptyStackException) Selector(java.nio.channels.Selector)

Example 45 with EmptyStackException

use of java.util.EmptyStackException in project j2objc by google.

the class NamespaceSupportTest method testPush_PopContext.

public void testPush_PopContext() {
    int count;
    ns = new NamespaceSupport();
    count = countPrefixes();
    ns.pushContext();
    ns.declarePrefix("dc", "http://www.purl.org/dc#");
    assertEquals("Test 1: Incorrect prefix count;", count + 1, countPrefixes());
    ns.popContext();
    assertEquals("Test 2: Incorrect prefix count;", count, countPrefixes());
    // Check that only one context has been created by pushContext().
    try {
        ns.popContext();
        fail("Test 3: EmptyStackException expected.");
    } catch (EmptyStackException e) {
    // Expected.
    }
}
Also used : EmptyStackException(java.util.EmptyStackException) NamespaceSupport(org.xml.sax.helpers.NamespaceSupport)

Aggregations

EmptyStackException (java.util.EmptyStackException)47 Stack (java.util.Stack)13 Test (org.junit.Test)6 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)5 Callable (java.util.concurrent.Callable)5 NamespaceSupport (org.xml.sax.helpers.NamespaceSupport)5 ActivityImple (com.arjuna.mwlabs.wsas.activity.ActivityImple)3 IOException (java.io.IOException)3 ResourceApplicationContext (com.cloud.spring.module.context.ResourceApplicationContext)2 ConfigCompileException (com.laytonsmith.core.exceptions.ConfigCompileException)2 ArrayList (java.util.ArrayList)2 SystemException (org.omg.CORBA.SystemException)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ActionControl (com.arjuna.ArjunaOTS.ActionControl)1 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)1 LightScrollPane (com.jsql.view.swing.scrollpane.LightScrollPane)1 TabHeader (com.jsql.view.swing.tab.TabHeader)1 FileOptions (com.laytonsmith.core.compiler.FileOptions)1 KeywordList (com.laytonsmith.core.compiler.KeywordList)1 CDecimal (com.laytonsmith.core.constructs.CDecimal)1