Search in sources :

Example 36 with EmptyStackException

use of java.util.EmptyStackException in project narayana by jbosstm.

the class UserActivityImple method current.

public final ActivityImple current() {
    Stack hier = (Stack) _threadAxData.get();
    ActivityImple currentActivity = null;
    if (hier != null) {
        try {
            currentActivity = (ActivityImple) hier.peek();
        } catch (EmptyStackException ex) {
        }
    }
    return currentActivity;
}
Also used : EmptyStackException(java.util.EmptyStackException) ActivityImple(com.arjuna.mwlabs.wsas.activity.ActivityImple) Stack(java.util.Stack)

Example 37 with EmptyStackException

use of java.util.EmptyStackException in project org.alloytools.alloy by AlloyTools.

the class LinkedStack method pop.

/**
 * Removes the object at the top of this stack and returns that object as the
 * value of this function.
 *
 * @ensures this.size' = this.size - 1 && all i: [1..this.size) |
 *          this.elems'[i-1] = this.elems[i]
 * @return this.elems[0]
 * @throws EmptyStackException no this.elems
 */
@Override
public T pop() {
    if (head == null)
        throw new EmptyStackException();
    final T pop = head.data;
    head = head.next;
    size--;
    return pop;
}
Also used : EmptyStackException(java.util.EmptyStackException)

Example 38 with EmptyStackException

use of java.util.EmptyStackException in project org.alloytools.alloy by AlloyTools.

the class ArrayStack method pop.

/**
 * @see kodkod.util.collections.Stack#pop()
 */
@Override
public T pop() {
    if (empty())
        throw new EmptyStackException();
    final T top = elems[--size];
    elems[size] = null;
    return top;
}
Also used : EmptyStackException(java.util.EmptyStackException)

Example 39 with EmptyStackException

use of java.util.EmptyStackException in project teiid by teiid.

the class MongoDBSelectVisitor method visit.

@Override
public void visit(AggregateFunction obj) {
    if (!obj.getParameters().isEmpty()) {
        append(obj.getParameters());
    }
    BasicDBObject expr = null;
    if (obj.getName().equals(AggregateFunction.COUNT)) {
        // this is only true for count(*) case, so we need implicit group id clause
        try {
            Object param = this.onGoingExpression.pop();
            BasicDBList eq = new BasicDBList();
            eq.add(0, param);
            eq.add(1, null);
            BasicDBList values = new BasicDBList();
            // $NON-NLS-1$
            values.add(0, new BasicDBObject("$eq", eq));
            values.add(1, 0);
            values.add(2, 1);
            // $NON-NLS-1$ //$NON-NLS-2$
            expr = new BasicDBObject("$sum", new BasicDBObject("$cond", values));
        } catch (EmptyStackException e) {
            // $NON-NLS-1$
            this.group.put("_id", null);
            // $NON-NLS-1$
            expr = new BasicDBObject("$sum", new Integer(1));
        }
    } else if (obj.getName().equals(AggregateFunction.AVG)) {
        // $NON-NLS-1$
        expr = new BasicDBObject("$avg", this.onGoingExpression.pop());
    } else if (obj.getName().equals(AggregateFunction.SUM)) {
        // $NON-NLS-1$
        expr = new BasicDBObject("$sum", this.onGoingExpression.pop());
    } else if (obj.getName().equals(AggregateFunction.MIN)) {
        // $NON-NLS-1$
        expr = new BasicDBObject("$min", this.onGoingExpression.pop());
    } else if (obj.getName().equals(AggregateFunction.MAX)) {
        // $NON-NLS-1$
        expr = new BasicDBObject("$max", this.onGoingExpression.pop());
    } else {
        this.exceptions.add(new TranslatorException(MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18005, obj.getName())));
    }
    if (expr != null) {
        this.onGoingExpression.push(expr);
    }
}
Also used : EmptyStackException(java.util.EmptyStackException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BasicDBObject(com.mongodb.BasicDBObject) BasicDBList(com.mongodb.BasicDBList) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) TranslatorException(org.teiid.translator.TranslatorException)

Example 40 with EmptyStackException

use of java.util.EmptyStackException in project ecf by eclipse.

the class RFC1960Filter method fromString.

/**
 * get a filter instance from filter string.
 *
 * @param filterString
 *            the filter string.
 * @return a filter instance.
 * @throws InvalidSyntaxException
 *             is the string is invalid.
 */
