Example usage for java.util Stack empty

List of usage examples for java.util Stack empty

Introduction

In this page you can find the example usage for java.util Stack empty.

Prototype

public boolean empty() 

Source Link

Document

Tests if this stack is empty.

Usage

From source file:org.apache.hadoop.hbase.filter.ParseFilter.java

/**
 * Pops an argument from the operator stack and the number of arguments required by the operator
 * from the filterStack and evaluates them
 * <p>/* ww  w. j  a va  2s  .  com*/
 * @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<Filter>();
            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<Filter>();
            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");
    }
}

From source file:org.lambdamatic.analyzer.ast.LambdaExpressionReader.java

/**
 * Returns the {@link Expression} from the current {@link Expression} {@link Stack}, depending on
 * the current context (i.e., the current {@link JumpInsnNode} and its previous
 * {@link AbstractInsnNode}.// w  w  w  .j av a2 s .c o m
 * 
 * @param jumpInsnNode the instruction
 * @param expressionStack the stack of expressions
 * @return the comparison expression (can be an {@link CompoundExpression} or some other form of
 *         type of {@link Expression} that return a Boolean value)
 */
private static Expression getControlFlowExpression(final JumpInsnNode jumpInsnNode,
        final Stack<Expression> expressionStack) {
    final CompoundExpressionOperator comparisonOperator = extractComparisonOperator(jumpInsnNode);
    final Expression rightSideOperand = expressionStack.pop();
    final Expression leftSideOperand = (expressionStack.empty() ? getDefaultComparisonOperand(rightSideOperand)
            : expressionStack.pop());
    if (leftSideOperand.equals(new BooleanLiteral(false))) {
        switch (comparisonOperator) {
        case EQUALS:
            // if we have: 'expr == false', just return '!expr'
            return rightSideOperand.inverse();
        case NOT_EQUALS:
            // if we have: 'expr != false', just return 'expr'
            return rightSideOperand;
        default:
            throw new AnalyzeException("There's no expression to compare with " + rightSideOperand + " "
                    + comparisonOperator + " [expected something here]");
        }
    }
    // ensure the operand types match by forcing the right side to be the same type as the left side
    final Class<?> leftSideOperandType = getOperandType(leftSideOperand);
    final Expression castedRightOperand = castOperand(rightSideOperand, leftSideOperandType.getName());
    final CompoundExpression controlFlowExpression = new CompoundExpression(comparisonOperator,
            Arrays.asList(leftSideOperand, castedRightOperand));
    return controlFlowExpression;
}

From source file:edu.emory.cci.aiw.cvrg.eureka.etl.ksb.PropositionDefinitionFinder.java

private void getNodesToLoad(Stack<String> processedStack, LinkedHashSet<String> nodesToLoad) {
    while (!processedStack.empty()) {
        String node = processedStack.pop();
        if (!nodesToLoad.contains(node)) {
            if (defaultProps.contains(node)) {
                nodesToLoad.add(node);/*from   ww  w.  j a  v a  2s.c om*/
            } else {
                List<PropositionDefinition> parents;
                synchronized (parentsCache) {
                    parents = parentsCache.get(node);
                }
                if (parents != null) {
                    for (PropositionDefinition parent : parents) {
                        if (nodesToLoad.contains(parent.getId())) {
                            nodesToLoad.add(node);
                            break;
                        }
                    }
                }
            }
        }
    }
}

From source file:org.ros.internal.node.server.ParameterServer.java

@SuppressWarnings("unchecked")
public Object get(GraphName name) {
    Preconditions.checkArgument(name.isGlobal());
    Stack<String> parts = getGraphNameParts(name);
    Object possibleSubtree = tree;
    while (!parts.empty() && possibleSubtree != null) {
        if (!(possibleSubtree instanceof Map)) {
            return null;
        }//from ww w .j  a  v a 2  s  .  c  om
        possibleSubtree = ((Map<String, Object>) possibleSubtree).get(parts.pop());
    }
    return possibleSubtree;
}

From source file:org.ros.internal.node.server.ParameterServer.java

@SuppressWarnings("unchecked")
public boolean has(GraphName name) {
    Preconditions.checkArgument(name.isGlobal());
    Stack<String> parts = getGraphNameParts(name);
    Map<String, Object> subtree = tree;
    while (!parts.empty() && subtree.containsKey(parts.peek())) {
        String part = parts.pop();
        if (!parts.empty()) {
            subtree = (Map<String, Object>) subtree.get(part);
        }//  w  w w . jav a 2  s .c  om
    }
    return parts.empty();
}

