Example usage for java.util ArrayDeque peekLast

List of usage examples for java.util ArrayDeque peekLast

Introduction

In this page you can find the example usage for java.util ArrayDeque peekLast.

Prototype

public E peekLast() 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {

    ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8);

    deque.add(25);/*w  w  w  .  j  av  a 2s .co m*/
    deque.add(2);
    deque.add(1);
    deque.add(18);

    // this will retrieve end value
    int retval = deque.peekLast();
    System.out.println("Retrieved Element is " + retval);

    System.out.println(deque);
}

From source file:com.comcast.oscar.dictionary.DictionaryTLV.java

/**
 * // www. j a v  a 2  s .  com
 * @param adqsTypeHierarchyStack
        
 * @param sValue
        
 * @param jaTlvDictionary JSONArray
 */
private static void searchAndUpdateDictionaryValue(ArrayDeque<String> adqsTypeHierarchyStack,
        JSONArray jaTlvDictionary, final String sValue) {

    boolean localDebug = Boolean.FALSE;

    //Create a local copy
    ArrayDeque<String> adqsTypeHierarchyStackLocal = adqsTypeHierarchyStack.clone();

    //Cycle thru JSON Array and inspect each JSON Object
    for (int iJsonArrayIndex = 0; iJsonArrayIndex < jaTlvDictionary.length(); iJsonArrayIndex++) {

        if (debug | localDebug)
            System.out.println("DictionaryTLV.searchAndUpdateDictionaryValue(ad,ja,s) +-----INDEX: "
                    + iJsonArrayIndex + "-----+");

        JSONObject joTlvDictionary = null;

        try {
            joTlvDictionary = jaTlvDictionary.getJSONObject(iJsonArrayIndex);
        } catch (JSONException e1) {
            e1.printStackTrace();
        }

        try {

            //Check to see if this object have SubTypes , if so go into SubType Array
            if ((joTlvDictionary.getBoolean(Dictionary.ARE_SUBTYPES)) && (joTlvDictionary
                    .getString(Dictionary.TLV_NAME).equalsIgnoreCase(adqsTypeHierarchyStackLocal.peekLast()))) {

                if (debug | localDebug) {
                    System.out.println(
                            "DictionaryTLV.searchAndUpdateDictionaryValue(ad,ja,s) SUB-TYPE-ARRAY-TRUE: "
                                    + joTlvDictionary);
                    System.out.println(
                            "DictionaryTLV.searchAndUpdateDictionaryValue(ad,ja,s) -> TLV-SUB-NAME: -> "
                                    + adqsTypeHierarchyStackLocal.peekLast());
                }

                adqsTypeHierarchyStackLocal.removeLast();

                searchAndUpdateDictionaryValue(adqsTypeHierarchyStackLocal,
                        joTlvDictionary.getJSONArray(Dictionary.SUBTYPE_ARRAY), sValue);

            } else if (adqsTypeHierarchyStackLocal.size() == 1) {

                if (debug | localDebug)
                    System.out.println(
                            "DictionaryTLV.searchAndUpdateDictionaryValue(ad,ja,s) SUB-TYPE-ARRAY-FALSE: "
                                    + joTlvDictionary);

                searchAndUpdateDictionaryValue(adqsTypeHierarchyStackLocal, joTlvDictionary, sValue);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

}

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testPeekLast() {
    Object o1 = new Object();
    Object o2 = new Object();
    Object o3 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertNull(deque.peekLast());

    deque.add(o1);/*from   w ww  . java2  s  . c om*/
    assertEquals(o1, deque.peekLast());
    checkDequeSizeAndContent(deque, o1);

    deque.add(o2);
    assertEquals(o2, deque.peekLast());
    checkDequeSizeAndContent(deque, o1, o2);

    deque.addFirst(o3);
    assertEquals(o2, deque.peekLast());
    checkDequeSizeAndContent(deque, o3, o1, o2);

    deque.clear();
    assertTrue(deque.isEmpty());
    assertNull(deque.peekLast());
}