public static Filter fromString(final String filterString) {
    if (filterString == null || "".equals(filterString)) {
        return NULL_FILTER;
    }
    Stack stack = new Stack();
    try {
        final int len = filterString.length();
        int last = -1;
        int oper = 0;
        String id = null;
        int comparator = -1;
        final char[] chars = filterString.toCharArray();
        stack.clear();
        for (int i = 0; i < chars.length; i++) {
            switch(chars[i]) {
                case '(':
                    // lookahead ...
                    final char nextChar = chars[i + 1];
                    if (nextChar == '&') {
                        stack.push(new RFC1960Filter(AND_OPERATOR));
                        continue;
                    } else if (nextChar == '|') {
                        stack.push(new RFC1960Filter(OR_OPERATOR));
                        continue;
                    } else if (nextChar == '!') {
                        stack.push(new RFC1960Filter(NOT_OPERATOR));
                        continue;
                    } else {
                        if (last == -1) {
                            last = i;
                        } else {
                            throw new IllegalStateException("Surplus left paranthesis at: " + filterString.substring(i));
                        }
                    }
                    continue;
                case ')':
                    if (last == -1) {
                        RFC1960Filter filter = (RFC1960Filter) stack.pop();
                        if (stack.isEmpty()) {
                            return filter;
                        }
                        RFC1960Filter parent = (RFC1960Filter) stack.peek();
                        if (parent.operator == NOT_OPERATOR && !parent.operands.isEmpty()) {
                            throw new IllegalStateException("Unexpected literal: " + filterString.substring(i));
                        }
                        parent.operands.add(filter);
                        if (i == len - 1) {
                            throw new IllegalStateException("Missing right paranthesis at the end.");
                        }
                    } else {
                        if (oper == 0) {
                            throw new IllegalStateException("Missing operator.");
                        }
                        if (stack.isEmpty()) {
                            if (i == len - 1) {
                                // just a single simple filter
                                String value = filterString.substring(++oper, len - 1);
                                if (value.equals("*") && comparator == EQUALS) {
                                    comparator = PRESENT;
                                    value = null;
                                }
                                return new RFC1960SimpleFilter(id, comparator, value);
                            } else {
                                throw new IllegalStateException("Unexpected literal: " + filterString.substring(i));
                            }
                        }
                        // get the parent from stack
                        RFC1960Filter parent = ((RFC1960Filter) stack.peek());
                        String value = filterString.substring(++oper, i);
                        if (value.equals("*") && comparator == EQUALS) {
                            comparator = PRESENT;
                            value = null;
                        }
                        // link current element to parent
                        parent.operands.add(new RFC1960SimpleFilter(id, comparator, value));
                        oper = 0;
                        last = -1;
                        id = null;
                        comparator = -1;
                    }
                    continue;
                case '~':
                    if (oper == 0 && chars[i + 1] == '=') {
                        id = filterString.substring(last + 1, i).trim();
                        comparator = APPROX;
                        oper = ++i;
                        continue;
                    } else {
                        throw new IllegalStateException("Unexpected character " + chars[i + 1]);
                    }
                case '>':
                    if (oper == 0 && chars[i + 1] == '=') {
                        id = filterString.substring(last + 1, i).trim();
                        comparator = GREATER;
                        oper = ++i;
                        continue;
                    } else {
                        throw new IllegalStateException("Unexpected character " + chars[i + 1]);
                    }
                case '<':
                    if (oper == 0 && chars[i + 1] == '=') {
                        id = filterString.substring(last + 1, i).trim();
                        comparator = LESS;
                        oper = ++i;
                        continue;
                    } else {
                        throw new IllegalStateException("Unexpected character " + chars[i + 1]);
                    }
                case '=':
                    // could also be a "=*" present production.
                    // if this is the case, it is fixed later, because
                    // value=* and value=*key would require a lookahead of at
                    // least two. (the symbol "=*" alone is ambigous).
                    id = filterString.substring(last + 1, i).trim();
                    comparator = EQUALS;
                    oper = i;
                    continue;
            }
        }
        return (RFC1960Filter) stack.pop();
    } catch (EmptyStackException e) {
        throw new IllegalStateException("Filter expression not well-formed.");
    }
}
Also used : EmptyStackException(java.util.EmptyStackException) Stack(java.util.Stack)

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