List of usage examples for java.util ArrayDeque ArrayDeque
public ArrayDeque()
From source file:eu.stratosphere.runtime.io.channels.InputChannel.java
@Override public void destroy() { final Queue<Buffer> buffersToRecycle = new ArrayDeque<Buffer>(); synchronized (this.queuedEnvelopes) { this.destroyCalled = true; while (!this.queuedEnvelopes.isEmpty()) { final Envelope envelope = this.queuedEnvelopes.poll(); if (envelope.getBuffer() != null) { buffersToRecycle.add(envelope.getBuffer()); }//from ww w. ja va2s. com } } while (!buffersToRecycle.isEmpty()) { buffersToRecycle.poll().recycleBuffer(); } }
From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java
public void testOfferLast() { Object o1 = new Object(); Object o2 = new Object(); Object o3 = new Object(); ArrayDeque<Object> deque = new ArrayDeque<>(); assertTrue(deque.offerLast(o1));/*w w w. j a va2 s. c o m*/ checkDequeSizeAndContent(deque, o1); assertTrue(deque.offerLast(o2)); checkDequeSizeAndContent(deque, o1, o2); assertTrue(deque.offerLast(o3)); checkDequeSizeAndContent(deque, o1, o2, o3); try { deque.offerLast(null); fail(); } catch (NullPointerException expected) { } }
From source file:com.espertech.esper.event.vaevent.VAERevisionProcessorMerge.java
public Collection<EventBean> getSnapshot(EPStatementAgentInstanceHandle createWindowStmtHandle, Viewable parent) {/*from w ww . j a v a 2s .c om*/ createWindowStmtHandle.getStatementAgentInstanceLock().acquireReadLock(); try { Iterator<EventBean> it = parent.iterator(); if (!it.hasNext()) { return Collections.EMPTY_LIST; } ArrayDeque<EventBean> list = new ArrayDeque<EventBean>(); while (it.hasNext()) { RevisionEventBeanMerge fullRevision = (RevisionEventBeanMerge) it.next(); Object key = fullRevision.getKey(); RevisionStateMerge state = statePerKey.get(key); list.add(state.getLastEvent()); } return list; } finally { createWindowStmtHandle.getStatementAgentInstanceLock().releaseReadLock(); } }
From source file:bwem.map.MapImpl.java
public TilePosition breadthFirstSearch(TilePosition start, Pred findCond, Pred visitCond, boolean connect8) { if (findCond.isTrue(getData().getTile(start), start, this)) { return start; }/*from w w w . ja v a2s.co m*/ final Set<TilePosition> visited = new TreeSet<>((a, b) -> { int result = Integer.compare(a.getX(), b.getX()); if (result != 0) { return result; } return Integer.compare(a.getY(), b.getY()); }); Queue<TilePosition> toVisit = new ArrayDeque<>(); toVisit.add(start); visited.add(start); TilePosition[] dir8 = { new TilePosition(-1, -1), new TilePosition(0, -1), new TilePosition(1, -1), new TilePosition(-1, 0), new TilePosition(1, 0), new TilePosition(-1, 1), new TilePosition(0, 1), new TilePosition(1, 1) }; TilePosition[] dir4 = { new TilePosition(0, -1), new TilePosition(-1, 0), new TilePosition(+1, 0), new TilePosition(0, +1) }; TilePosition[] directions = connect8 ? dir8 : dir4; while (!toVisit.isEmpty()) { TilePosition current = toVisit.remove(); for (TilePosition delta : directions) { TilePosition next = current.add(delta); if (getData().getMapData().isValid(next)) { Tile nextTile = getData().getTile(next, CheckMode.NO_CHECK); if (findCond.isTrue(nextTile, next, this)) { return next; } if (visitCond.isTrue(nextTile, next, this) && !visited.contains(next)) { toVisit.add(next); visited.add(next); } } } } //TODO: Are we supposed to return start or not? // bwem_assert(false); throw new IllegalStateException(); // return start; }
From source file:org.apache.hadoop.hbase.tool.LoadIncrementalHFiles.java
/** * Perform a bulk load of the given directory into the given pre-existing table. This method is * not threadsafe./*from w ww . java 2 s . c om*/ * @param map map of family to List of hfiles * @param admin the Admin * @param table the table to load into * @param regionLocator region locator * @param silence true to ignore unmatched column families * @param copyFile always copy hfiles if true * @throws TableNotFoundException if table does not yet exist */ public Map<LoadQueueItem, ByteBuffer> doBulkLoad(Map<byte[], List<Path>> map, final Admin admin, Table table, RegionLocator regionLocator, boolean silence, boolean copyFile) throws TableNotFoundException, IOException { if (!admin.isTableAvailable(regionLocator.getName())) { throw new TableNotFoundException("Table " + table.getName() + " is not currently available."); } // LQI queue does not need to be threadsafe -- all operations on this queue // happen in this thread Deque<LoadQueueItem> queue = new ArrayDeque<>(); ExecutorService pool = null; SecureBulkLoadClient secureClient = null; try { prepareHFileQueue(map, table, queue, silence); if (queue.isEmpty()) { LOG.warn("Bulk load operation did not get any files to load"); return Collections.emptyMap(); } pool = createExecutorService(); secureClient = new SecureBulkLoadClient(table.getConfiguration(), table); return performBulkLoad(admin, table, regionLocator, queue, pool, secureClient, copyFile); } finally { cleanup(admin, queue, pool, secureClient); } }
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); }// w ww. j a va2s . co 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; }
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 www .java 2s . c o 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.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck.java
/** * Checks to see if there are any unclosed tags on the stack. The token * represents a html tag that has been closed and has a corresponding open * tag on the stack. Any tags, except single tags, that were opened * (pushed on the stack) after the token are missing a close. * * @param htmlStack the stack of opened HTML tags. * @param token the current HTML tag name that has been closed. *//*from w w w . j av a2s.com*/ private void checkUnclosedTags(Deque<HtmlTag> htmlStack, String token) { final Deque<HtmlTag> unclosedTags = new ArrayDeque<>(); HtmlTag lastOpenTag = htmlStack.pop(); while (!token.equalsIgnoreCase(lastOpenTag.getId())) { // Find unclosed elements. Put them on a stack so the // output order won't be back-to-front. if (isSingleTag(lastOpenTag)) { lastOpenTag = htmlStack.pop(); } else { unclosedTags.push(lastOpenTag); lastOpenTag = htmlStack.pop(); } } // Output the unterminated tags, if any // Skip multiples, like <b>..<b> String lastFound = ""; for (final HtmlTag htag : unclosedTags) { lastOpenTag = htag; if (lastOpenTag.getId().equals(lastFound)) { continue; } lastFound = lastOpenTag.getId(); log(lastOpenTag.getLineNo(), lastOpenTag.getPosition(), UNCLOSED_HTML, lastOpenTag); } }
From source file:com.espertech.esper.core.start.EPPreparedExecuteMethod.java
private Collection<EventBean> getStreamFilterSnapshot(int streamNum, ContextPartitionSelector contextPartitionSelector) { final StreamSpecCompiled streamSpec = statementSpec.getStreamSpecs().get(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); }//ww w . j a va 2 s. c om // context partition runtime query Collection<Integer> contextPartitions; if (contextPartitionSelector == null || contextPartitionSelector instanceof ContextPartitionSelectorAll) { contextPartitions = namedWindowProcessor.getProcessorInstancesAll(); } else { ContextManager contextManager = services.getContextManagementService() .getContextManager(namedWindowProcessor.getContextName()); contextPartitions = contextManager.getAgentInstanceIds(contextPartitionSelector); } // 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; }
From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java
private void handleChanges(State startingState, List<TreeNode> changes) { ArrayDeque<State> check = new ArrayDeque<>(); check.add(startingState);/*ww w . ja va 2 s . co m*/ while (!check.isEmpty()) { State next = check.pop(); TreeNode match = Utils.find(next.needle, next.haystack); if (match != null) { for (TreeNode current : next.needle.getChildren()) { check.add(new State(current, match.getChildren())); } } else { changes.add(next.needle); } } }