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


Java Queue.peek方法代码示例

本文整理汇总了Java中java.util.Queue.peek方法的典型用法代码示例。如果您正苦于以下问题:Java Queue.peek方法的具体用法?Java Queue.peek怎么用?Java Queue.peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Queue的用法示例。


在下文中一共展示了Queue.peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: width

import java.util.Queue; //导入方法依赖的package包/类
public static int width(TreeNode t) {
    int maxWdith = 0, levelWidth = 0;
    Queue<TreeNode> q = new LinkedList<>();
    q.add(t);
    q.add(null);
    while (!q.isEmpty()) {
        if (null == (t = q.poll())) {
            if (levelWidth > maxWdith)
                maxWdith = levelWidth;
            levelWidth = 0;
            if (null != q.peek()) q.add(null);
        } else {
            levelWidth++;
            if (null != t.getLeft()) q.add(t.getLeft());
            if (null != t.getRight()) q.add(t.getRight());
        }
    }
    return maxWdith;
}
 
开发者ID:ApolloZhu,项目名称:APCSAB,代码行数:20,代码来源:ZhuZhiyu_Period1_BinaryTreeLab.java

示例2: containsTerminal

import java.util.Queue; //导入方法依赖的package包/类
private boolean containsTerminal(Object phrase, List<Terminal> candidates) {
	// cannot contain any terminal node if it is not a nonterminal
	if (!(phrase instanceof Nonterminal))
		return false;

	// Gather all child nodes in 'todo' and check whether one of them is a
	// candidate terminal. If this is the case one of the terminals is
	// part of the phrase.
	Queue<Object> todo = new LinkedList<Object>();
	todo.offer(phrase);
	while (todo.peek() != null) {
		Object top = todo.poll();
		if (candidates.contains(top))
			return true;

		List<Object> children = this.transitions.get(top);
		if (children == null)
			continue;

		for (Object child : children)
			todo.offer(child);
	}

	// default case: no candidate terminal is part of the phrase
	return false;
}
 
开发者ID:artificial-max,项目名称:polcla,代码行数:27,代码来源:ConstituencyTree.java

示例3: query

