List of usage examples for java.util ArrayDeque ArrayDeque
public ArrayDeque()
From source file:com.grepcurl.random.ObjectGenerator.java
public <T> T generate(Class<T> klass, SetterOverrides setterOverrides, Object... constructorArgs) { return generate(klass, setterOverrides, new ArrayDeque<>(), constructorArgs); }
From source file:info.guardianproject.iocipher.camera.VideoCameraActivity.java
private void startRecording() { mFrameQ = new ArrayDeque<VideoFrame>(); mFramesTotal = 0;//from www.j a v a 2 s . co m mFpsCounter = 0; lastTime = System.currentTimeMillis(); String fileName = "secure_video_" + new java.util.Date().getTime() + ".mp4"; fileOut = new info.guardianproject.iocipher.File(mFileBasePath, fileName); mResultList.add(fileOut.getAbsolutePath()); Intent intentResult = new Intent().putExtra(MediaStore.EXTRA_OUTPUT, mResultList.toArray(new String[mResultList.size()])); setResult(Activity.RESULT_OK, intentResult); try { mIsRecording = true; if (useAAC) initAudio(fileOut.getAbsolutePath() + ".aac"); else initAudio(fileOut.getAbsolutePath() + ".pcm"); boolean withEmbeddedAudio = true; Encoder encoder = new Encoder(fileOut, mFPS, withEmbeddedAudio); encoder.start(); //start capture startAudioRecording(); progress.setText(R.string._rec_); } catch (Exception e) { Log.d("Video", "error starting video", e); Toast.makeText(this, "Error init'ing video: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); finish(); } }
From source file:edu.umn.cs.spatialHadoop.nasa.StockQuadTree.java
/** * Constructs a stock quad tree for the given resolution * @param resolution/*from ww w . java 2 s .c o m*/ */ StockQuadTree(int resolution) { this.resolution = resolution; this.r = new int[resolution * resolution]; final int[] z = new int[resolution * resolution]; // The list of all nodes Vector<Node> nodes = new Vector<Node>(); // Compute the Z-order of all values for (int i = 0; i < z.length; i++) { short x = (short) (i % resolution); short y = (short) (i / resolution); int zorder = AggregateQuadTree.computeZOrder(x, y); z[i] = zorder; r[i] = i; } // Sort ArrayToZOrder1200 by Z-Order and keep the original position of // each element by mirroring all swaps to ZOrderToArray1200 new QuickSort().sort(new IndexedSortable() { @Override public void swap(int i, int j) { int temp; // Swap z-values (which are to be sorted) temp = z[i]; z[i] = z[j]; z[j] = temp; // Swap their relative positions in the other array temp = r[i]; r[i] = r[j]; r[j] = temp; } @Override public int compare(int i, int j) { return z[i] - z[j]; } }, 0, z.length); // Construct the structure of the quad tree based on Z-values // Maximum number of values per node. Set it to a very small number to // construct as many levels as possible. Notice that when quad trees // are aggregated, a single value might become 366 values in the same pos. final int capacity = 100; Node root = new Node(); root.startPosition = 0; root.endPosition = z.length; root.id = 1; Queue<Node> nodesToCheckForSplit = new ArrayDeque<Node>(); nodesToCheckForSplit.add(root); int numOfSignificantBitsInTree = getNumOfSignificantBits(resolution * resolution - 1); if ((numOfSignificantBitsInTree & 1) == 1) numOfSignificantBitsInTree++; // Round to next even value int maxId = 0; while (!nodesToCheckForSplit.isEmpty()) { Node nodeToCheckForSplit = nodesToCheckForSplit.poll(); boolean needsToSplit = nodeToCheckForSplit.getNumOfElements() > capacity; if (nodeToCheckForSplit.id > maxId) maxId = nodeToCheckForSplit.id; nodes.add(nodeToCheckForSplit); if (needsToSplit) { // Need to split // Determine split points based on the Z-order values of the first and // last elements in this node int depth = nodeToCheckForSplit.id == 0 ? 0 : (getNumOfSignificantBits(nodeToCheckForSplit.id - 1) / 2 + 1); depth = (getNumOfSignificantBits(nodeToCheckForSplit.id) - 1) / 2; int numOfSignificantBitsInNode = numOfSignificantBitsInTree - depth * 2; // Create four child nodes under this node int zOrderCommonBits = z[nodeToCheckForSplit.startPosition] & (0xffffffff << numOfSignificantBitsInNode); int childStartPosition = nodeToCheckForSplit.startPosition; for (int iChild = 0; iChild < 4; iChild++) { int zOrderUpperBound = zOrderCommonBits + ((iChild + 1) << (numOfSignificantBitsInNode - 2)); int childEndPosition = Arrays.binarySearch(z, childStartPosition, nodeToCheckForSplit.endPosition, zOrderUpperBound); if (childEndPosition < 0) childEndPosition = -(childEndPosition + 1); Node child = new Node(); child.startPosition = childStartPosition; child.endPosition = childEndPosition; child.id = nodeToCheckForSplit.id * 4 + iChild; nodesToCheckForSplit.add(child); // Prepare for next iteration childStartPosition = childEndPosition; } if (childStartPosition != nodeToCheckForSplit.endPosition) throw new RuntimeException(); } } // Convert nodes to column format for memory efficiency nodesID = new int[nodes.size()]; nodesStartPosition = new int[nodes.size()]; nodesEndPosition = new int[nodes.size()]; for (int i = 0; i < nodes.size(); i++) { Node node = nodes.get(i); nodesID[i] = node.id; nodesStartPosition[i] = node.startPosition; nodesEndPosition[i] = node.endPosition; } }
From source file:com.mgmtp.jfunk.core.config.JFunkBaseModule.java
@Provides
@ScriptScoped
Deque<ReportContext> provideReportContextStack() {
return new ArrayDeque<>();
}
From source file:org.springframework.xd.dirt.stream.zookeeper.ZooKeeperStreamRepository.java
@Override public void delete(String id) { logger.info("Undeploying stream {}", id); String streamDeploymentPath = Paths.build(Paths.STREAM_DEPLOYMENTS, id); String streamModuleDeploymentPath = Paths.build(streamDeploymentPath, Paths.MODULES); CuratorFramework client = zkConnection.getClient(); Deque<String> paths = new ArrayDeque<String>(); try {//from w w w .jav a2s .c o m client.setData().forPath(Paths.build(Paths.STREAM_DEPLOYMENTS, id, Paths.STATUS), ZooKeeperUtils .mapToBytes(new DeploymentUnitStatus(DeploymentUnitStatus.State.undeploying).toMap())); } catch (Exception e) { logger.warn("Exception while transitioning stream {} state to {}", id, DeploymentUnitStatus.State.undeploying, e); } // Place all module deployments into a tree keyed by the // ZK transaction id. The ZK transaction id maintains // total ordering of all changes. This allows the // undeployment of modules in the reverse order in // which they were deployed. Map<Long, String> txMap = new TreeMap<Long, String>(); try { List<String> deployments = client.getChildren().forPath(streamModuleDeploymentPath); for (String deployment : deployments) { String path = new StreamDeploymentsPath(Paths.build(streamModuleDeploymentPath, deployment)) .build(); Stat stat = client.checkExists().forPath(path); Assert.notNull(stat); txMap.put(stat.getCzxid(), path); } } catch (Exception e) { //NoNodeException - nothing to delete ZooKeeperUtils.wrapAndThrowIgnoring(e, KeeperException.NoNodeException.class); } for (String deployment : txMap.values()) { paths.add(deployment); } for (Iterator<String> iterator = paths.descendingIterator(); iterator.hasNext();) { try { String path = iterator.next(); logger.trace("removing path {}", path); client.delete().deletingChildrenIfNeeded().forPath(path); } catch (Exception e) { ZooKeeperUtils.wrapAndThrowIgnoring(e, KeeperException.NoNodeException.class); } } try { client.delete().deletingChildrenIfNeeded().forPath(streamDeploymentPath); } catch (KeeperException.NotEmptyException e) { List<String> children = new ArrayList<String>(); try { children.addAll(client.getChildren().forPath(streamModuleDeploymentPath)); } catch (Exception ex) { children.add("Could not load list of children due to " + ex); } throw new IllegalStateException(String.format("The following children were not deleted from %s: %s", streamModuleDeploymentPath, children), e); } catch (Exception e) { ZooKeeperUtils.wrapAndThrowIgnoring(e, KeeperException.NoNodeException.class); } }
From source file:com.gdc.nms.web.mibquery.wizard.ciscavate.cjwizard.WizardContainer.java
/** * Customized constructor./*from w ww. jav a2 s . c om*/ * @param factory The factory which will be used to create the pages. * @param template Template to put inside the pages. * @param settings The settings to store the values put by the user. */ public WizardContainer(PageFactory factory, PageTemplate template, WizardSettings settings) { _factory = factory; _template = template; _settings = settings; _path = new LinkedList<WizardPage>(); _visitedPath = new ArrayDeque<WizardPage>(); _listeners = new LinkedList<WizardListener>(); _cancelStatuses = new ArrayDeque<Boolean>(); _prevStatuses = new ArrayDeque<Boolean>(); _nextStatuses = new ArrayDeque<Boolean>(); _finishStatuses = new ArrayDeque<Boolean>(); _visitedCancelStatuses = new ArrayDeque<Boolean>(); _visitedPrevStatuses = new ArrayDeque<Boolean>(); _visitedNextStatuses = new ArrayDeque<Boolean>(); _visitedFinishStatuses = new ArrayDeque<Boolean>(); initComponents(); _template.registerController(this); // get the first page: next(); }
From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ObjectKeyExpressionEvaluator.java
private List<JRJsonNode> goAnywhereDown(JRJsonNode jrJsonNode) { if (log.isDebugEnabled()) { log.debug("going " + MemberExpression.DIRECTION.ANYWHERE_DOWN + " by " + (expression.isWildcard() ? "wildcard" : "key: [" + expression.getObjectKey() + "]") + " on " + jrJsonNode.getDataNode()); }/*from www . j a v a2 s . c om*/ List<JRJsonNode> result = new ArrayList<>(); Deque<JRJsonNode> stack = new ArrayDeque<>(); JsonNode initialDataNode = jrJsonNode.getDataNode(); if (log.isDebugEnabled()) { log.debug("initial stack population with: " + initialDataNode); } // populate the stack initially if (initialDataNode.isArray()) { for (JsonNode deeper : initialDataNode) { stack.addLast(jrJsonNode.createChild(deeper)); } } else { stack.push(jrJsonNode); } while (!stack.isEmpty()) { JRJsonNode stackNode = stack.pop(); JsonNode stackDataNode = stackNode.getDataNode(); addChildrenToStack(stackNode, stack); if (log.isDebugEnabled()) { log.debug("processing stack element: " + stackDataNode); } // process the current stack item if (stackDataNode.isObject()) { if (log.isDebugEnabled()) { log.debug("stack element is object; wildcard: " + expression.isWildcard()); } // if wildcard => only filter the parent; we already added the object keys to the stack if (expression.isWildcard()) { if (applyFilter(stackNode)) { result.add(stackNode); } } // else go down and filter else { JRJsonNode deeperNode = goDeeperIntoObjectNode(stackNode, false); if (deeperNode != null) { result.add(deeperNode); } } } else if (stackDataNode.isValueNode() || stackDataNode.isArray()) { if (log.isDebugEnabled()) { log.debug("stack element is " + (stackDataNode.isValueNode() ? "value node" : "array") + "; wildcard: " + expression.isWildcard()); } if (expression.isWildcard()) { if (applyFilter(stackNode)) { result.add(stackNode); } } } } return result; }
From source file:org.onehippo.cms7.essentials.dashboard.instruction.FileInstruction.java
/** * Recursively creates parent directories in case they don't exist yet * * @param destination starting directory * @throws IOException//from w ww . j a v a 2 s. co m */ protected void createParentDirectories(final File destination) throws IOException { Deque<String> directories = new ArrayDeque<>(); String parent = destination.getParent(); while (!new File(parent).exists()) { directories.push(parent); parent = new File(parent).getParent(); } processDirectories(directories); Files.createFile(destination.toPath()); }
From source file:com.espertech.esper.epl.agg.service.AggSvcGroupByReclaimAgedImpl.java
private void sweep(long currentTime, long currentMaxAge) { ArrayDeque<Object> removed = new ArrayDeque<Object>(); for (Map.Entry<Object, AggregationMethodRowAged> entry : aggregatorsPerGroup.entrySet()) { long age = currentTime - entry.getValue().getLastUpdateTime(); if (age > currentMaxAge) { removed.add(entry.getKey()); }// www. jav a 2s. com } for (Object key : removed) { aggregatorsPerGroup.remove(key); internalHandleRemoved(key); removedCallback.removed(key); } }
From source file:com.tussle.script.StackedBindings.java
public Object put(String key, Object value) { //If it already exists, find where it is in the stack, and replace if (bindingMap.containsKey(key)) { for (Map<String, Object> val : bindingStack) if (val.containsKey(key)) { Object fromMapVal = bindingMap.get(key).pop(); Object fromStackVal = val.put(key, value); bindingMap.get(key).push(value); assert fromMapVal == fromStackVal; return fromMapVal; }//w ww.ja v a 2 s . com throw new AssertionError("Key found in map but not in stack"); } else { //Put it on the topmost map bindingStack.peek().put(key, value); bindingMap.put(key, new ArrayDeque<>()); bindingMap.get(key).push(value); return null; } }