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