List of usage examples for java.util ArrayDeque addAll
public boolean addAll(Collection<? extends E> c)
From source file:com.facebook.litho.dataflow.DataFlowGraph.java
private void regenerateSortedNodes() { mSortedNodes.clear();/*from w w w.java 2 s . com*/ if (mBindings.size() == 0) { return; } final ArraySet<ValueNode> leafNodes = ComponentsPools.acquireArraySet(); final SimpleArrayMap<ValueNode, Integer> nodesToOutputsLeft = new SimpleArrayMap<>(); for (int i = 0, bindingsSize = mBindingToNodes.size(); i < bindingsSize; i++) { final ArraySet<ValueNode> nodes = mBindingToNodes.valueAt(i); for (int j = 0, nodesSize = nodes.size(); j < nodesSize; j++) { final ValueNode node = nodes.valueAt(j); final int outputCount = node.getOutputCount(); if (outputCount == 0) { leafNodes.add(node); } else { nodesToOutputsLeft.put(node, outputCount); } } } if (!nodesToOutputsLeft.isEmpty() && leafNodes.isEmpty()) { throw new DetectedCycleException("Graph has nodes, but they represent a cycle with no leaf nodes!"); } final ArrayDeque<ValueNode> nodesToProcess = ComponentsPools.acquireArrayDeque(); nodesToProcess.addAll(leafNodes); while (!nodesToProcess.isEmpty()) { final ValueNode next = nodesToProcess.pollFirst(); mSortedNodes.add(next); for (int i = 0, count = next.getInputCount(); i < count; i++) { final ValueNode input = next.getInputAt(i); final int outputsLeft = nodesToOutputsLeft.get(input) - 1; nodesToOutputsLeft.put(input, outputsLeft); if (outputsLeft == 0) { nodesToProcess.addLast(input); } else if (outputsLeft < 0) { throw new DetectedCycleException("Detected cycle."); } } } int expectedTotalNodes = nodesToOutputsLeft.size() + leafNodes.size(); if (mSortedNodes.size() != expectedTotalNodes) { throw new DetectedCycleException( "Had unreachable nodes in graph -- this likely means there was a cycle"); } Collections.reverse(mSortedNodes); mIsDirty = false; ComponentsPools.release(nodesToProcess); ComponentsPools.release(leafNodes); }
From source file:org.carrot2.source.microsoft.v5.Bing5NewsDocumentSource.java
@Override protected void handleResponse(BingResponse response, SearchEngineResponse ser) { NewsResponse newsResponse = (NewsResponse) response; ser.metadata.put(SearchEngineResponse.RESULTS_TOTAL_KEY, newsResponse.totalEstimatedMatches); if (newsResponse.value != null) { ArrayDeque<NewsResponse.NewsArticle> articles = new ArrayDeque<>(newsResponse.value); while (!articles.isEmpty()) { NewsResponse.NewsArticle r = articles.removeFirst(); if (r.clusteredArticles != null) { articles.addAll(r.clusteredArticles); }/*from ww w .j a v a 2 s . c o m*/ Document doc = new Document(r.name, r.description, r.url); if (r.image != null && r.image.thumbnail != null) { doc.setField(Document.THUMBNAIL_URL, r.image.thumbnail.contentUrl); } if (r.provider != null) { ArrayList<String> sources = new ArrayList<>(); for (NewsResponse.NewsArticle.Organization o : r.provider) { sources.add(o.name); } doc.setField(Document.SOURCES, sources); } ser.results.add(doc); } } }
From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java
public void updateTree(List<TreeNode> add, List<TreeNode> remove) { Set<TreeItem<TreeNode>> updated = new HashSet<>(); ArrayDeque<TreeNode> queue = new ArrayDeque<>(); queue.addAll(add); while (!queue.isEmpty()) { TreeNode thisNode = queue.pop(); TreeItem<TreeNode> parent; if (thisNode.getParent() == null) { parent = rootItem;/*from w ww . java 2 s . co m*/ } else { parent = itemMap.get(thisNode.getParent()); } updated.add(parent); TreeItem<TreeNode> thisItem = new TreeItem<>(thisNode); thisItem.addEventHandler(TreeItem.<TreeNode>branchExpandedEvent(), event -> { if (thisItem.getChildren().size() == 1) { thisItem.getChildren().get(0).setExpanded(true); } }); thisItem.setGraphic(new ImageView(new Image(getIconForTreeItem(thisNode)))); FutureTask<Void> call = new FutureTask<>(() -> { parent.getChildren().add(thisItem); return null; }); Platform.runLater(call); try { call.get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } itemMap.put(thisNode, thisItem); queue.addAll(thisNode.getChildren()); } for (TreeItem<TreeNode> parent : updated) { if (parent.getChildren().size() > 1) { FutureTask<Void> call = new FutureTask<>(() -> { parent.getChildren().sort((a, b) -> { int ac = a.getValue().getChildren().size(); int bc = b.getValue().getChildren().size(); if (ac == 0 && bc != 0) return 1; else if (ac != 0 && bc == 0) return -1; return a.getValue().getDisplayName().compareTo(b.getValue().getDisplayName()); }); return null; }); Platform.runLater(call); try { call.get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } } } queue.addAll(remove); while (!queue.isEmpty()) { TreeNode thisNode = queue.pop(); TreeItem<TreeNode> thisItem = itemMap.remove(thisNode); thisItem.getParent().getChildren().remove(thisItem); queue.addAll(thisNode.getChildren()); } }
From source file:org.apache.hadoop.hbase.thrift.TestMutationWriteToWAL.java
@Test public void testMutationWriteToWAL() throws Exception { HBaseTestingUtility.setThreadNameFromMethod(); final Configuration conf = TEST_UTIL.getConfiguration(); FileSystem fs = FileSystem.get(conf); List<String> expectedLogEntries = new ArrayList<String>(); try {/*from w w w .j a va2 s. c o m*/ Hbase.Client client = createClient(); client.createTable(HTestConst.DEFAULT_TABLE_BYTE_BUF, HTestConst.DEFAULT_COLUMN_DESC_LIST); int expectedEntriesForRow[] = new int[NUM_ROWS]; for (int i = NUM_ROWS - 1; i >= 0; --i) { final String row = getRow(i); List<Mutation> mutations = new ArrayList<Mutation>(); // writeToWAL cannot depend on column, only on the row boolean writeToWAL = i % 3 == 0; for (int j = 0; j < NUM_COLS_PER_ROW; ++j) { final String qual = getCol(j); boolean isDelete = shouldDelete(i, j); if (!isDelete) { expectedEntriesForRow[i]++; } final String value = isDelete ? "" : getValue(i, j); Mutation m = new Mutation(false, ByteBuffer.wrap(Bytes.toBytes(HTestConst.DEFAULT_CF_STR + ":" + qual)), ByteBuffer.wrap(Bytes.toBytes(value)), writeToWAL, HConstants.LATEST_TIMESTAMP); m.isDelete = isDelete; mutations.add(m); if (writeToWAL) { expectedLogEntries.add(row + "," + qual + "," + value + "," + m.isDelete); } } final ByteBuffer rowBuf = ByteBuffer.wrap(Bytes.toBytes(row)); // Exercise both APIs. if (i % 2 == 0) { client.mutateRow(HTestConst.DEFAULT_TABLE_BYTE_BUF, rowBuf, mutations, null, null); } else { List<BatchMutation> rowBatches = new ArrayList<BatchMutation>(); BatchMutation bm = new BatchMutation(rowBuf, mutations); rowBatches.add(bm); client.mutateRows(HTestConst.DEFAULT_TABLE_BYTE_BUF, rowBatches, null, null); } } client.disableTable(HTestConst.DEFAULT_TABLE_BYTE_BUF); client.enableTable(HTestConst.DEFAULT_TABLE_BYTE_BUF); // Check that all the data is there for (int i = 0; i < NUM_ROWS; ++i) { final String row = getRow(i); List<TRowResult> results = client.getRow(HTestConst.DEFAULT_TABLE_BYTE_BUF, ByteBuffer.wrap(Bytes.toBytes(row)), null); TRowResult result = results.get(0); assertEquals("No results found for row " + row, expectedEntriesForRow[i], result.getColumnsSize()); Map<ByteBuffer, TCell> sortedColumns = new TreeMap<ByteBuffer, TCell>(result.getColumns()); int j = -1; for (Map.Entry<ByteBuffer, TCell> entry : sortedColumns.entrySet()) { ++j; while (shouldDelete(i, j)) { ++j; } assertEquals(HTestConst.DEFAULT_CF_STR + ":" + getCol(j), Bytes.toStringBinaryRemaining(entry.getKey())); assertEquals(getValue(i, j), Bytes.toStringBinary(entry.getValue().getValue())); } } } finally { closeClientSockets(); } TEST_UTIL.shutdownMiniHBaseCluster(); final Path baseDir = new Path(conf.get(HConstants.HBASE_DIR)); final Path oldLogDir = new Path(baseDir, HConstants.HREGION_OLDLOGDIR_NAME); int nLogFilesRead = 0; List<String> actualLogEntries = new ArrayList<String>(); ArrayDeque<FileStatus> checkQueue = new ArrayDeque<FileStatus>( java.util.Arrays.asList(fs.listStatus(oldLogDir))); while (!checkQueue.isEmpty()) { FileStatus logFile = checkQueue.pop(); if (logFile.isDir()) { checkQueue.addAll(java.util.Arrays.asList(fs.listStatus(logFile.getPath()))); continue; } HLog.Reader r = HLog.getReader(fs, logFile.getPath(), conf); LOG.info("Reading HLog: " + logFile.getPath()); HLog.Entry entry = null; while ((entry = r.next(entry)) != null) { if (!Bytes.equals(entry.getKey().getTablename(), HTestConst.DEFAULT_TABLE_BYTES)) { continue; } for (KeyValue kv : entry.getEdit().getKeyValues()) { if (Bytes.equals(kv.getRow(), HLog.METAROW)) { continue; } actualLogEntries.add(Bytes.toStringBinary(kv.getRow()) + "," + Bytes.toStringBinary(kv.getQualifier()) + "," + Bytes.toStringBinary(kv.getValue()) + "," + (kv.getType() == KeyValue.Type.DeleteColumn.getCode())); } } r.close(); ++nLogFilesRead; } assertTrue(nLogFilesRead > 0); Collections.sort(expectedLogEntries); Collections.sort(actualLogEntries); LOG.info("Expected log entries: " + expectedLogEntries.size() + ", actual log entries: " + actualLogEntries.size()); assertEquals(expectedLogEntries.toString(), actualLogEntries.toString()); }
From source file:com.espertech.esper.epl.join.table.PropertySortedEventTable.java
private Collection<EventBean> normalizeCollection(SortedMap<Object, Set<EventBean>> submapOne, SortedMap<Object, Set<EventBean>> submapTwo) { if (submapOne.size() == 0) { return normalizeCollection(submapTwo); }/*www .j a va2s .c o m*/ if (submapTwo.size() == 0) { return normalizeCollection(submapOne); } ArrayDeque<EventBean> result = new ArrayDeque<EventBean>(); for (Map.Entry<Object, Set<EventBean>> entry : submapOne.entrySet()) { result.addAll(entry.getValue()); } for (Map.Entry<Object, Set<EventBean>> entry : submapTwo.entrySet()) { result.addAll(entry.getValue()); } return result; }
From source file:com.espertech.esper.core.start.EPPreparedExecuteSingleStream.java
/** * Executes the prepared query.// ww w . j a va 2 s .c om * @return query results */ public EPPreparedQueryResult execute(ContextPartitionSelector[] contextPartitionSelectors) { if (contextPartitionSelectors != null && contextPartitionSelectors.length != 1) { throw new IllegalArgumentException("Number of context partition selectors must be one"); } ContextPartitionSelector optionalSingleSelector = contextPartitionSelectors != null && contextPartitionSelectors.length > 0 ? contextPartitionSelectors[0] : null; // validate context if (processor.getContextName() != null && statementSpec.getOptionalContextName() != null && !processor.getContextName().equals(statementSpec.getOptionalContextName())) { throw new EPException("Context for named window is '" + processor.getContextName() + "' and query specifies context '" + statementSpec.getOptionalContextName() + "'"); } // handle non-specified context if (statementSpec.getOptionalContextName() == null) { NamedWindowProcessorInstance processorInstance = processor.getProcessorInstanceNoContext(); if (processorInstance != null) { EventBean[] rows = executor.execute(processorInstance); if (rows.length > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getNamedWindowType(), rows); } } // context partition runtime query Collection<Integer> agentInstanceIds = EPPreparedExecuteMethodHelper.getAgentInstanceIds(processor, optionalSingleSelector, services.getContextManagementService(), processor.getContextName()); // collect events and agent instances if (agentInstanceIds.isEmpty()) { return new EPPreparedQueryResult(processor.getNamedWindowType(), CollectionUtil.EVENT_PER_STREAM_EMPTY); } if (agentInstanceIds.size() == 1) { int agentInstanceId = agentInstanceIds.iterator().next(); NamedWindowProcessorInstance processorInstance = processor.getProcessorInstance(agentInstanceId); EventBean[] rows = executor.execute(processorInstance); if (rows.length > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getNamedWindowType(), rows); } ArrayDeque<EventBean> allRows = new ArrayDeque<EventBean>(); for (int agentInstanceId : agentInstanceIds) { NamedWindowProcessorInstance processorInstance = processor.getProcessorInstance(agentInstanceId); if (processorInstance != null) { EventBean[] rows = executor.execute(processorInstance); allRows.addAll(Arrays.asList(rows)); } } if (allRows.size() > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getNamedWindowType(), allRows.toArray(new EventBean[allRows.size()])); }
From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java
@FXML public void initialize() { this.rootItem = new TreeItem<>(new TreeNode("[root]")); this.root.setRoot(this.rootItem); this.root.setCellFactory(new TreeCellFactory<>(node -> { if (node.getParent() == null) { ContextMenu export = new ContextMenu(); MenuItem exportItem = new MenuItem("Export"); export.setOnAction(e -> { File file = messageHandler.chooseFile().withInitialDirectory(new File(".")) .withTitle(Message.GENERIC_CHOOSE_EXPORT_LOCATION_JAR.format()) .withExtensionFilter(new FileFilter(Message.FILETYPE_JAVA_ARCHIVE.format(), "*.jar"), true)/*from w w w. j av a2 s . c o m*/ .promptSave(); OpenedFile openedFile = (OpenedFile) node.getMetadata().get(OpenedFile.OPENED_FILE); Map<String, byte[]> clone = new HashMap<>(openedFile.getContents()); backgroundTaskHelper.submit( new BackgroundTask(Message.TASK_SAVING_FILE.format(node.getDisplayName()), true, () -> { try { if (!file.exists()) { if (!file.createNewFile()) { throw new IOException("Could not create export file"); } } try (ZipOutputStream zipOutputStream = new ZipOutputStream( new FileOutputStream(file))) { for (Map.Entry<String, byte[]> ent : clone.entrySet()) { ZipEntry zipEntry = new ZipEntry(ent.getKey()); zipOutputStream.putNextEntry(zipEntry); zipOutputStream.write(ent.getValue()); zipOutputStream.closeEntry(); } } messageHandler.handleMessage(Message.GENERIC_EXPORTED.format()); } catch (IOException ex) { messageHandler.handleException(Message.ERROR_IOEXCEPTION_OCCURRED.format(), ex); } })); }); export.getItems().add(exportItem); return export; } return null; })); root.addEventHandler(KeyEvent.KEY_RELEASED, event -> { if (event.getCode() == KeyCode.ENTER) { TreeItem<TreeNode> selected = this.root.getSelectionModel().getSelectedItem(); if (selected != null) { if (selected.getChildren().size() != 0) { selected.setExpanded(!selected.isExpanded()); } else { getParentController().getAllFilesViewerController().handleClick(selected.getValue()); } } } }); Tooltip tooltip = new Tooltip(); StringBuilder search = new StringBuilder(); List<TreeItem<TreeNode>> searchContext = new ArrayList<>(); AtomicInteger searchIndex = new AtomicInteger(); root.focusedProperty().addListener((observable, oldValue, newValue) -> { if (!newValue) { tooltip.hide(); search.setLength(0); } }); root.boundsInLocalProperty().addListener((observable, oldValue, newValue) -> { Bounds bounds = root.localToScreen(newValue); tooltip.setAnchorX(bounds.getMinX()); tooltip.setAnchorY(bounds.getMinY()); }); root.addEventHandler(KeyEvent.KEY_PRESSED, event -> { if (tooltip.isShowing() && event.getCode() == KeyCode.UP) { if (searchIndex.decrementAndGet() < 0) { searchIndex.set(searchContext.size() - 1); } } else if (tooltip.isShowing() && event.getCode() == KeyCode.DOWN) { if (searchIndex.incrementAndGet() >= searchContext.size()) { searchIndex.set(0); } } else { return; } event.consume(); root.scrollTo(root.getRow(searchContext.get(searchIndex.get()))); root.getSelectionModel().select(searchContext.get(searchIndex.get())); }); root.addEventHandler(KeyEvent.KEY_TYPED, event -> { if (event.getCharacter().charAt(0) == '\b') { if (search.length() > 0) { search.setLength(search.length() - 1); } } else if (event.getCharacter().charAt(0) == '\u001B') { //esc tooltip.hide(); search.setLength(0); return; } else if (search.length() > 0 || (search.length() == 0 && StringUtils.isAlphanumeric(event.getCharacter()))) { search.append(event.getCharacter()); if (!tooltip.isShowing()) { tooltip.show(root.getScene().getWindow()); } } if (!tooltip.isShowing()) return; String str = search.toString(); tooltip.setText("Search for: " + str); searchContext.clear(); ArrayDeque<TreeItem<TreeNode>> deque = new ArrayDeque<>(); deque.addAll(rootItem.getChildren()); while (!deque.isEmpty()) { TreeItem<TreeNode> item = deque.poll(); if (item.getValue().getDisplayName().contains(str)) { searchContext.add(item); } if (item.isExpanded() && item.getChildren().size() > 0) deque.addAll(item.getChildren()); } searchIndex.set(0); if (searchContext.size() > 0) { root.scrollTo(root.getRow(searchContext.get(0))); root.getSelectionModel().select(searchContext.get(0)); } }); openedFileController.loadedFiles().addListener((MapChangeListener<String, OpenedFile>) change -> { if (change.getValueAdded() != null) { updateTree(change.getValueAdded()); } if (change.getValueRemoved() != null) { this.rootItem.getChildren() .removeIf(ti -> ti.getValue().equals(change.getValueRemoved().getRoot())); } }); }
From source file:com.espertech.esper.core.start.EPPreparedExecuteIUDSingleStream.java
/** * Executes the prepared query./*from w w w .java 2s . co m*/ * @return query results */ public EPPreparedQueryResult execute(ContextPartitionSelector[] contextPartitionSelectors) { try { if (contextPartitionSelectors != null && contextPartitionSelectors.length != 1) { throw new IllegalArgumentException("Number of context partition selectors must be one"); } ContextPartitionSelector optionalSingleSelector = contextPartitionSelectors != null && contextPartitionSelectors.length > 0 ? contextPartitionSelectors[0] : null; // validate context if (processor.getContextName() != null && statementSpec.getOptionalContextName() != null && !processor.getContextName().equals(statementSpec.getOptionalContextName())) { throw new EPException("Context for named window is '" + processor.getContextName() + "' and query specifies context '" + statementSpec.getOptionalContextName() + "'"); } // handle non-specified context if (statementSpec.getOptionalContextName() == null) { FireAndForgetInstance processorInstance = processor.getProcessorInstanceNoContext(); if (processorInstance != null) { EventBean[] rows = executor.execute(processorInstance); if (rows != null && rows.length > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getEventTypePublic(), rows); } } // context partition runtime query Collection<Integer> agentInstanceIds = EPPreparedExecuteMethodHelper.getAgentInstanceIds(processor, optionalSingleSelector, services.getContextManagementService(), processor.getContextName()); // collect events and agent instances if (agentInstanceIds.isEmpty()) { return new EPPreparedQueryResult(processor.getEventTypeResultSetProcessor(), CollectionUtil.EVENTBEANARRAY_EMPTY); } if (agentInstanceIds.size() == 1) { int agentInstanceId = agentInstanceIds.iterator().next(); FireAndForgetInstance processorInstance = processor .getProcessorInstanceContextById(agentInstanceId); EventBean[] rows = executor.execute(processorInstance); if (rows.length > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getEventTypeResultSetProcessor(), rows); } ArrayDeque<EventBean> allRows = new ArrayDeque<EventBean>(); for (int agentInstanceId : agentInstanceIds) { FireAndForgetInstance processorInstance = processor .getProcessorInstanceContextById(agentInstanceId); if (processorInstance != null) { EventBean[] rows = executor.execute(processorInstance); allRows.addAll(Arrays.asList(rows)); } } if (allRows.size() > 0) { dispatch(); } return new EPPreparedQueryResult(processor.getEventTypeResultSetProcessor(), allRows.toArray(new EventBean[allRows.size()])); } finally { if (hasTableAccess) { services.getTableService().getTableExprEvaluatorContext().releaseAcquiredLocks(); } } }
From source file:com.britesnow.snow.web.RequestContext.java
public void setFramePaths(String[] framePaths) { if (framePaths != null) { ArrayDeque<String> stack = new ArrayDeque<String>(); stack.addAll(Arrays.asList(framePaths)); framePathsStack = stack;// w ww . j a va 2s. c o m } }
From source file:com.espertech.esper.core.start.EPPreparedExecuteMethodQuery.java
private Collection<EventBean> getStreamFilterSnapshot(int streamNum, ContextPartitionSelector contextPartitionSelector) { final StreamSpecCompiled streamSpec = statementSpec.getStreamSpecs()[streamNum]; NamedWindowConsumerStreamSpec namedSpec = (NamedWindowConsumerStreamSpec) streamSpec; NamedWindowProcessor namedWindowProcessor = processors[streamNum]; // handle the case of a single or matching agent instance NamedWindowProcessorInstance processorInstance = namedWindowProcessor .getProcessorInstance(agentInstanceContext); if (processorInstance != null) { return getStreamSnapshotInstance(streamNum, namedSpec, processorInstance); }/*from w w w. ja v a 2 s . c o m*/ // context partition runtime query Collection<Integer> contextPartitions = EPPreparedExecuteMethodHelper.getAgentInstanceIds( namedWindowProcessor, contextPartitionSelector, services.getContextManagementService(), namedWindowProcessor.getContextName()); // collect events ArrayDeque<EventBean> events = new ArrayDeque<EventBean>(); for (int agentInstanceId : contextPartitions) { processorInstance = namedWindowProcessor.getProcessorInstance(agentInstanceId); if (processorInstance != null) { Collection<EventBean> coll = processorInstance.getTailViewInstance().snapshot(filters[streamNum], statementSpec.getAnnotations()); events.addAll(coll); } } return events; }