Search in sources :

Example 26 with Stack

use of java.util.Stack in project Mycat-Server by MyCATApache.

the class FunctionParser method parseFunction.

public static Function parseFunction(String function) throws SQLNonTransientException {
    StringBuilder buffer = new StringBuilder();
    Stack<Function> functions = new Stack<>();
    int flag = 0;
    for (int i = 0; i < function.length(); i++) {
        char current = function.charAt(i);
        switch(current) {
            case Commons.LEFT_BRACKET:
                if (flag == 0) {
                    String currentIdentifier = buffer.toString().trim();
                    buffer = new StringBuilder();
                    if (!StringUtil.isEmpty(currentIdentifier)) {
                        Function function1 = new Function(currentIdentifier);
                        if (!functions.empty() && functions.peek() != null) {
                            functions.peek().getArguments().add(function1);
                        }
                        functions.push(function1);
                    }
                    break;
                }
                buffer.append(current);
                break;
            case Commons.ARGUMENT_SEPARATOR:
                if (flag == 0 || flag == 3) {
                    String currentIdentifier = buffer.toString().trim();
                    buffer = new StringBuilder();
                    if (!StringUtil.isEmpty(currentIdentifier)) {
                        if (flag == 3) {
                            flag = 0;
                            Identifier identifier = new Identifier(currentIdentifier);
                            functions.peek().getArguments().add(identifier);
                        } else {
                            Field field = new Field(currentIdentifier);
                            functions.peek().getArguments().add(field);
                        }
                    }
                    break;
                }
                buffer.append(current);
                break;
            case Commons.RIGHT_BRACKET:
                if (flag != 1 && flag != 2) {
                    String currentIdentifier = buffer.toString().trim();
                    buffer = new StringBuilder();
                    if (!StringUtil.isEmpty(currentIdentifier)) {
                        if (flag == 3) {
                            flag = 0;
                            Identifier identifier = new Identifier(currentIdentifier);
                            functions.peek().getArguments().add(identifier);
                        } else {
                            Field field = new Field(currentIdentifier);
                            functions.peek().getArguments().add(field);
                        }
                    }
                    if (flag == 0) {
                        if (functions.size() == 1) {
                            return functions.pop();
                        } else {
                            functions.pop();
                        }
                    }
                    break;
                }
                buffer.append(current);
                break;
            case Commons.QUOTE:
                if (flag == 0) {
                    flag = 1;
                } else if (flag == 1) {
                    flag = 3;
                }
            case Commons.DOUBLE_QUOTE:
                if (flag == 0) {
                    flag = 2;
                } else if (flag == 2) {
                    flag = 3;
                }
            default:
                buffer.append(current);
        }
    }
    throw new SQLNonTransientException("Function is not in right format!");
}
Also used : Function(io.mycat.route.parser.primitive.Model.Function) Field(io.mycat.route.parser.primitive.Model.Field) SQLNonTransientException(java.sql.SQLNonTransientException) Identifier(io.mycat.route.parser.primitive.Model.Identifier) Stack(java.util.Stack)

Example 27 with Stack

use of java.util.Stack in project aerosolve by airbnb.

the class KDTreeModel method queryBox.

// Returns the indices of all node overlapping the box
public ArrayList<Integer> queryBox(double minX, double minY, double maxX, double maxY) {
    ArrayList<Integer> idx = new ArrayList<>();
    if (nodes == null)
        return idx;
    Stack<Integer> stack = new Stack<Integer>();
    stack.push(0);
    while (!stack.isEmpty()) {
        int currIdx = stack.pop();
        idx.add(currIdx);
        KDTreeNode node = nodes[currIdx];
        switch(node.nodeType) {
            case X_SPLIT:
                {
                    if (minX < node.splitValue) {
                        stack.push(node.leftChild);
                    }
                    if (maxX >= node.splitValue) {
                        stack.push(node.rightChild);
                    }
                }
                break;
            case Y_SPLIT:
                {
                    if (minY < node.splitValue) {
                        stack.push(node.leftChild);
                    }
                    if (maxY >= node.splitValue) {
                        stack.push(node.rightChild);
                    }
                }
            case LEAF:
                break;
        }
    }
    return idx;
}
Also used : KDTreeNode(com.airbnb.aerosolve.core.KDTreeNode) ArrayList(java.util.ArrayList) Stack(java.util.Stack)

Example 28 with Stack

use of java.util.Stack in project native-navigation by airbnb.

the class ReactNativeTabActivity method traverseTabs.

