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");
}
}
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;
}
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);
}
}
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;
}
}
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.
}
}
Aggregations