当前位置: 首页>>代码示例>>Java>>正文


Java Deque.pollFirst方法代码示例

本文整理汇总了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;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:35,代码来源:ZKUtil.java

示例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;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:35,代码来源:ZKUtil.java

示例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;
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:23,代码来源:ConfigurationReader.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:Nodes.java

示例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;
}
 
开发者ID:JoeZ-EE,项目名称:Aim2Offer,代码行数:21,代码来源:065_MaxInSlidingWindow.java

示例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;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:36,代码来源:ZKUtil.java

示例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;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:36,代码来源:ZKUtil.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:ConsString.java

示例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;

}
 
开发者ID:ohpauleez,项目名称:dais,代码行数:39,代码来源:Chain.java

示例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();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:9,代码来源:BufferSupplier.java

示例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;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:46,代码来源:RuntimeBeanEntry.java

示例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();
        }
    };
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:45,代码来源:OperatorTakeLastTimed.java

示例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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:68,代码来源:DirectoryWithSnapshotFeature.java


注:本文中的java.util.Deque.pollFirst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。