List of usage examples for java.util ArrayDeque size
public int size()
From source file:fr.moribus.imageonmap.migration.V3Migrator.java
private void mergeMapData() { PluginLogger.info(I.t("Merging map data...")); ArrayDeque<OldSavedMap> remainingMaps = new ArrayDeque<>(); ArrayDeque<OldSavedPoster> remainingPosters = new ArrayDeque<>(); ArrayDeque<Short> missingMapIds = new ArrayDeque<>(); UUID playerUUID;//from www.j a va 2s. c o m OldSavedMap map; while (!mapsToMigrate.isEmpty()) { map = mapsToMigrate.pop(); playerUUID = usersUUIDs.get(map.getUserName()); if (playerUUID == null) { remainingMaps.add(map); } else if (!map.isMapValid()) { missingMapIds.add(map.getMapId()); } else { MapManager.insertMap(map.toImageMap(playerUUID)); } } mapsToMigrate.addAll(remainingMaps); OldSavedPoster poster; while (!postersToMigrate.isEmpty()) { poster = postersToMigrate.pop(); playerUUID = usersUUIDs.get(poster.getUserName()); if (playerUUID == null) { remainingPosters.add(poster); } else if (!poster.isMapValid()) { missingMapIds.addAll(Arrays.asList(ArrayUtils.toObject(poster.getMapsIds()))); } else { MapManager.insertMap(poster.toImageMap(playerUUID)); } } postersToMigrate.addAll(remainingPosters); if (!missingMapIds.isEmpty()) { PluginLogger.warning(I.tn("{0} registered minecraft map is missing from the save.", "{0} registered minecraft maps are missing from the save.", missingMapIds.size())); PluginLogger.warning(I.t( "These maps will not be migrated, but this could mean the save has been altered or corrupted.")); PluginLogger .warning(I.t("The following maps are missing : {0} ", StringUtils.join(missingMapIds, ','))); } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testDescendingIterator() { Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); Iterator<Object> it = deque.descendingIterator(); assertFalse(it.hasNext());//from w ww . j a va 2 s .c o m try { it.next(); fail(); } catch (NoSuchElementException expected) { } deque.add(o1); deque.add(o2); deque.add(o3); it = deque.descendingIterator(); assertTrue(it.hasNext()); assertEquals(o3, it.next()); assertTrue(it.hasNext()); assertEquals(o2, it.next()); assertTrue(it.hasNext()); assertEquals(o1, it.next()); assertFalse(it.hasNext()); try { it.next(); fail(); } catch (NoSuchElementException expected) { } checkDequeSizeAndContent(deque, o1, o2, o3); deque = new ArrayDeque<>(); deque.add(o1); deque.add(o2); deque.add(o3); it = deque.descendingIterator(); assertTrue(it.hasNext()); assertEquals(o3, it.next()); it.remove(); assertEquals(2, deque.size()); assertTrue(it.hasNext()); assertEquals(o2, it.next()); assertTrue(it.hasNext()); assertEquals(o1, it.next()); it.remove(); checkDequeSizeAndContent(deque, o2); }
From source file:com.espertech.esper.core.EPRuntimeImpl.java
private void processMatches(EventBean event) { // get matching filters ArrayBackedCollection<FilterHandle> matches = matchesArrayThreadLocal.get(); long version = services.getFilterService().evaluate(event, matches, engineFilterAndDispatchTimeContext); if (ThreadLogUtil.ENABLED_TRACE) { ThreadLogUtil.trace("Found matches for underlying ", matches.size(), event.getUnderlying()); }/*from w w w .j a v a2 s.c o m*/ if (matches.size() == 0) { if (unmatchedListener != null) { unmatchedListener.update(event); } return; } Map<EPStatementHandle, ArrayDeque<FilterHandleCallback>> stmtCallbacks = matchesPerStmtThreadLocal.get(); Object[] matchArray = matches.getArray(); int entryCount = matches.size(); for (int i = 0; i < entryCount; i++) { EPStatementHandleCallback handleCallback = (EPStatementHandleCallback) matchArray[i]; EPStatementHandle handle = handleCallback.getEpStatementHandle(); // Self-joins require that the internal dispatch happens after all streams are evaluated. // Priority or preemptive settings also require special ordering. if (handle.isCanSelfJoin() || isPrioritized) { ArrayDeque<FilterHandleCallback> callbacks = stmtCallbacks.get(handle); if (callbacks == null) { callbacks = new ArrayDeque<FilterHandleCallback>(); stmtCallbacks.put(handle, callbacks); } callbacks.add(handleCallback.getFilterCallback()); continue; } if ((MetricReportingPath.isMetricsEnabled) && (handle.getMetricsHandle().isEnabled())) { long cpuTimeBefore = MetricUtil.getCPUCurrentThread(); long wallTimeBefore = MetricUtil.getWall(); processStatementFilterSingle(handle, handleCallback, event, version); long wallTimeAfter = MetricUtil.getWall(); long cpuTimeAfter = MetricUtil.getCPUCurrentThread(); long deltaCPU = cpuTimeAfter - cpuTimeBefore; long deltaWall = wallTimeAfter - wallTimeBefore; services.getMetricsReportingService().accountTime(handle.getMetricsHandle(), deltaCPU, deltaWall, 1); } else { if ((ThreadingOption.isThreadingEnabled) && (services.getThreadingService().isRouteThreading())) { services.getThreadingService() .submitRoute(new RouteUnitSingle(this, handleCallback, event, version)); } else { processStatementFilterSingle(handle, handleCallback, event, version); } } } matches.clear(); if (stmtCallbacks.isEmpty()) { return; } for (Map.Entry<EPStatementHandle, ArrayDeque<FilterHandleCallback>> entry : stmtCallbacks.entrySet()) { EPStatementHandle handle = entry.getKey(); ArrayDeque<FilterHandleCallback> callbackList = entry.getValue(); if ((MetricReportingPath.isMetricsEnabled) && (handle.getMetricsHandle().isEnabled())) { long cpuTimeBefore = MetricUtil.getCPUCurrentThread(); long wallTimeBefore = MetricUtil.getWall(); processStatementFilterMultiple(handle, callbackList, event, version); long wallTimeAfter = MetricUtil.getWall(); long cpuTimeAfter = MetricUtil.getCPUCurrentThread(); long deltaCPU = cpuTimeAfter - cpuTimeBefore; long deltaWall = wallTimeAfter - wallTimeBefore; services.getMetricsReportingService().accountTime(handle.getMetricsHandle(), deltaCPU, deltaWall, callbackList.size()); } else { if ((ThreadingOption.isThreadingEnabled) && (services.getThreadingService().isRouteThreading())) { services.getThreadingService() .submitRoute(new RouteUnitMultiple(this, callbackList, event, handle, version)); } else { processStatementFilterMultiple(handle, callbackList, event, version); } if ((isPrioritized) && (handle.isPreemptive())) { break; } } } stmtCallbacks.clear(); }
From source file:com.sonymobile.android.media.internal.VUParser.java
private boolean parseMtdt(BoxHeader header) { boolean parseOK = true; // if mCurrentBoxSequence contains trak, then add metadata to current // track/*from w w w . ja v a 2 s.c o m*/ // else metadata is for file // we're currently not interested in anything on track level try { int numberOfUnits = mDataSource.readShort(); mHmmpTitles = new ArrayList<String>(1); ArrayDeque<String> titleLanguages = new ArrayDeque<String>(1); ArrayDeque<String> iconLanguages = new ArrayDeque<String>(1); for (int i = 0; i < numberOfUnits; i++) { short dataUnitSize = mDataSource.readShort(); int dataTypeID = mDataSource.readInt(); short language = mDataSource.readShort(); char l1 = Character.toChars(((language >> 10) & 0x1F) + 96)[0]; char l2 = Character.toChars(((language >> 5) & 0x1F) + 96)[0]; char l3 = Character.toChars(((language) & 0x1F) + 96)[0]; String languageString = "" + l1 + l2 + l3; short encodingType = mDataSource.readShort(); if (encodingType == 0x01) { byte[] metadata = new byte[dataUnitSize - 10]; mDataSource.read(metadata); String metadataString = new String(metadata, "UTF-16BE").trim(); if ((dataTypeID & 0xFFFF) == 0x01) { mHmmpTitles.add(metadataString); titleLanguages.add(languageString); } } else if (encodingType == 0x101) { if (dataTypeID == 0xA04) { if (mIconList == null) { mIconList = new ArrayList<IconInfo>(); } mDataSource.skipBytes(4); // selectionFlags mDataSource.skipBytes(4); // reserved int artworkCount = mDataSource.readInt(); for (int j = 0; j < artworkCount; j++) { IconInfo iconInfo = new IconInfo(); iconInfo.mtsmId = mDataSource.readInt(); iconInfo.mdstIndex = mDataSource.readInt(); iconInfo.languageIndex = iconLanguages.size(); mDataSource.skipBytes(4); mIconList.add(iconInfo); } iconLanguages.add(languageString); } } } addMetaDataValue(KEY_HMMP_TITLE_LANGUAGES, titleLanguages.toArray()); addMetaDataValue(KEY_HMMP_ICON_LANGUAGES, iconLanguages.toArray()); } catch (EOFException e) { if (LOGS_ENABLED) Log.e(TAG, "Exception while reading from 'MTDT' box", e); return false; } catch (IOException e) { if (LOGS_ENABLED) Log.e(TAG, "Exception while reading from 'MTDT' box", e); return false; } return parseOK; }
From source file:com.vgi.mafscaling.VECalc.java
protected void loadLogFile() { fileChooser.setMultiSelectionEnabled(true); if (JFileChooser.APPROVE_OPTION != fileChooser.showOpenDialog(this)) return;/*from w ww.j av a2 s.c om*/ 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;/*ww w.ja v a 2s .c om*/ 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); } } } } }