private void traverseTabs() {
    Stack<ViewGroup> stack = new Stack<>();
    stack.push(tabConfigContainer);
    prevTabBarConfig = renderedTabBarConfig;
    renderedTabBarConfig = ConversionUtil.EMPTY_MAP;
    tabViews = new ArrayMap<>();
    while (!stack.empty()) {
        ViewGroup view = stack.pop();
        int childCount = view.getChildCount();
        for (int i = 0; i < childCount; ++i) {
            View child = view.getChildAt(i);
            if (child instanceof TabView) {
                tabViews.put(child.getId(), (TabView) child);
            } else if (child instanceof TabBarView) {
                TabBarView tabBarView = (TabBarView) child;
                renderedTabBarConfig = ConversionUtil.combine(renderedTabBarConfig, tabBarView.getConfig());
                stack.push(tabBarView);
            } else if (child instanceof ViewGroup) {
                stack.push((ViewGroup) child);
            }
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) BottomNavigationView(android.support.design.widget.BottomNavigationView) View(android.view.View) Stack(java.util.Stack)

Example 29 with Stack

use of java.util.Stack in project native-navigation by airbnb.

the class ViewUtils method findViewGroupWithTag.

/**
   * Breadth-first search of a view hierarchy that returns the first element with a matching tag.
   *
   * @param root   - The view to start traversing (it is also checked for a matching tag)
   * @param key    - The tag key
   * @param object - The object to test for
   * @return - The first matching view
   */
@Nullable
static ViewGroup findViewGroupWithTag(ViewGroup root, int key, Object object) {
    Stack<ViewGroup> stack = new Stack<>();
    stack.push(root);
    while (!stack.empty()) {
        ViewGroup view = stack.pop();
        Object tag = view.getTag(key);
        if (object.equals(tag)) {
            return view;
        }
        int childCount = view.getChildCount();
        for (int i = 0; i < childCount; ++i) {
            View child = view.getChildAt(i);
            if (child instanceof ViewGroup) {
                stack.push((ViewGroup) child);
            }
        }
    }
    return null;
}
Also used : ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) View(android.view.View) Point(android.graphics.Point) Stack(java.util.Stack) Nullable(android.support.annotation.Nullable)

Example 30 with Stack

use of java.util.Stack in project atlas by alibaba.

the class SsaMethod method forEachBlockDepthFirst.

/**
     * Walks the basic block tree in depth-first order, calling the visitor
     * method once for every block. This depth-first walk may be run forward
     * from the method entry point or backwards from the method exit points.
     *
     * @param reverse true if this should walk backwards from the exit points
     * @param v {@code non-null;} callback interface. {@code parent} is set
     * unless this is the root node
     */
public void forEachBlockDepthFirst(boolean reverse, SsaBasicBlock.Visitor v) {
    BitSet visited = new BitSet(blocks.size());
    // We push the parent first, then the child on the stack.
    Stack<SsaBasicBlock> stack = new Stack<SsaBasicBlock>();
    SsaBasicBlock rootBlock = reverse ? getExitBlock() : getEntryBlock();
    if (rootBlock == null) {
        // in the case there's no exit block
        return;
    }
    // Start with null parent.
    stack.add(null);
    stack.add(rootBlock);
    while (stack.size() > 0) {
        SsaBasicBlock cur = stack.pop();
        SsaBasicBlock parent = stack.pop();
        if (!visited.get(cur.getIndex())) {
            BitSet children = reverse ? cur.getPredecessors() : cur.getSuccessors();
            for (int i = children.nextSetBit(0); i >= 0; i = children.nextSetBit(i + 1)) {
                stack.add(cur);
                stack.add(blocks.get(i));
            }
            visited.set(cur.getIndex());
            v.visitBlock(cur, parent);
        }
    }
}
Also used : BitSet(java.util.BitSet) Stack(java.util.Stack)

Aggregations

Stack (java.util.Stack)245 HashSet (java.util.HashSet)42 ArrayList (java.util.ArrayList)37 File (java.io.File)23 IOException (java.io.IOException)22 View (android.view.View)18 Test (org.junit.Test)18 ViewGroup (android.view.ViewGroup)14 HashMap (java.util.HashMap)14 Set (java.util.Set)12 LinkedList (java.util.LinkedList)11 List (java.util.List)11 ImageView (android.widget.ImageView)10 Map (java.util.Map)10 Document (org.w3c.dom.Document)10 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)9 PostfixMathCommandI (org.nfunk.jep.function.PostfixMathCommandI)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 NotificationPanelView (com.android.systemui.statusbar.phone.NotificationPanelView)7 TreeSet (java.util.TreeSet)7