List of usage examples for java.util ArrayDeque removeLast
public E removeLast()
From source file:Main.java
public static void main(String[] args) { ArrayDeque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(3);/*from www . j a va2 s.co m*/ deque.add(2); deque.add(25); deque.add(40); System.out.println(deque); // this will remove element at last position int retval = deque.removeLast(); System.out.println("Element removed is: " + retval); System.out.println(deque); }
From source file:com.redhat.lightblue.util.Error.java
/** * Pops the context information from current thread stack *///from ww w.j av a2 s.c o m public static void pop() { ArrayDeque<String> c = THREAD_CONTEXT.get(); if (!c.isEmpty()) { String context = c.removeLast(); LOGGER.debug("pop: {}", context); } if (c.isEmpty()) { reset(); } }
From source file:com.comcast.oscar.dictionary.DictionaryTLV.java
/** * //from ww w.ja v a 2s.c o m * @param adqsTypeHierarchyStack - TLV Name * @param joDictionary * @param sValue */ public static void updateDictionaryValue(final ArrayDeque<String> adqsTypeHierarchyStack, JSONObject joDictionary, final String sValue) { boolean localDebug = Boolean.FALSE; //Create a local copy ArrayDeque<String> adqsTypeHierarchyStackLocal = adqsTypeHierarchyStack.clone(); if (debug | localDebug) { System.out.println("DictionaryTLV.updateDictionaryValue(ad,jo,s): adqsTypeHierarchyStackLocal: " + adqsTypeHierarchyStackLocal); System.out.println("DictionaryTLV.updateDictionaryValue(ad,jo,s): sValue: " + sValue); } try { if (joDictionary.get(Dictionary.DATA_TYPE) == DataTypeDictionaryReference.DATA_TYPE_OID) { if (debug | localDebug) System.out.println("DictionaryTLV.updateDictionaryValue(ad,jo,s): DATA_TYPE_OID: " + sValue); } else if (joDictionary.getBoolean(Dictionary.ARE_SUBTYPES)) { //Remove Starting TlvName adqsTypeHierarchyStackLocal.removeLast(); searchAndUpdateDictionaryValue(adqsTypeHierarchyStackLocal, joDictionary.getJSONArray(Dictionary.SUBTYPE_ARRAY), sValue); } else { searchAndUpdateDictionaryValue(adqsTypeHierarchyStackLocal, joDictionary, sValue); } } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testRemoveLast() { Object o1 = new Object(); Object o2 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); try {/*from ww w. ja v a2s . c o m*/ deque.removeLast(); fail(); } catch (NoSuchElementException expected) { } deque.add(o1); assertEquals(o1, deque.removeLast()); assertTrue(deque.isEmpty()); deque.add(o1); deque.add(o2); assertEquals(o2, deque.removeLast()); checkDequeSizeAndContent(deque, o1); assertEquals(o1, deque.removeLast()); assertEquals(0, deque.size()); try { deque.removeLast(); fail(); } catch (NoSuchElementException 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();/*from w ww . ja v a 2s . c o 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) { } }
From source file:com.comcast.oscar.dictionary.DictionaryTLV.java
/** * // w w w. j av 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 testFailFastIterator() { ArrayDeque<Object> deque = new ArrayDeque<>(asList(getFullNonNullElements())); Iterator<Object> it = deque.iterator(); it.next();/*from w ww .ja v a 2 s .com*/ 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.vgi.mafscaling.VECalc.java
protected void loadLogFile() { fileChooser.setMultiSelectionEnabled(true); if (JFileChooser.APPROVE_OPTION != fileChooser.showOpenDialog(this)) return;//w ww . j a va2 s .co m File[] files = fileChooser.getSelectedFiles(); for (File file : files) { BufferedReader br = null; ArrayDeque<String[]> buffer = new ArrayDeque<String[]>(); try { br = new BufferedReader(new FileReader(file.getAbsoluteFile())); String line = br.readLine(); if (line != null) { String[] elements = line.split("(\\s*)?,(\\s*)?", -1); getColumnsFilters(elements); boolean resetColumns = false; if (logThrottleAngleColIdx >= 0 || logFfbColIdx >= 0 || logSdColIdx >= 0 || (logWbAfrColIdx >= 0 && isOl) || (logStockAfrColIdx >= 0 && !isOl) || (logAfLearningColIdx >= 0 && !isOl) || (logAfCorrectionColIdx >= 0 && !isOl) || logRpmColIdx >= 0 || logMafColIdx >= 0 || logIatColIdx >= 0 || logMpColIdx >= 0) { if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, "Would you like to reset column names or filter values?", "Columns/Filters Reset", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE)) resetColumns = true; } if (resetColumns || logThrottleAngleColIdx < 0 || logFfbColIdx < 0 || logSdColIdx < 0 || (logWbAfrColIdx < 0 && isOl) || (logStockAfrColIdx < 0 && !isOl) || (logAfLearningColIdx < 0 && !isOl) || (logAfCorrectionColIdx < 0 && !isOl) || logRpmColIdx < 0 || logMafColIdx < 0 || logIatColIdx < 0 || logMpColIdx < 0) { ColumnsFiltersSelection selectionWindow = new VEColumnsFiltersSelection(false); if (!selectionWindow.getUserSettings(elements) || !getColumnsFilters(elements)) return; } if (logClOlStatusColIdx == -1) clValue = -1; String[] flds; String[] afrflds; boolean removed = false; int i = 2; int clol = -1; int row = getLogTableEmptyRow(); double thrtlMaxChange2 = thrtlMaxChange + thrtlMaxChange / 2.0; double throttle = 0; double pThrottle = 0; double ppThrottle = 0; double afr = 0; double rpm; double ffb; double iat; clearRunTables(); setCursor(new Cursor(Cursor.WAIT_CURSOR)); for (int k = 0; k <= afrRowOffset && line != null; ++k) { line = br.readLine(); if (line != null) buffer.addFirst(line.split(",", -1)); } try { while (line != null && buffer.size() > afrRowOffset) { afrflds = buffer.getFirst(); flds = buffer.removeLast(); line = br.readLine(); if (line != null) buffer.addFirst(line.split(",", -1)); ppThrottle = pThrottle; pThrottle = throttle; throttle = Double.valueOf(flds[logThrottleAngleColIdx]); try { if (row > 0 && Math.abs(pThrottle - throttle) > thrtlMaxChange) { if (!removed) Utils.removeRow(row--, logDataTable); removed = true; } else if (row <= 0 || Math.abs(ppThrottle - throttle) <= thrtlMaxChange2) { // Filters afr = (isOl ? Double.valueOf(afrflds[logWbAfrColIdx]) : Double.valueOf(afrflds[logStockAfrColIdx])); rpm = Double.valueOf(flds[logRpmColIdx]); ffb = Double.valueOf(flds[logFfbColIdx]); iat = Double.valueOf(flds[logIatColIdx]); if (clValue != -1) clol = Integer.valueOf(flds[logClOlStatusColIdx]); boolean flag = isOl ? ((afr <= afrMax || throttle >= thrtlMin) && afr <= afrMax) : (afrMin <= afr); if (flag && clol == clValue && rpmMin <= rpm && ffbMin <= ffb && ffb <= ffbMax && iat <= iatMax) { removed = false; if (!isOl) trims.add(Double.valueOf(flds[logAfLearningColIdx]) + Double.valueOf(flds[logAfCorrectionColIdx])); Utils.ensureRowCount(row + 1, logDataTable); logDataTable.setValueAt(rpm, row, 0); logDataTable.setValueAt(iat, row, 1); logDataTable.setValueAt(Double.valueOf(flds[logMpColIdx]), row, 2); logDataTable.setValueAt(ffb, row, 3); logDataTable.setValueAt(afr, row, 4); logDataTable.setValueAt(Double.valueOf(flds[logMafColIdx]), row, 5); logDataTable.setValueAt(Double.valueOf(flds[logSdColIdx]), row, 6); row += 1; } else removed = true; } else removed = true; } catch (NumberFormatException e) { logger.error(e); JOptionPane.showMessageDialog(null, "Error parsing number at " + file.getName() + " line " + i + ": " + e, "Error processing file", JOptionPane.ERROR_MESSAGE); return; } i += 1; } } finally { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } } catch (Exception e) { logger.error(e); JOptionPane.showMessageDialog(null, e, "Error opening file", JOptionPane.ERROR_MESSAGE); } finally { if (br != null) { try { br.close(); } catch (IOException e) { logger.error(e); } } } } }
From source file:com.vgi.mafscaling.OpenLoop.java
protected void loadLogFile() { fileChooser.setMultiSelectionEnabled(true); if (JFileChooser.APPROVE_OPTION != fileChooser.showOpenDialog(this)) return;// w w w. j av a2 s . c o m boolean isPolSet = polfTable.isSet(); File[] files = fileChooser.getSelectedFiles(); for (File file : files) { BufferedReader br = null; ArrayDeque<String[]> buffer = new ArrayDeque<String[]>(); try { br = new BufferedReader(new FileReader(file.getAbsoluteFile())); String line = br.readLine(); if (line != null) { String[] elements = line.split("(\\s*)?,(\\s*)?", -1); getColumnsFilters(elements, false); boolean resetColumns = false; if (logThtlAngleColIdx >= 0 || logAfLearningColIdx >= 0 || logAfCorrectionColIdx >= 0 || logMafvColIdx >= 0 || logAfrColIdx >= 0 || logRpmColIdx >= 0 || logLoadColIdx >= 0 || logCommandedAfrCol >= 0) { if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, "Would you like to reset column names or filter values?", "Columns/Filters Reset", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE)) resetColumns = true; } if (resetColumns || logThtlAngleColIdx < 0 || logAfLearningColIdx < 0 || logAfCorrectionColIdx < 0 || logMafvColIdx < 0 || logAfrColIdx < 0 || logRpmColIdx < 0 || logLoadColIdx < 0 || (logCommandedAfrCol < 0 && !isPolSet)) { ColumnsFiltersSelection selectionWindow = new OLColumnsFiltersSelection(isPolSet); if (!selectionWindow.getUserSettings(elements) || !getColumnsFilters(elements, isPolSet)) return; } String[] flds; String[] afrflds; boolean wotFlag = true; boolean foundWot = false; double throttle; double stft; double ltft; double afr; double rpm; double load; double mafv; double cmdafr = 0; double afrErr = 0; int skipRowCount = 0; int row = 0; int i = 0; int j = 0; for (; i < runTables.length; ++i) { if (runTables[i].getValueAt(0, 0).toString().isEmpty()) break; } if (i == runTables.length) return; setCursor(new Cursor(Cursor.WAIT_CURSOR)); for (int k = 0; k <= afrRowOffset && line != null; ++k) { line = br.readLine(); if (line != null) buffer.addFirst(line.split(",", -1)); } while (line != null && buffer.size() > afrRowOffset) { afrflds = buffer.getFirst(); flds = buffer.removeLast(); line = br.readLine(); if (line != null) buffer.addFirst(line.split(",", -1)); try { throttle = Double.valueOf(flds[logThtlAngleColIdx]); if (row == 0 && throttle < 99) wotFlag = false; if (throttle < wotPoint) { if (wotFlag == true) { wotFlag = false; skipRowCount = 0; j -= 1; while (j > 0 && skipRowCount < skipRowsOnTransition) { runTables[i].setValueAt("", j, 0); runTables[i].setValueAt("", j, 1); runTables[i].setValueAt("", j, 2); skipRowCount += 1; j -= 1; } skipRowCount = 0; } } else { if (wotFlag == false) { wotFlag = true; skipRowCount = 0; if (foundWot) { i += 1; if (i == runTables.length) return; } if (row > 0) j = 0; } if (skipRowCount >= skipRowsOnTransition) { mafv = Double.valueOf(flds[logMafvColIdx]); if (minMafV <= mafv) { foundWot = true; stft = Double.valueOf(flds[logAfCorrectionColIdx]); ltft = Double.valueOf(flds[logAfLearningColIdx]); afr = Double.valueOf(afrflds[logAfrColIdx]); rpm = Double.valueOf(flds[logRpmColIdx]); load = Double.valueOf(flds[logLoadColIdx]); afr = afr / ((100.0 - (ltft + stft)) / 100.0); if (logCommandedAfrCol >= 0) cmdafr = Double.valueOf(flds[logCommandedAfrCol]); else if (isPolSet) cmdafr = Utils.calculateCommandedAfr(rpm, load, minWotEnrichment, polfTable); else { JOptionPane.showMessageDialog(null, "Please set either \"Commanded AFR\" column or \"Primary Open Loop Fueling\" table", "Error", JOptionPane.ERROR_MESSAGE); return; } afrErr = (afr - cmdafr) / cmdafr * 100.0; if (Math.abs(afrErr) <= afrErrPrct) { Utils.ensureRowCount(j + 1, runTables[i]); runTables[i].setValueAt(rpm, j, 0); runTables[i].setValueAt(mafv, j, 1); runTables[i].setValueAt(afrErr, j, 2); j += 1; } } } skipRowCount += 1; } } catch (NumberFormatException e) { logger.error(e); JOptionPane.showMessageDialog(null, "Error parsing number at " + file.getName() + " line " + (row + 1) + ": " + e, "Error processing file", JOptionPane.ERROR_MESSAGE); return; } row += 1; } if (!foundWot) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); JOptionPane.showMessageDialog(null, "Sorry, no WOT pulls were found in the log file", "No WOT data", JOptionPane.INFORMATION_MESSAGE); } } } catch (Exception e) { logger.error(e); JOptionPane.showMessageDialog(null, e, "Error opening file", JOptionPane.ERROR_MESSAGE); } finally { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); if (br != null) { try { br.close(); } catch (IOException e) { logger.error(e); } } } } }