本文整理汇总了Java中java.util.Deque.pollFirst方法的典型用法代码示例。如果您正苦于以下问题:Java Deque.pollFirst方法的具体用法?Java Deque.pollFirst怎么用?Java Deque.pollFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Deque
的用法示例。
在下文中一共展示了Deque.pollFirst方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listSubTreeBFS
import java.util.Deque; //导入方法依赖的package包/类
/**
* BFS Traversal of the system under pathRoot, with the entries in the list, in the
* same order as that of the traversal.
* <p>
* <b>Important:</b> This is <i>not an atomic snapshot</i> of the tree ever, but the
* state as it exists across multiple RPCs from zkClient to the ensemble.
* For practical purposes, it is suggested to bring the clients to the ensemble
* down (i.e. prevent writes to pathRoot) to 'simulate' a snapshot behavior.
*
* @param zk the zookeeper handle
* @param pathRoot The znode path, for which the entire subtree needs to be listed.
* @throws InterruptedException
* @throws KeeperException
*/
public static List<String> listSubTreeBFS(ZooKeeper zk, final String pathRoot) throws
KeeperException, InterruptedException {
Deque<String> queue = new LinkedList<String>();
List<String> tree = new ArrayList<String>();
queue.add(pathRoot);
tree.add(pathRoot);
while (true) {
String node = queue.pollFirst();
if (node == null) {
break;
}
List<String> children = zk.getChildren(node, false);
for (final String child : children) {
final String childPath = node + "/" + child;
queue.add(childPath);
tree.add(childPath);
}
}
return tree;
}
示例2: listSubTreeBFS
import java.util.Deque; //导入方法依赖的package包/类
/**
* BFS Traversal of the system under pathRoot, with the entries in the list, in the
* same order as that of the traversal.
* <p>
* <b>Important:</b> This is <i>not an atomic snapshot</i> of the tree ever, but the
* state as it exists across multiple RPCs from zkClient to the ensemble.
* For practical purposes, it is suggested to bring the clients to the ensemble
* down (i.e. prevent writes to pathRoot) to 'simulate' a snapshot behavior.
*
* @param zk the zookeeper handle
* @param pathRoot The znode path, for which the entire subtree needs to be listed.
* @throws InterruptedException
* @throws KeeperException
*/
public static List<String> listSubTreeBFS(ZooKeeper zk, final String pathRoot) throws
KeeperException, InterruptedException {
Deque<String> queue = new LinkedList<String>();
List<String> tree = new ArrayList<String>();
queue.add(pathRoot);
tree.add(pathRoot);
while (true) {
String node = queue.pollFirst();
if (node == null) {
break;
}
List<String> children = zk.getChildren(node, false);
for (final String child : children) {
final String childPath = node + "/" + child;
queue.add(childPath);
tree.add(childPath);
}
}
return tree;
}
示例3: readEffectiveConfig
import java.util.Deque; //导入方法依赖的package包/类
private static Map<String, Object> readEffectiveConfig(Path filePath){
Map<String, Object> config = getConfigParametersFromFile(filePath);
Deque<Map<String, Object>> configs = new ArrayDeque<>();
configs.add(config);
while (config.get(INHERIT) != null) {
String inherit = String.valueOf(config.get(INHERIT));
filePath = filePath.getParent().resolve(inherit);
config = getConfigParametersFromFile(filePath);
if (!config.isEmpty()) {
configs.addFirst(config);
}
}
Map<String, Object> effectiveConfig = configs.pollFirst();
while (!configs.isEmpty()) {
overwriteInnerProperties(effectiveConfig, configs.pollFirst());
}
effectiveConfig.remove(INHERIT);
return effectiveConfig;
}
示例4: findNextLeafNode
import java.util.Deque; //导入方法依赖的package包/类
/**
* Depth first search, in left-to-right order, of the node tree, using
* an explicit stack, to find the next non-empty leaf node.
*/
@SuppressWarnings("unchecked")
protected final N findNextLeafNode(Deque<N> stack) {
N n = null;
while ((n = stack.pollFirst()) != null) {
if (n.getChildCount() == 0) {
if (n.count() > 0)
return n;
} else {
for (int i = n.getChildCount() - 1; i >= 0; i--)
stack.addFirst((N) n.getChild(i));
}
}
return null;
}
示例5: maxSlidingWindow
import java.util.Deque; //导入方法依赖的package包/类
public int[] maxSlidingWindow(int[] nums, int k) {
int len = nums.length;
if (len == 0) return nums;
int[] res = new int[len - k + 1];
Deque<Integer> dq = new LinkedList<Integer>();
for (int i = 0; i < len; i++) {
while (!dq.isEmpty() && dq.peekLast() < nums[i])
dq.pollLast();
dq.offer(nums[i]);
if (i >= k - 1) {
res[i - k + 1] = dq.peek();
if (nums[i - k + 1] == dq.peek())
dq.pollFirst();
}
}
return res;
}
示例6: listChildrenBFSNoWatch
import java.util.Deque; //导入方法依赖的package包/类
/**
* BFS Traversal of all the children under path, with the entries in the list,
* in the same order as that of the traversal. Lists all the children without
* setting any watches.
*
* @param zkw
* - zk reference
* @param znode
* - path of node
* @return list of children znodes under the path
* @throws KeeperException
* if unexpected ZooKeeper exception
*/
private static List<String> listChildrenBFSNoWatch(ZooKeeperWatcher zkw,
final String znode) throws KeeperException {
Deque<String> queue = new LinkedList<String>();
List<String> tree = new ArrayList<String>();
queue.add(znode);
while (true) {
String node = queue.pollFirst();
if (node == null) {
break;
}
List<String> children = listChildrenNoWatch(zkw, node);
if (children == null) {
continue;
}
for (final String child : children) {
final String childPath = node + "/" + child;
queue.add(childPath);
tree.add(childPath);
}
}
return tree;
}
示例7: listChildrenBFSAndWatchThem
import java.util.Deque; //导入方法依赖的package包/类
/**
* BFS Traversal of all the children under path, with the entries in the list,
* in the same order as that of the traversal.
* Lists all the children and set watches on to them.
*
* @param zkw
* - zk reference
* @param znode
* - path of node
* @return list of children znodes under the path
* @throws KeeperException
* if unexpected ZooKeeper exception
*/
private static List<String> listChildrenBFSAndWatchThem(ZooKeeperWatcher zkw, final String znode)
throws KeeperException {
Deque<String> queue = new LinkedList<String>();
List<String> tree = new ArrayList<String>();
queue.add(znode);
while (true) {
String node = queue.pollFirst();
if (node == null) {
break;
}
List<String> children = listChildrenAndWatchThem(zkw, node);
if (children == null) {
continue;
}
for (final String child : children) {
final String childPath = node + "/" + child;
queue.add(childPath);
tree.add(childPath);
}
}
return tree;
}
示例8: flatten
import java.util.Deque; //导入方法依赖的package包/类
private synchronized void flatten(final boolean flattenNested) {
// We use iterative traversal as recursion may exceed the stack size limit.
final char[] chars = new char[length];
int pos = length;
// Strings are most often composed by appending to the end, which causes ConsStrings
// to be very unbalanced, with mostly single string elements on the right and a long
// linear list on the left. Traversing from right to left helps to keep the stack small
// in this scenario.
final Deque<CharSequence> stack = new ArrayDeque<>();
stack.addFirst(left);
CharSequence cs = right;
do {
if (cs instanceof ConsString) {
final ConsString cons = (ConsString) cs;
// Count the times a cons-string is traversed as part of other cons-strings being flattened.
// If it crosses a threshold we flatten the nested cons-string internally.
if (cons.state == STATE_FLATTENED || (flattenNested && ++cons.state >= STATE_THRESHOLD)) {
cs = cons.flattened(false);
} else {
stack.addFirst(cons.left);
cs = cons.right;
}
} else {
final String str = (String) cs;
pos -= str.length();
str.getChars(0, str.length(), chars, pos);
cs = stack.isEmpty() ? null : stack.pollFirst();
}
} while (cs != null);
left = new String(chars);
right = "";
state = STATE_FLATTENED;
}
示例9: handleEnter
import java.util.Deque; //导入方法依赖的package包/类
public static final Map<Object,Object> handleEnter(Map<Object,Object> context,
Deque<IInterceptor> queue,
Deque<IInterceptor> stack,
List<Predicate<Map<Object,Object>>> terminators) {
//NOTE: It's assumed the queue has been null-checked by this point
while (queue.size() > 0) {
IInterceptor interceptor = queue.pollFirst();
if (interceptor == null) {
context.remove("dais.queue");
return handleLeave(context, stack);
}
stack.offerFirst(interceptor);
try {
context = IInterceptor.enter(interceptor, context);
if (context.get("error") != null) {
return handleError(context, interceptor, stack);
}
} catch (Throwable t) {
context.put("error", t);
return handleError(context, interceptor, stack);
}
if (terminators != null) {
for (Predicate p : terminators) {
if (p != null && p.test(context)) {
context.remove("dais.queue");
return handleLeave(context, stack);
}
}
}
}
return context;
}
示例10: get
import java.util.Deque; //导入方法依赖的package包/类
@Override
public ByteBuffer get(int size) {
Deque<ByteBuffer> bufferQueue = bufferMap.get(size);
if (bufferQueue == null || bufferQueue.isEmpty())
return ByteBuffer.allocate(size);
else
return bufferQueue.pollFirst();
}
示例11: extractClassNameToRuntimeBeanMap
import java.util.Deque; //导入方法依赖的package包/类
/**
* @return map containing all class names as key, extracted RuntimeBeans as
* values. If more than zero values is returned, exactly one
* RuntimeBeanEntry will have isRoot set to true, even if yang does
* not contain special configuration for it.
*/
public static Map<String, RuntimeBeanEntry> extractClassNameToRuntimeBeanMap(
final String packageName, final DataNodeContainer container,
final String moduleYangName, final TypeProviderWrapper typeProviderWrapper,
final String javaNamePrefix, final Module currentModule, final SchemaContext schemaContext) {
AttributesRpcsAndRuntimeBeans attributesRpcsAndRuntimeBeans = extractSubtree(
packageName, container, typeProviderWrapper, currentModule,
schemaContext);
Map<String, RuntimeBeanEntry> result = new HashMap<>();
List<AttributeIfc> attributes;
Set<Rpc> rpcs;
if (attributesRpcsAndRuntimeBeans.isEmpty() == false) {
attributes = attributesRpcsAndRuntimeBeans.getAttributes();
rpcs = attributesRpcsAndRuntimeBeans.getRpcs();
} else {
// create artificial root if not defined in yang
attributes = Collections.emptyList();
rpcs = Collections.emptySet();
}
RuntimeBeanEntry rootRuntimeBeanEntry = createRoot(packageName,
container, moduleYangName, attributes, javaNamePrefix,
attributesRpcsAndRuntimeBeans.getRuntimeBeanEntries(), rpcs);
Deque<RuntimeBeanEntry> stack = new LinkedList<>();
stack.add(rootRuntimeBeanEntry);
while (stack.isEmpty() == false) {
RuntimeBeanEntry first = stack.pollFirst();
if (result.containsKey(first.getJavaNameOfRuntimeMXBean())) {
throw new NameConflictException(
first.getJavaNameOfRuntimeMXBean(), null, null);
}
result.put(first.getJavaNameOfRuntimeMXBean(), first);
stack.addAll(first.getChildren());
}
return result;
}
示例12: call
import java.util.Deque; //导入方法依赖的package包/类
public Subscriber<? super T> call(Subscriber<? super T> subscriber) {
final Deque<Object> buffer = new ArrayDeque();
final Deque<Long> timestampBuffer = new ArrayDeque();
final NotificationLite<T> notification = NotificationLite.instance();
final TakeLastQueueProducer<T> producer = new TakeLastQueueProducer(notification, buffer, subscriber);
subscriber.setProducer(producer);
final Subscriber<? super T> subscriber2 = subscriber;
return new Subscriber<T>(subscriber) {
protected void runEvictionPolicy(long now) {
while (OperatorTakeLastTimed.this.count >= 0 && buffer.size() > OperatorTakeLastTimed.this.count) {
timestampBuffer.pollFirst();
buffer.pollFirst();
}
while (!buffer.isEmpty() && ((Long) timestampBuffer.peekFirst()).longValue() < now - OperatorTakeLastTimed.this.ageMillis) {
timestampBuffer.pollFirst();
buffer.pollFirst();
}
}
public void onStart() {
request(Long.MAX_VALUE);
}
public void onNext(T args) {
long t = OperatorTakeLastTimed.this.scheduler.now();
timestampBuffer.add(Long.valueOf(t));
buffer.add(notification.next(args));
runEvictionPolicy(t);
}
public void onError(Throwable e) {
timestampBuffer.clear();
buffer.clear();
subscriber2.onError(e);
}
public void onCompleted() {
runEvictionPolicy(OperatorTakeLastTimed.this.scheduler.now());
timestampBuffer.clear();
buffer.offer(notification.completed());
producer.startEmitting();
}
};
}
示例13: cleanDeletedINode
import java.util.Deque; //导入方法依赖的package包/类
/**
* Clean an inode while we move it from the deleted list of post to the
* deleted list of prior.
* @param bsps The block storage policy suite.
* @param inode The inode to clean.
* @param post The post snapshot.
* @param prior The id of the prior snapshot.
* @param collectedBlocks Used to collect blocks for later deletion.
* @return Quota usage update.
*/
private static QuotaCounts cleanDeletedINode(
final BlockStoragePolicySuite bsps, INode inode,
final int post, final int prior,
final BlocksMapUpdateInfo collectedBlocks,
final List<INode> removedINodes) {
QuotaCounts counts = new QuotaCounts.Builder().build();
Deque<INode> queue = new ArrayDeque<INode>();
queue.addLast(inode);
while (!queue.isEmpty()) {
INode topNode = queue.pollFirst();
if (topNode instanceof INodeReference.WithName) {
INodeReference.WithName wn = (INodeReference.WithName) topNode;
if (wn.getLastSnapshotId() >= post) {
INodeReference.WithCount wc =
(INodeReference.WithCount) wn.getReferredINode();
if (wc.getLastWithName() == wn && wc.getParentReference() == null) {
// this wn is the last wn inside of the wc, also the dstRef node has
// been deleted. In this case, we should treat the referred file/dir
// as normal case
queue.add(wc.getReferredINode());
} else {
wn.cleanSubtree(bsps, post, prior, collectedBlocks, removedINodes);
}
}
// For DstReference node, since the node is not in the created list of
// prior, we should treat it as regular file/dir
} else if (topNode.isFile() && topNode.asFile().isWithSnapshot()) {
INodeFile file = topNode.asFile();
counts.add(file.getDiffs().deleteSnapshotDiff(bsps, post, prior, file,
collectedBlocks, removedINodes));
} else if (topNode.isDirectory()) {
INodeDirectory dir = topNode.asDirectory();
ChildrenDiff priorChildrenDiff = null;
DirectoryWithSnapshotFeature sf = dir.getDirectoryWithSnapshotFeature();
if (sf != null) {
// delete files/dirs created after prior. Note that these
// files/dirs, along with inode, were deleted right after post.
DirectoryDiff priorDiff = sf.getDiffs().getDiffById(prior);
if (priorDiff != null && priorDiff.getSnapshotId() == prior) {
priorChildrenDiff = priorDiff.getChildrenDiff();
counts.add(priorChildrenDiff.destroyCreatedList(bsps, dir,
collectedBlocks, removedINodes));
}
}
for (INode child : dir.getChildrenList(prior)) {
if (priorChildrenDiff != null
&& priorChildrenDiff.search(ListType.DELETED,
child.getLocalNameBytes()) != null) {
continue;
}
queue.addLast(child);
}
}
}
return counts;
}