List of usage examples for java.util ArrayDeque addFirst
public void addFirst(E e)
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(5); deque.add(25);/*from w w w.j av a 2 s .co m*/ deque.add(2); deque.add(35); deque.addFirst(10); deque.addFirst(3); deque.addFirst(1);//now, element 1 will be at the front deque.add(45); deque.add(40); System.out.println(deque); }
From source file:com.comcast.oscar.dictionary.DictionaryTLV.java
/** * /*w w w. j a va 2 s. co m*/ * @param sTlvDotNotation Example 24.1.3 * @param dsq DictionarySQLQueries * @return ArrayDeque<String> of TLV Names found in Dictionary */ public static ArrayDeque<String> getTypeHierarchyStack(String sTlvDotNotation, DictionarySQLQueries dsq) { boolean localDebug = Boolean.FALSE; ArrayDeque<String> adTypeHierarchyStack = new ArrayDeque<String>(); List<String> lsTlvDotNotation = new ArrayList<String>(); lsTlvDotNotation = Arrays.asList(sTlvDotNotation.split("\\.")); if (debug | localDebug) System.out.println("ConfigrationFileExport.getTlvDefintion(): " + lsTlvDotNotation.toString()); //Get TLV Dictionary for the Top Level JSONObject joTlvDictionary = dsq.getTlvDefinition(Integer.decode(lsTlvDotNotation.get(0))); //Search for TLV Definition if (lsTlvDotNotation.size() == 1) { try { adTypeHierarchyStack.addFirst(joTlvDictionary.getString(Dictionary.TLV_NAME)); } catch (JSONException e) { e.printStackTrace(); } } else if (lsTlvDotNotation.size() >= 1) { try { adTypeHierarchyStack.addFirst(joTlvDictionary.getString(Dictionary.TLV_NAME)); } catch (JSONException e) { e.printStackTrace(); } int iRecursiveSearch = 0; while (iRecursiveSearch < lsTlvDotNotation.size()) { if (debug | localDebug) System.out.println("ConfigrationFileExport.getTlvDefintion(): WHILE-LOOP"); try { if (joTlvDictionary.getString(Dictionary.TYPE).equals(lsTlvDotNotation.get(iRecursiveSearch))) { if (joTlvDictionary.getBoolean(Dictionary.ARE_SUBTYPES)) { try { JSONArray jaTlvDictionary = joTlvDictionary.getJSONArray(Dictionary.SUBTYPE_ARRAY); for (int iIndex = 0; iIndex < jaTlvDictionary.length(); iIndex++) { if (debug | localDebug) System.out.println("ConfigrationFileExport.getTlvDefintion(): FOR-LOOP"); JSONObject joTlvDictionaryTemp = jaTlvDictionary.getJSONObject(iIndex); if (joTlvDictionaryTemp.getString(Dictionary.TYPE) .equals(lsTlvDotNotation.get(iRecursiveSearch + 1))) { joTlvDictionary = joTlvDictionaryTemp; iRecursiveSearch++; try { adTypeHierarchyStack .addFirst(joTlvDictionary.getString(Dictionary.TLV_NAME)); } catch (JSONException e) { e.printStackTrace(); } break; } } } catch (JSONException e) { e.printStackTrace(); } } else { iRecursiveSearch++; } } } catch (JSONException e1) { e1.printStackTrace(); } } } return adTypeHierarchyStack; }
From source file:androidx.navigation.NavDestination.java
/** * Build an array containing the hierarchy from the root down to this destination. * * @return An array containing all of the ids from the root to this destination *///w w w .j a v a 2 s . c o m @NonNull int[] buildDeepLinkIds() { ArrayDeque<NavDestination> hierarchy = new ArrayDeque<>(); NavDestination current = this; do { NavGraph parent = current.getParent(); if (parent == null || parent.getStartDestination() != current.getId()) { hierarchy.addFirst(current); } current = parent; } while (current != null); int[] deepLinkIds = new int[hierarchy.size()]; int index = 0; for (NavDestination destination : hierarchy) { deepLinkIds[index++] = destination.getId(); } return deepLinkIds; }
From source file:com.restswitch.controlpanel.MainActivity.java
private TimingStats getTimingStats(String devid, int ms, int valcnt) { if (valcnt < 5) valcnt = 5;//from w ww .j a v a 2 s . co m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // devid1_times String key = (devid + "_times"); String jsonData = prefs.getString(key, ""); JSONArray data = null; try { data = new JSONArray(jsonData); } catch (Exception ex) { data = new JSONArray(); } data.put(ms); // examine the last 'valcnt' values int minms = 8000; int maxms = 0; int totalms = 0; int len = 0; ArrayDeque<Integer> newData = new ArrayDeque<>(); for (int i = data.length() - 1; i >= 0; --i) { int val = 0; try { val = data.getInt(i); } catch (Exception ex) { continue; } if (val > 7) { // 8ms sanity if (val > maxms) maxms = val; if (val < minms) minms = val; totalms += val; newData.addFirst(val); ++len; if (len >= valcnt) break; } } SharedPreferences.Editor prefsEdit = prefs.edit(); try { JSONArray outJson = new JSONArray(newData); prefsEdit.putString(key, outJson.toString()); //alertInfo(outJson.toString()); } catch (Exception ex) { prefsEdit.remove(key); } prefsEdit.apply(); int avgms = (len == 0) ? 0 : (totalms / len); TimingStats stats = new TimingStats(ms, minms, avgms, maxms); return (stats); }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testAddFirst() { Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); deque.addFirst(o1); checkDequeSizeAndContent(deque, o1); deque.addFirst(o2);/*from w w w .j av a 2 s .c o m*/ checkDequeSizeAndContent(deque, o2, o1); deque.addFirst(o3); checkDequeSizeAndContent(deque, o3, o2, o1); try { deque.addFirst(null); fail(); } catch (NullPointerException expected) { } }
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());/*from w w w .j a va2s.co m*/ deque.add(o1); 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 testPeekLast() { Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); assertNull(deque.peekLast());//from w ww. ja v a2s . c o m deque.add(o1); 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()); }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testPeekFirst() { Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); assertNull(deque.peekFirst());/*from w w w .j a v a 2s.c o m*/ deque.add(o1); assertEquals(o1, deque.peekFirst()); checkDequeSizeAndContent(deque, o1); deque.add(o2); assertEquals(o1, deque.peekFirst()); checkDequeSizeAndContent(deque, o1, o2); deque.addFirst(o3); assertEquals(o3, deque.peekFirst()); checkDequeSizeAndContent(deque, o3, o1, o2); deque.clear(); assertTrue(deque.isEmpty()); assertNull(deque.peekFirst()); }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testFailFastIterator() { ArrayDeque<Object> deque = new ArrayDeque<>(asList(getFullNonNullElements())); Iterator<Object> it = deque.iterator(); it.next();//from w ww. j a va2s . c om deque.removeFirst(); try { it.next(); } catch (ConcurrentModificationException e) { fail(); } deque.removeLast(); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.iterator(); it.next(); deque.clear(); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.iterator(); it.next(); deque.addFirst(new Object()); try { it.next(); } catch (ConcurrentModificationException e) { fail(); } deque.addLast(new Object()); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.iterator(); it.next(); it.next(); deque.removeFirst(); try { it.remove(); } catch (ConcurrentModificationException e) { fail(); } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.iterator(); it.next(); it.next(); deque.removeFirst(); deque.removeFirst(); try { it.remove(); fail(); } catch (ConcurrentModificationException expected) { } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testFailFastDescendingIterator() { ArrayDeque<Object> deque = new ArrayDeque<>(asList(getFullNonNullElements())); Iterator<Object> it = deque.descendingIterator(); it.next();/* ww w . j av a 2s.co m*/ deque.removeLast(); try { it.next(); } catch (ConcurrentModificationException e) { fail(); } deque.removeFirst(); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.descendingIterator(); it.next(); deque.clear(); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.descendingIterator(); it.next(); deque.addLast(new Object()); try { it.next(); } catch (ConcurrentModificationException e) { fail(); } deque.addFirst(new Object()); try { it.next(); fail(); } catch (ConcurrentModificationException expected) { } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.descendingIterator(); it.next(); it.next(); deque.removeLast(); try { it.remove(); } catch (ConcurrentModificationException e) { fail(); } deque = new ArrayDeque<>(asList(getFullNonNullElements())); it = deque.descendingIterator(); it.next(); it.next(); deque.removeLast(); deque.removeLast(); try { it.remove(); fail(); } catch (ConcurrentModificationException expected) { } }