List of usage examples for java.util ArrayDeque peek
public E peek()
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(25);/*from ww w . jav a2s . co m*/ deque.add(2); deque.add(1); deque.add(18); // this will retrieve head of the queue int retval = deque.peek(); System.out.println("Retrieved Element is " + retval); System.out.println(deque); }
From source file:com.comcast.oscar.dictionary.DictionaryTLV.java
/** * // w ww . ja v a 2 s.com * @param adqsTypeHierarchyStack * @param sValue * @param joTlvDictionary JSONObject * @return JSONObject */ private static JSONObject searchAndUpdateDictionaryValue(ArrayDeque<String> adqsTypeHierarchyStack, JSONObject joTlvDictionary, final String sValue) { boolean localDebug = Boolean.FALSE; if (debug | localDebug) System.out.println("DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s): Peek: " + adqsTypeHierarchyStack.peek()); try { if (joTlvDictionary.getString(Dictionary.TLV_NAME).equalsIgnoreCase(adqsTypeHierarchyStack.peek())) { String sDataType = joTlvDictionary.getString(Dictionary.DATA_TYPE); //Determine Data Type and insert with correct //Convert Value to Proper Data Type if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_INTEGER)) { if (debug | localDebug) System.out.println("DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s): " + sValue); //Get Value int iValue = Integer.parseInt(sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, iValue); if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_INTEGER: " + iValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_OID)) { /* DO NOTHING */ } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_BYTE_ARRAY)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_BYTE_ARRAY: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_STRING_NULL_TERMINATED)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_STRING_NULL_TERMINATED: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_STRING)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_STRING: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_MULTI_TLV_BYTE_ARRAY)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_MULTI_TLV_BYTE_ARRAY: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_TRANSPORT_ADDR_IPV4_ADDR)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_TRANSPORT_ADDR_IPV4_ADDR: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_TRANSPORT_ADDR_IPV6_ADDR)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_TRANSPORT_ADDR_IPV6_ADDR: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_TRANSPORT_ADDR_INET_ADDR)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_TRANSPORT_ADDR_INET_ADDR: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_DOUBLE_BYTE_ARRAY)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_DOUBLE_BYTE_ARRAY: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_STRING_BITS)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_STRING_BITS: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_MAC_ADDRESS)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_MAC_ADDRESS: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_BYTE_ARRAY_IPV4_ADDR)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_BYTE_ARRAY_IPV4_ADDR: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_BYTE_ARRAY_IPV6_ADDR)) { if (debug | localDebug) System.out.println( "DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_BYTE_ARRAY_IPV6_ADDR: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_BYTE)) { if (debug | localDebug) System.out .println("DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_BYTE: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_OID_ASN1_OBJECT_6)) { if (debug | localDebug) System.out .println("DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s) -> DATA_TYPE_BYTE: " + sValue); //Insert Value into JSON Object joTlvDictionary.put(Dictionary.VALUE, sValue); } } } catch (JSONException e) { e.printStackTrace(); } if (debug | localDebug) System.out.println("DictionaryTLV.searchAndUpdateDictionaryValue(ad,jo,s): RETURN: " + joTlvDictionary); return joTlvDictionary; }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testPeek() { Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); assertNull(deque.peek()); deque.add(o1);/*from w w w . j a va 2 s .c o m*/ assertEquals(o1, deque.peek()); checkDequeSizeAndContent(deque, o1); deque.add(o2); assertEquals(o1, deque.peek()); checkDequeSizeAndContent(deque, o1, o2); deque.addFirst(o3); assertEquals(o3, deque.peek()); checkDequeSizeAndContent(deque, o3, o1, o2); deque.clear(); assertTrue(deque.isEmpty()); assertNull(deque.peek()); }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRolloverInvariants() { ArrayDeque<Integer> deque = new ArrayDeque<>(); assertTrue(deque.add(1));//from w w w. j a v a 2s . c o m assertEquals(1, (int) deque.removeFirst()); for (int i = 0; i < 100; i++) { assertTrue(deque.add(i)); } assertNotNull(deque.peek()); assertFalse(deque.isEmpty()); Iterator<Integer> it = deque.iterator(); for (int i = 0; i < 100; i++) { assertTrue(it.hasNext()); assertEquals(i, (int) it.next()); it.remove(); } assertFalse(it.hasNext()); assertNull(deque.peek()); assertTrue(deque.isEmpty()); }