Example usage for java.util Stack peek

List of usage examples for java.util Stack peek

Introduction

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

Prototype

public synchronized E peek() 

Source Link

Document

Looks at the object at the top of this stack without removing it from the stack.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    Stack s = new Stack();
    s.push("A");/*from w ww. ja  v  a 2 s  .c o  m*/
    s.push("B");
    s.push("C");

    System.out.println("Next: " + s.peek());
}

From source file:Main.java

public static void main(String args[]) {
    Stack<String> s = new Stack<String>();
    s.push("A");/*from   w  w  w.  j  a  v a 2  s .  c  om*/
    s.push("B");
    s.push("C");

    System.out.println("Next: " + s.peek());
}

From source file:MainClass.java

public static void main(String args[]) {
    Stack s = new Stack();
    s.push("A");/*from ww  w . ja va 2  s  .com*/
    s.push("B");
    s.push("C");

    System.out.println("Next: " + s.peek());
    s.push("D");

    System.out.println(s.pop());
    s.push("E");
    s.push("F");

    int count = s.search("E");
    while (count != -1 && count > 1) {
        s.pop();
        count--;
    }
    System.out.println(s);
}

From source file:StackExample.java

public static void main(String args[]) {
    Stack s = new Stack();
    s.push("Java");
    s.push("Source");
    s.push("and");

    System.out.println("Next: " + s.peek());
    s.push("Support");
    System.out.println(s.pop());//from w w w. j  a v a2  s  .  c o  m
    s.push(".");
    int count = s.search("Java");
    while (count != -1 && count > 1) {
        s.pop();
        count--;
    }
    System.out.println(s.pop());
    System.out.println(s.empty());
}

From source file:Main.java

public static void main(String args[]) {
    Stack<String> s = new Stack<String>();
    s.push("A");//from   w ww.  j ava 2s. c  o  m
    s.push("B");
    s.push("C");

    System.out.println("Next: " + s.peek());
    s.push("D");

    System.out.println(s.pop());
    s.push("E");
    s.push("F");

    int count = s.search("E");
    while (count != -1 && count > 1) {
        s.pop();
        count--;
    }
    System.out.println(s);
}

From source file:Main.java

public static void main(String args[]) {

    Stack st = new Stack();

    st.push("Java");
    st.push("Source");
    st.push("from java2s.com");

    // checking the top object
    System.out.println("Top object is: " + st.peek());
}

From source file:de.codesourcery.gittimelapse.Main.java

public static void main(String[] args) throws IOException, RevisionSyntaxException, GitAPIException {
    final Stack<String> argStack = new Stack<>();

    final String testFile = "/home/tgierke/workspace/voipmanager/voipmngr/voipmngr/build.xml";
    if (ArrayUtils.isEmpty(args) && new File(testFile).exists()) {
        argStack.push(testFile);//from   ww w. ja  v  a2s.com
    }

    File file = null;
    while (!argStack.isEmpty()) {
        if ("-d".equals(argStack.peek())) {
            DEBUG_MODE = true;
            argStack.pop();
        } else {
            file = new File(argStack.pop());
        }
    }

    if (file == null) {
        System.err.println("ERROR: Invalid command line.");
        System.err.println("Usage: [-d] <versioned file>\n");
        return;
    }

    final GitHelper helper = new GitHelper(file.getParentFile());

    MyFrame frame = new MyFrame(file, helper);
    frame.setPreferredSize(new Dimension(640, 480));
    frame.pack();
    frame.setVisible(true);
}

From source file:edu.usc.squash.Main.java

public static void main(String[] args) {
    Stack<Module> modulesStack;
    Module module;// w  w  w .j a  v  a  2 s.  co  m

    if (parseInputs(args) == false) {
        System.exit(-1); //The input files do not exist
    }

    String separator = "----------------------------------------------";
    System.out.println("Squash v2.0");
    System.out.println(separator);
    long start = System.currentTimeMillis();

    // Parsing the input library
    Library library = QLib.readLib(libraryPath);
    library.setCurrentECC(currentECC);

    HashMap<String, Module> modules = parseQASMHF(library);
    Module mainModule = modules.get("main");

    //Finding max{A_L_i}
    int childModulesLogicalAncillaReq;
    int moduleAncillaReq;

    modulesStack = new Stack<Module>();

    modulesStack.add(mainModule);
    while (!modulesStack.isEmpty()) {
        module = modulesStack.peek();
        if (!module.isVisited() && module.isChildrenVisited()) {
            //Finding the maximum 
            childModulesLogicalAncillaReq = 0;
            for (Module child : module.getDFG().getModules()) {
                childModulesLogicalAncillaReq = Math.max(childModulesLogicalAncillaReq, child.getAncillaReq());
            }
            moduleAncillaReq = module.getAncillaQubitNo() + childModulesLogicalAncillaReq;
            module.setAncillaReq(moduleAncillaReq);
            //            System.out.println("Module "+module.getName()+" requires "+moduleAncillaReq+" ancilla.");

            modulesStack.pop();
            module.setVisited();
        } else if (module.isVisited()) {
            modulesStack.pop();
        } else if (!module.isChildrenVisited()) {
            modulesStack.addAll(module.getDFG().getModules());
            module.setChildrenVisited();
        }
    }

    int totalLogicalAncilla = mainModule.getAncillaReq();

    System.out.println("A_L_i_max: " + totalLogicalAncilla);

    final int Q_L = mainModule.getDataQubitNo();

    /* 
     * In order traversal of modules
     */
    //Making sure all of the modules are unvisited
    for (Module m : modules.values()) {
        m.setUnvisited();
    }
    modulesStack = new Stack<Module>();

    modulesStack.add(mainModule);
    while (!modulesStack.isEmpty()) {
        module = modulesStack.peek();
        if (!module.isVisited() && module.isChildrenVisited()) {
            System.out.println(separator);

            mapModule(module, k, physicalAncillaBudget, totalLogicalAncilla, Q_L, beta_pmd, alpha_int,
                    gamma_memory, library);

            modulesStack.pop();
            module.setVisited();
        } else if (module.isVisited()) {
            modulesStack.pop();
        } else if (!module.isChildrenVisited()) {
            modulesStack.addAll(module.getDFG().getModules());
            module.setChildrenVisited();
        }
    }

    System.out.println(separator);
    double runtime = (System.currentTimeMillis() - start) / 1000.0;
    System.out.println("B_P: " + B_P);
    System.out.println("Total Runtime:\t" + runtime + " sec");
}

From source file:Main.java

public static <E> E peekOrNull(final Stack<? extends E> stack) {
    return !isEmpty(stack) ? stack.peek() : null;
}

From source file:org.sakaiproject.signup.tool.entityproviders.CopyFileProcessor.java

public static Element timeslotToXml(SignupTimeslot timeslot, Document doc, Stack<Element> stack) {
    Element element = doc.createElement("timeslot");

    if (stack.isEmpty()) {
        doc.appendChild(element);/*from  w w w.  j  a  v a 2s . co  m*/
    } else {
        ((Element) stack.peek()).appendChild(element);
    }

    stack.push(element);

    Date startTime = timeslot.getStartTime();
    Date endTime = timeslot.getEndTime();
    Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String strStartTime = formatter.format(startTime);
    String strEndTime = formatter.format(endTime);

    element.setAttribute("endTime", strEndTime);
    element.setAttribute("startTime", strStartTime);

    stack.pop();

    return element;
}