Example usage for java.util Stack pop

List of usage examples for java.util Stack pop

Introduction

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

Prototype

public synchronized E pop() 

Source Link

Document

Removes the object at the top of this stack and returns that object as the value of this function.

Usage

From source file:FibonacciHeap.java

/**
 * Creates a String representation of this Fibonacci heap.
 *
 * @return String of this.//  ww  w.  j a v a 2s . co  m
 */
public String toString() {
    if (minNode == null) {
        return "FibonacciHeap=[]";
    }

    // create a new stack and put root on it
    Stack<FibonacciHeapNode<T>> stack = new Stack<FibonacciHeapNode<T>>();
    stack.push(minNode);

    StringBuffer buf = new StringBuffer(512);
    buf.append("FibonacciHeap=[");

    // do a simple breadth-first traversal on the tree
    while (!stack.empty()) {
        FibonacciHeapNode<T> curr = stack.pop();
        buf.append(curr);
        buf.append(", ");

        if (curr.child != null) {
            stack.push(curr.child);
        }

        FibonacciHeapNode<T> start = curr;
        curr = curr.right;

        while (curr != start) {
            buf.append(curr);
            buf.append(", ");

            if (curr.child != null) {
                stack.push(curr.child);
            }

            curr = curr.right;
        }
    }

    buf.append(']');

    return buf.toString();
}

From source file:com.dragoniade.deviantart.ui.PreferencesDialog.java

private boolean testPath(String location, String username) {
    File dest = LocationHelper.getFile(location, username, sample, sample.getImageFilename());

    Stack<File> stack = new Stack<File>();
    Stack<File> toDelete = new Stack<File>();

    stack.push(dest);//from www . j  a  v  a2  s.com
    while ((dest = dest.getParentFile()) != null) {
        stack.push(dest);
    }

    try {
        while (!stack.isEmpty()) {
            File file = stack.pop();
            if (file.exists()) {
                continue;
            } else {
                if (stack.isEmpty()) {
                    if (!file.createNewFile()) {
                        return false;
                    }
                } else {
                    if (!file.mkdir()) {
                        return false;
                    }
                }

                toDelete.add(file);
            }
        }
    } catch (IOException ex) {
        return false;
    } finally {
        while (!toDelete.isEmpty()) {
            toDelete.pop().delete();
        }
    }
    return true;
}

From source file:com.wavemaker.json.AlternateJSONTransformer.java

private static Object toObjectInternal(JSONState jsonState, JSONObject obj, Object root,
        FieldDefinition fieldDefinition, TypeState typeState, int arrayLevel, Stack<String> setterQueue)
        throws InstantiationException, IllegalAccessException, InvocationTargetException,
        NoSuchMethodException {/*from   w  w  w.  j a v a 2  s.  c  o m*/

    if (fieldDefinition == null) {
        throw new NullArgumentException("fieldDefinition");
    } else if (fieldDefinition.getTypeDefinition() == null) {
        throw new WMRuntimeException(MessageResource.JSON_TYPEDEF_REQUIRED);
    } else if (!(fieldDefinition.getTypeDefinition() instanceof ObjectTypeDefinition)) {
        throw new WMRuntimeException(MessageResource.JSON_OBJECTTYPEDEF_REQUIRED,
                fieldDefinition.getTypeDefinition(), fieldDefinition.getTypeDefinition().getClass());
    }

    ObjectTypeDefinition otd = (ObjectTypeDefinition) fieldDefinition.getTypeDefinition();

    Object instance = otd.newInstance();

    for (Object entryO : obj.entrySet()) {
        Entry<?, ?> entry = (Entry<?, ?>) entryO;
        String key = (String) entry.getKey();

        FieldDefinition nestedFieldDefinition = otd.getFields().get(key);
        if (nestedFieldDefinition == null) {
            throw new WMRuntimeException(MessageResource.JSON_NO_PROP_MATCHES_KEY, key, fieldDefinition);
        }
        if (!PropertyUtils.isWriteable(instance, key)) {
            logger.warn(MessageResource.JSON_NO_WRITE_METHOD.getMessage(fieldDefinition, key));
            continue;
        }

        // setter list support
        setterQueue.push(key);
        jsonState.getSettersCalled().add(getPropertyFromQueue(setterQueue));

        Object paramValue = toObjectInternal(jsonState, entry.getValue(), root, nestedFieldDefinition,
                typeState, 0, setterQueue);
        PropertyUtils.setProperty(instance, key, paramValue);

        // end setter list support
        setterQueue.pop();
    }

    return instance;
}