From source file:org.ros.internal.node.server.ParameterServer.java

@SuppressWarnings("unchecked")
public void delete(GraphName name) {
    Preconditions.checkArgument(name.isGlobal());
    Stack<String> parts = getGraphNameParts(name);
    Map<String, Object> subtree = tree;
    while (!parts.empty() && subtree.containsKey(parts.peek())) {
        String part = parts.pop();
        if (parts.empty()) {
            subtree.remove(part);/*from  w  w w.  j av  a 2  s .  co m*/
        } else {
            subtree = (Map<String, Object>) subtree.get(part);
        }
    }
}

From source file:com.glaf.batch.job.BatchJob.java

public void execute(JobExecution execution) {
    IJobService jobService = ContextFactory.getBean("jobService");
    if (execution.getSteps() != null && !execution.getSteps().isEmpty()) {
        List<StepExecution> steps = execution.getSteps();
        Collections.sort(steps);/* w ww . j  a  v a 2s .c o  m*/
        /**
         * ??
         */
        Stack<StepExecution> stack = new Stack<StepExecution>();
        for (int i = steps.size() - 1; i >= 0; i--) {
            stack.push(steps.get(i));
        }

        while (!stack.empty()) {
            StepExecution step = stack.peek();
            if (!jobService.stepExecutionCompleted(step.getJobStepKey())) {
                boolean success = false;
                int retry = 0;
                while (retry < 3 && !success) {
                    retry++;
                    try {
                        jobService.startStepExecution(step.getJobStepKey());
                        if (StringUtils.isNotEmpty(step.getJobClass())) {
                            Object object = ClassUtils.instantiateObject(step.getJobClass());
                            if (object instanceof IStep) {
                                IStep ix = (IStep) object;
                                ix.execute(step);
                                if (jobService.stepExecutionCompleted(step.getJobStepKey())) {
                                    /**
                                     * ????
                                     */
                                    stack.pop();
                                    success = true;
                                    retry = Integer.MAX_VALUE;
                                    break;
                                }
                            }
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                if (!success) {
                    throw new RuntimeException(
                            step.getStepKey() + " " + step.getStepName() + " execute failed.");
                }
            }
        }
    }
}

From source file:org.ros.internal.node.server.ParameterServer.java

@SuppressWarnings("unchecked")
private void setValue(GraphName name, Object value) {
    Preconditions.checkArgument(name.isGlobal());
    Stack<String> parts = getGraphNameParts(name);
    Map<String, Object> subtree = tree;
    while (!parts.empty()) {
        String part = parts.pop();
        if (parts.empty()) {
            subtree.put(part, value);/*from ww w  . j av a  2s .  com*/
        } else if (subtree.containsKey(part) && subtree.get(part) instanceof Map) {
            subtree = (Map<String, Object>) subtree.get(part);
        } else {
            Map<String, Object> newSubtree = Maps.newHashMap();
            subtree.put(part, newSubtree);
            subtree = newSubtree;
        }
    }
}

From source file:org.apache.hadoop.hive.ql.plan.BaseWork.java

public Set<Operator<?>> getAllOperators() {

    Set<Operator<?>> returnSet = new LinkedHashSet<Operator<?>>();
    Set<Operator<?>> opSet = getAllRootOperators();
    Stack<Operator<?>> opStack = new Stack<Operator<?>>();

    // add all children
    opStack.addAll(opSet);//from  w w w  . j a  v a2 s.c om

    while (!opStack.empty()) {
        Operator<?> op = opStack.pop();
        returnSet.add(op);
        if (op.getChildOperators() != null) {
            opStack.addAll(op.getChildOperators());
        }
    }

    return returnSet;
}

From source file:org.apache.hadoop.hive.ql.plan.BaseWork.java

/**
 * Returns a set containing all leaf operators from the operator tree in this work.
 * @return a set containing all leaf operators in this operator tree.
 *//*w w  w. ja va  2s. co m*/
public Set<Operator<?>> getAllLeafOperators() {
    Set<Operator<?>> returnSet = new LinkedHashSet<Operator<?>>();
    Set<Operator<?>> opSet = getAllRootOperators();
    Stack<Operator<?>> opStack = new Stack<Operator<?>>();

    // add all children
    opStack.addAll(opSet);

    while (!opStack.empty()) {
        Operator<?> op = opStack.pop();
        if (op.getNumChild() == 0) {
            returnSet.add(op);
        }
        if (op.getChildOperators() != null) {
            opStack.addAll(op.getChildOperators());
        }
    }

    return returnSet;
}