import java.util.Queue; //导入方法依赖的package包/类
public List<RegistryNode> query(final RegistryFilter filter) {
    List<RegistryNode> matches = new LinkedList<RegistryNode>();
    Queue<RegistryNode> queue = new LinkedList<RegistryNode>();
    
    queue.offer(registryRoot);
    while (queue.peek() != null) {
        final RegistryNode node = queue.poll();
        
        if (filter.accept(node)) {
            matches.add(node);
        }
        
        for (RegistryNode child: node.getChildren()) {
            queue.offer(child);
        }
    }
    
    return matches;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:Registry.java

示例4: test

import java.util.Queue; //导入方法依赖的package包/类
@APILevel
final boolean test(Connection connection, Session session, T t) {
	NetCom2Utils.parameterNotNull(connection, session, t);
	final Queue<TriPredicate<Connection, Session, T>> predicateTemp = new LinkedList<>(predicates);
	while (predicateTemp.peek() != null) {
		if (! predicateTemp.remove().test(connection, session, t)) {
			return false;
		}
	}
	return true;
}
 
开发者ID:ThorbenKuck,项目名称:NetCom2,代码行数:12,代码来源:PipelineReceiver.java

示例5: add

import java.util.Queue; //导入方法依赖的package包/类
public void add(final Stock stock){
    final Queue<OhlcContainer> sequence = this.sequences.get(stock.getCode());
    final OhlcContainer latest = sequence.peek();

    if ((latest == null) || (latest.getTime().isBefore(stock.getTime()) && latest.getClose() != stock.getClose())) {
        getLogger().debug("New {} stock {} passed for average processing", stock.getCode(), stock);
        if (sequence.size() == 10)
            sequence.remove();

        sequence.add(stock);

        this.values.replace(stock.getCode(), sequence.stream()
                .mapToDouble(OhlcContainer::getClose)
                .sum() / 10);
    }
}
 
开发者ID:mumukiller,项目名称:stock-patterns-recognition,代码行数:17,代码来源:AverageDirector.java

示例6: poll

import java.util.Queue; //导入方法依赖的package包/类
public Object poll() {
    Object obj = null;
    synchronized (this) {
        Queue<Object> q = this.queue;
        if (q == null) {
        } else {
            obj = q.poll();
            Object ts = this.terminalState;
            if (obj == null && ts != null && q.peek() == null) {
                obj = ts;
                this.terminalState = null;
            }
        }
    }
    return obj;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:RxRingBuffer.java

示例7: peek

import java.util.Queue; //导入方法依赖的package包/类
public Object peek() {
    Object obj;
    synchronized (this) {
        Queue<Object> q = this.queue;
        if (q == null) {
            obj = null;
        } else {
            obj = q.peek();
            Object ts = this.terminalState;
            if (obj == null && ts != null && q.peek() == null) {
                obj = ts;
            }
        }
    }
    return obj;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:RxRingBuffer.java

示例8: constructTreeFromRule

import java.util.Queue; //导入方法依赖的package包/类
private static void constructTreeFromRule(final TreeNode currentNode,
                                          final int currentLevel,
                                          final Queue<InputDriver> inputs,
                                          final DecisionTreeRule rule,
                                          final DecisionTreeType type) {
    final InputDriver value = inputs.poll();

    if (value == null) {
        return;
    }

    TreeNode newNode;
    final int nextLevel = currentLevel + 1;

    if (inputs.peek() == null) {
        newNode = createNode(value, nextLevel, type, NodeSupplier.Type.RESULT, rule);
    } else {
        newNode = createNode(value, nextLevel, type, NodeSupplier.Type.NODE, rule);
    }

    if (currentNode != null) {
        newNode = currentNode.addNode(newNode);
    }

    constructTreeFromRule(newNode, nextLevel, inputs, rule, type);
}
 
开发者ID:jpmorganchase,项目名称:swblocks-decisiontree,代码行数:27,代码来源:DecisionTreeFactory.java

示例9: processNextPending

import java.util.Queue; //导入方法依赖的package包/类
private void processNextPending(final Queue<CommitEntry> queue, final State allowedState,
        final Consumer<CommitEntry> processor) {
    while (!queue.isEmpty()) {
        final CommitEntry entry = queue.peek();
        final SimpleShardDataTreeCohort cohort = entry.cohort;

        if (cohort.isFailed()) {
            LOG.debug("{}: Removing failed transaction {}", logContext, cohort.getIdentifier());
            queue.remove();
            continue;
        }

        if (cohort.getState() == allowedState) {
            processor.accept(entry);
        }

        break;
    }

    maybeRunOperationOnPendingTransactionsComplete();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:ShardDataTree.java

示例10: calculate

import java.util.Queue; //导入方法依赖的package包/类
public DateCalculatorResult calculate(String text) {
    final DateCalcExpressionParser parser = new DateCalcExpressionParser();
    final Queue<Token> tokens = parser.parse(text);

    try {
        if (!tokens.isEmpty()) {
            if (tokens.peek() instanceof DateToken) {
                return handleDateExpression(tokens);
            } else if (tokens.peek() instanceof TimeToken) {
                return handleTimeExpression(tokens);
            }
        }
    } catch (UnsupportedTemporalTypeException utte) {
        throw new DateCalcException(utte.getLocalizedMessage());
    }
    throw new DateCalcException("An invalid expression was given: " + text);
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:18,代码来源:DateCalculator.java

示例11: crawl

import java.util.Queue; //导入方法依赖的package包/类
public synchronized Set<NodeRef> crawl(Set<NodeRef> startingNodes)
{
    init();
    Queue<NodeRef> nodesToProcess = new LinkedList<NodeRef>();
    nodesToProcess.addAll(startingNodes);
    Set<NodeRef> resultingNodeSet = new HashSet<NodeRef>(89);
    Set<NodeRef> processedNodes = new HashSet<NodeRef>(89);

    // Do we have any more nodes to process?
    while (nodesToProcess.peek() != null)
    {
        // Yes, we do. Read the next noderef from the queue.
        NodeRef thisNode = nodesToProcess.poll();
        // Check that we haven't already processed it. Skip it if we have, process it if we haven't
        if (!processedNodes.contains(thisNode))
        {
            // Record the fact that we're processing this node
            processedNodes.add(thisNode);
            // We check this node against any filters that are in place (the nodes
            // that we were given to start with are always processed)
            if (startingNodes.contains(thisNode) || includeNode(thisNode))
            {
                resultingNodeSet.add(thisNode);
                Set<NodeRef> subsequentNodes = findSubsequentNodes(thisNode);
                for (NodeRef node : subsequentNodes)
                {
                    nodesToProcess.add(node);
                }
            }
        }
    }
    return resultingNodeSet;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:34,代码来源:StandardNodeCrawlerImpl.java

示例12: getNode

import java.util.Queue; //导入方法依赖的package包/类
private TreeNode getNode(Queue<Integer> nodes) {
    if (nodes.isEmpty()) return null;
    Integer val = nodes.poll();
    Queue<Integer> smaller = new LinkedList<>();
    while (!nodes.isEmpty() && nodes.peek() <= val) {
        smaller.offer(nodes.poll());
    }

    TreeNode root = new TreeNode(val);
    root.left = getNode(smaller);
    root.right = getNode(nodes);
    return root;
}
 
开发者ID:xy1m,项目名称:PlayGround,代码行数:14,代码来源:SerializeBinarySearchTree.java

示例13: selectNextStateToProcess

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Picks the cluster state with highest version with the same master from the queue. All cluster states with
 * lower versions are ignored. If a cluster state with a different master is seen the processing logic stops and the
 * last processed state is returned.
 */
static ClusterState selectNextStateToProcess(Queue<ProcessClusterState> processNewClusterStates) {
    // try and get the state with the highest version out of all the ones with the same master node id
    ProcessClusterState stateToProcess = processNewClusterStates.poll();
    if (stateToProcess == null) {
        return null;
    }
    stateToProcess.processed = true;
    while (true) {
        ProcessClusterState potentialState = processNewClusterStates.peek();
        // nothing else in the queue, bail
        if (potentialState == null) {
            break;
        }
        // if its not from the same master, then bail
        if (!Objects.equals(stateToProcess.clusterState.nodes().masterNodeId(), potentialState.clusterState.nodes().masterNodeId())) {
            break;
        }
        // we are going to use it for sure, poll (remove) it
        potentialState = processNewClusterStates.poll();
        if (potentialState == null) {
            // might happen if the queue is drained
            break;
        }
        potentialState.processed = true;

        if (potentialState.clusterState.version() > stateToProcess.clusterState.version()) {
            // we found a new one
            stateToProcess = potentialState;
        }
    }
    return stateToProcess.clusterState;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:38,代码来源:ZenDiscovery.java

示例14: handleDateExpression

import java.util.Queue; //导入方法依赖的package包/类
private DateCalculatorResult handleDateExpression(final Queue<Token> tokens) {
    DateToken startDateToken = (DateToken) tokens.poll();
    validateToken(tokens.peek(), OperatorToken.class);
    OperatorToken operatorToken = (OperatorToken) tokens.poll();
    Token thirdToken = tokens.peek();

    if (thirdToken instanceof IntegerToken) {
        return performDateMath(startDateToken, operatorToken, tokens);
    } else if (thirdToken instanceof DateToken) {
        return getDateDiff(startDateToken, tokens.poll());
    } else {
        throw new DateCalcException("Invalid expression");
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:15,代码来源:DateCalculator.java

示例15: handleTimeExpression

import java.util.Queue; //导入方法依赖的package包/类
private DateCalculatorResult handleTimeExpression(final Queue<Token> tokens) {
    TimeToken startTimeToken = (TimeToken) tokens.poll();
    validateToken(tokens.peek(), OperatorToken.class);
    OperatorToken operatorToken = (OperatorToken) tokens.poll();
    Token thirdToken = tokens.peek();

    if (thirdToken instanceof IntegerToken) {
        return doTimeMath(operatorToken, startTimeToken, tokens);
    } else if (thirdToken instanceof TimeToken) {
        return getTimeDiff(operatorToken, startTimeToken, tokens.poll());
    } else {
        throw new DateCalcException("Invalid expression");
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:15,代码来源:DateCalculator.java


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