From source file:edu.mit.lib.tools.Modernize.java

public void importToMds(String targetUrl) throws IOException {
    if (manif.isEmpty()) {
        manif.read();//from  w  w w. ja v a2 s  .  co  m
    }
    Stack<String> parents = new Stack<>();
    parents.push(null); // indicates no parent object

    for (int i = 0; i < manif.entries.size(); i++) {
        String handle = manif.entries.get(i);
        uploadPackage(getPackage(handle), getPostUrl(targetUrl, parents.peek(), manif.ctypes.get(i)));
        if (i < manif.entries.size() - 1) {
            int diff = manif.levels.get(i) - manif.levels.get(i + 1);
            if (diff < 0) {
                // I have kids - put myself on the parents stack
                parents.push(handle);
            } else if (diff > 0) {
                // expose grandparents
                while (diff-- > 0) {
                    parents.pop();
                }
            } // if diff == 0 - next entry is a sibling, nothing to do
        }
    }
}

From source file:org.apache.tajo.plan.ExprAnnotator.java

@Override
public EvalNode visitAnd(Context ctx, Stack<Expr> stack, BinaryOperator expr) throws TajoException {
    stack.push(expr);/*  ww w  . j a  va2 s. c  o  m*/
    EvalNode left = visit(ctx, stack, expr.getLeft());
    EvalNode right = visit(ctx, stack, expr.getRight());
    stack.pop();

    return new BinaryEval(EvalType.AND, left, right);
}

From source file:org.apache.tajo.plan.ExprAnnotator.java

@Override
public EvalNode visitOr(Context ctx, Stack<Expr> stack, BinaryOperator expr) throws TajoException {
    stack.push(expr);/*from  w w  w. j a va 2s.  c om*/
    EvalNode left = visit(ctx, stack, expr.getLeft());
    EvalNode right = visit(ctx, stack, expr.getRight());
    stack.pop();

    return new BinaryEval(EvalType.OR, left, right);
}

From source file:org.apache.tajo.plan.ExprAnnotator.java

@Override
public EvalNode visitPlus(Context ctx, Stack<Expr> stack, BinaryOperator expr) throws TajoException {
    stack.push(expr);//from w ww  .  j  a  v a  2s .co  m
    EvalNode left = visit(ctx, stack, expr.getLeft());
    EvalNode right = visit(ctx, stack, expr.getRight());
    stack.pop();

    return createBinaryNode(ctx, EvalType.PLUS, left, right);
}

From source file:org.apache.tajo.plan.ExprAnnotator.java

@Override
public EvalNode visitMinus(Context ctx, Stack<Expr> stack, BinaryOperator expr) throws TajoException {
    stack.push(expr);/*from   w ww .  jav  a 2  s . c o  m*/
    EvalNode left = visit(ctx, stack, expr.getLeft());
    EvalNode right = visit(ctx, stack, expr.getRight());
    stack.pop();

    return createBinaryNode(ctx, EvalType.MINUS, left, right);
}

From source file:org.apache.tajo.plan.ExprAnnotator.java

@Override
public EvalNode visitMultiply(Context ctx, Stack<Expr> stack, BinaryOperator expr) throws TajoException {
    stack.push(expr);/*w  w w  .  java2 s . co m*/
    EvalNode left = visit(ctx, stack, expr.getLeft());
    EvalNode right = visit(ctx, stack, expr.getRight());
    stack.pop();

    return createBinaryNode(ctx, EvalType.MULTIPLY, left, right);
}

From source file:org.apache.tajo.plan.ExprAnnotator.java

@Override
public EvalNode visitDivide(Context ctx, Stack<Expr> stack, BinaryOperator expr) throws TajoException {
    stack.push(expr);/* w  w  w  .ja  v a  2s .c o  m*/
    EvalNode left = visit(ctx, stack, expr.getLeft());
    EvalNode right = visit(ctx, stack, expr.getRight());
    stack.pop();

    return createBinaryNode(ctx, EvalType.DIVIDE, left, right);
}