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


Java Queue.offer方法代码示例

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


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

示例1: 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

示例2: free

import java.util.Queue; //导入方法依赖的package包/类
private void free(ByteBuffer oldBuf) {
    if ((oldBuf == null) || ((maxCachedBufferSize != 0) && (oldBuf.capacity() > maxCachedBufferSize))
            || oldBuf.isReadOnly() || isDerived() || (Thread.currentThread() != ownerThread)) {
        return;
    }

    // Add to the cache.
    Queue<CachedBuffer> pool;

    if (oldBuf.isDirect()) {
        pool = directBuffers.get().get(oldBuf.capacity());
    } else {
        pool = heapBuffers.get().get(oldBuf.capacity());
    }

    if (pool == null) {
        return;
    }

    // Restrict the size of the pool to prevent OOM.
    if ((maxPoolSize == 0) || (pool.size() < maxPoolSize)) {
        pool.offer(new CachedBuffer(oldBuf));
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:CachedBufferAllocator.java

示例3: getImportance

import java.util.Queue; //导入方法依赖的package包/类
public int getImportance(List<Employee> employees, int id) {
    final int[] sum = {0};
    Queue<Integer> q = new LinkedList<>();
    q.offer(id);
    while (!q.isEmpty()) {
        int i = q.poll();
        Employee e = find(employees, i);
        if (e != null) {
            sum[0] += e.importance;
            List<Integer> sub = e.subordinates;
            if (!sub.isEmpty()) {
                sub.forEach(s -> {
                    Employee emp = find(employees, s);
                    if (emp != null) {
                        q.offer(emp.id);
                    }
                });
            }
        }
    }
    return sum[0];
}
 
开发者ID:bakhodirsbox,项目名称:AlgoCS,代码行数:23,代码来源:EmployeeImp_690.java

示例4: rightSideView

import java.util.Queue; //导入方法依赖的package包/类
public List<Integer> rightSideView(TreeNode root) {
    if (root == null) return new LinkedList<>();
    Queue<TreeNode> q = new LinkedList<>();
    List<Integer> l = new LinkedList<>();
    q.offer(root);
    while (!q.isEmpty()) {
        int size = q.size();
        for (int i = 0; i < size; i++) {
            TreeNode t = q.poll();
            if (i == 0) l.add(t.val);
            if (t.right != null) {
                q.offer(t.right);
            }
            if (t.left != null) {
                q.offer(t.left);
            }
        }
    }
    return l;
}
 
开发者ID:bakhodirsbox,项目名称:AlgoCS,代码行数:21,代码来源:BinTreeRightSide_199.java

示例5: largestValues

import java.util.Queue; //导入方法依赖的package包/类
public List<Integer> largestValues(TreeNode root) {
    if (root == null) return new LinkedList<>();
    List<Integer> maxs = new LinkedList<>();
    Queue<TreeNode> q = new LinkedList<>();
    q.offer(root);
    int max = Integer.MIN_VALUE;
    while (!q.isEmpty()) {
        int size = q.size();
        for (int i = 0; i < size; i++) {
            TreeNode t = q.poll();
            if (t.val > max) max = t.val;
            if (t.left != null) q.offer(t.left);
            if (t.right != null) q.offer(t.right);
        }
        maxs.add(max);
        max = Integer.MIN_VALUE;
    }
    return maxs;
}
 
开发者ID:bakhodirsbox,项目名称:AlgoCS,代码行数:20,代码来源:LargeValEachRow_515.java

示例6: setRoadTrafficNotInNavigate

import java.util.Queue; //导入方法依赖的package包/类
/**
 * 检查路书是否堵车
 *
 * @param target     目标地点
 * @param routeModel 路书
 * @param sb         路况信息
 * @return true=是
 */
private boolean setRoadTrafficNotInNavigate(String target, RouteModel routeModel, StringBuilder sb) {
    routeModel.refreshRoadCondition();
    Log.i(TAG, "conditionNodes.size=" + routeModel.getConditionNodes().size());
    Queue<Integer> rQueue = new LinkedBlockingQueue<Integer>();
    int conjestionCount = 0;
    for (int i = 0; i < routeModel.getConditionNodes().size(); ++i) {
        if (routeModel.getConditionNodes().get(i).getRoadCondition() >= RouteModel.ROAD_CONDITION_TYPE_Slow) {
            rQueue.offer(i);
            if (routeModel.getConditionNodes().get(i).getRoadCondition() > RouteModel.ROAD_CONDITION_TYPE_Slow) {
                conjestionCount++;
            }
        }
    }
    return setTrafficState(sb, routeModel, rQueue, conjestionCount, 0);
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:24,代码来源:NavigatorService.java

示例7: processGrouperTypeToken

import java.util.Queue; //导入方法依赖的package包/类
private void processGrouperTypeToken(
		final Queue<Token> outputQueue,
		final Deque<Token> operationStack,
		final Token token ) {
	final GrouperType grouperType = (GrouperType) token.getValue();
	if ( grouperType == GrouperType.LEFT_PARENTHESES ) {
		operationStack.push( token );
		return;
	}
	checkArgument( grouperType == GrouperType.RIGHT_PARENTHESES );
	boolean foundLeftParentheses = false;
	for ( final Iterator<Token> tokenIterator = operationStack.iterator(); tokenIterator
			.hasNext(); ) {
		final Token stackedOperationToken = tokenIterator.next();
		if ( isLeftParentheses( stackedOperationToken ) ) {
			foundLeftParentheses = true;
			tokenIterator.remove();
			break;
		}
		tokenIterator.remove();
		outputQueue.offer( stackedOperationToken );
	}
	if ( ! foundLeftParentheses ) {
		throw new SyntaxExpressionException(
				"Mismatched right parentheses." );
	}
}
 
开发者ID:WellCosta,项目名称:MathMax,代码行数:28,代码来源:Parser.java

示例8: getUsedNamespaces

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Iterates through policy vocabulary and extracts set of namespaces used in
 * the policy expression.
 *
 * @return collection of used namespaces within given policy instance
 * @throws PolicyException Thrown if internal processing failed.
 */
private Collection<String> getUsedNamespaces() throws PolicyException {
    final Set<String> namespaces = new HashSet<String>();
    namespaces.add(getNamespaceVersion().toString());

    if (this.policyId != null) {
        namespaces.add(PolicyConstants.WSU_NAMESPACE_URI);
    }

    final Queue<ModelNode> nodesToBeProcessed = new LinkedList<ModelNode>();
    nodesToBeProcessed.add(rootNode);

    ModelNode processedNode;
    while ((processedNode = nodesToBeProcessed.poll()) != null) {
        for (ModelNode child : processedNode.getChildren()) {
            if (child.hasChildren()) {
                if (!nodesToBeProcessed.offer(child)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0081_UNABLE_TO_INSERT_CHILD(nodesToBeProcessed, child)));
                }
            }

            if (child.isDomainSpecific()) {
                final AssertionData nodeData = child.getNodeData();
                namespaces.add(nodeData.getName().getNamespaceURI());
                if (nodeData.isPrivateAttributeSet()) {
                    namespaces.add(PolicyConstants.SUN_POLICY_NAMESPACE_URI);
                }

                for (Entry<QName, String> attribute : nodeData.getAttributesSet()) {
                    namespaces.add(attribute.getKey().getNamespaceURI());
                }
            }
        }
    }

    return namespaces;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:PolicySourceModel.java

示例9: main

import java.util.Queue; //导入方法依赖的package包/类
public static void main(String[] args) {
    Queue<Long> userIds = new ArrayDeque<>();
    userIds.offer(1l);

    for (int i = 0; userIds.iterator().hasNext(); i++) {
        final long nextUserId = userIds.iterator().next();
        System.out.println(i + ":" + nextUserId);
    }

}
 
开发者ID:freedompy,项目名称:commelina,代码行数:11,代码来源:ArrayTest.java

示例10: 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

示例11: createPropertyEvaluator

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Creates a {@link PropertyEvaluator} with {@link ProjectConfiguration} support.
 * @param project the project to create {@link PropertyEvaluator} for
 * @param helper the {@link Project}'s {@link AntProjectHelper}
 * @param additionalPropertyProviders the additional {@link PropertyProvider}s
 * @return a new {@link PropertyEvaluator}
 */
@NonNull
public static PropertyEvaluator createPropertyEvaluator(
    @NonNull final Project project,
    @NonNull final AntProjectHelper helper,
    @NonNull final PropertyProvider... additionalPropertyProviders) {
    Parameters.notNull("project", project); //NOI18N
    Parameters.notNull("helper", helper);   //NOI18N
    Parameters.notNull("additionalPropertyProviders", additionalPropertyProviders); //NOI18N

    PropertyEvaluator baseEval1 = PropertyUtils.sequentialPropertyEvaluator(
            helper.getStockPropertyPreprovider(),
            helper.getPropertyProvider(ProjectConfigurations.CONFIG_PROPS_PATH));
    PropertyEvaluator baseEval2 = PropertyUtils.sequentialPropertyEvaluator(
            helper.getStockPropertyPreprovider(),
            helper.getPropertyProvider(AntProjectHelper.PRIVATE_PROPERTIES_PATH));
    final Queue<PropertyProvider> providers = new ArrayDeque<>(additionalPropertyProviders.length + 7);
    providers.offer(helper.getPropertyProvider(ProjectConfigurations.CONFIG_PROPS_PATH));
    providers.offer(new ConfigPropertyProvider(baseEval1, "nbproject/private/configs", helper));    //NOI18N
    providers.offer(helper.getPropertyProvider(AntProjectHelper.PRIVATE_PROPERTIES_PATH));
    providers.offer(helper.getProjectLibrariesPropertyProvider());
    providers.offer(PropertyUtils.userPropertiesProvider(baseEval2,
        "user.properties.file", FileUtil.toFile(project.getProjectDirectory())));   //NOI18N
    providers.offer(new ConfigPropertyProvider(baseEval1, "nbproject/configs", helper));    //NOI18N
    providers.offer(helper.getPropertyProvider(AntProjectHelper.PROJECT_PROPERTIES_PATH));
    Collections.addAll(providers, additionalPropertyProviders);
    return PropertyUtils.sequentialPropertyEvaluator(
        helper.getStockPropertyPreprovider(),
        providers.toArray(new PropertyProvider[providers.size()]));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:ProjectConfigurations.java

示例12: main

import java.util.Queue; //导入方法依赖的package包/类
public static void main(String[] args) {
	
	//LinkedList é uma fila também, por isso sua participação na definição
	Queue<String> fila = new LinkedList<>();
	
	//offer trabalha como o add
	//Sua diferença é que quando, por qualquer motivo, não seja possível inserir ele não vai retornar erro
	//simplesmente ele irá retornar falso
	fila.offer("Maria");
	fila.offer("João");
	
	fila.add("José"); // -> Retorna erro
	
	//Os dois métodos Peek/Element pegam elementos da lista, porém
	//Peek -> Quando a fila está vazia retorna null
	//Element -> Quando a fila está vazia retorna um erro
	
	System.out.println("Peek/Element...");
	
	System.out.println(fila.peek());
	System.out.println(fila.element());
	
	//Removendo elementos da lista
	//Poll/Remove...
	System.out.println("Pool/Remove");
	System.out.println(fila.poll()); //-> Remove o primeiro da fila
	System.out.print(fila.remove());
	System.out.println(fila.poll());
	System.out.println(fila.poll()); //Quando os elementos da fila acabam e o poll é executado
									 //ele retorna null
	
	System.out.println(fila.remove()); //Quando os elementos da fila acabam e o remove é executado
										//ele retorna um erro

	
}
 
开发者ID:Gigers,项目名称:Examples,代码行数:37,代码来源:Fila.java

示例13: forceClearLocks

import java.util.Queue; //导入方法依赖的package包/类
Collection<? extends Lock> forceClearLocks() {
    synchronized (locks) {
        final Queue<RecordOwnerLock> locked = new ArrayDeque<>();
        for (Iterator<RecordOwnerLock> it = locks.values().iterator();
            it.hasNext();) {
            RecordOwnerLock lock = it.next();
            if (lock.isLocked()) {
                it.remove();
                locked.offer(lock);
            }
        }
        return locked;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:RecordOwnerLockFactory.java

示例14: travelBFS

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Benedth First Search
 */
@Override
public LinkedList<StationGraphVO> travelBFS(StationGraphVO vertex, boolean isAscending) {
	LinkedList<StationGraphVO> results = new LinkedList<>();
	
	HashSet<StationGraphVO> checkVisitSet = new HashSet<>();
	
	Queue<StationGraphVO> queue = new LinkedList<>();
	
	//첫 번째 Node 방문
	StationGraphVO firstVertex = getVertex(vertex);
	queue.offer(firstVertex);
	checkVisitSet.add(firstVertex);
	
	while(!queue.isEmpty()) {
		StationGraphVO dequeuedVertex = queue.poll();
		results.add(dequeuedVertex);
		
		sort(edgesByVertices.get(dequeuedVertex), isAscending);
		
		for(Edge edge : edgesByVertices.get(dequeuedVertex)) {
			
			StationGraphVO linkedVertex = edge.getToVertex();
			linkedVertex = edgesByVertices.ceilingKey(linkedVertex); //추가
			
			if(!checkVisitSet.contains(linkedVertex)) {
				checkVisitSet.add(linkedVertex);
				queue.offer(linkedVertex);
			}
		}
	}
	
	return results;
}
 
开发者ID:xeyez,项目名称:StationGraph,代码行数:37,代码来源:StationGraph.java

示例15: bfs

import java.util.Queue; //导入方法依赖的package包/类
/**
 * BFS the merge tree and identify cluster membership.
 * @param membership the cluster membership array.
 * @param cluster the last merge point of cluster.
 * @param id the cluster ID.
 */
private void bfs(int[] membership, int cluster, int id) {
    int n = merge.length + 1;
    Queue<Integer> queue = new LinkedList<>();
    queue.offer(cluster);

    for (Integer i = queue.poll(); i != null; i = queue.poll()) {
        if (i < n) {
            membership[i] = id;
            continue;
        }

        i -= n;

        int m1 = merge[i][0];

        if (m1 >= n) {
            queue.offer(m1);
        } else {
            membership[m1] = id;
        }

        int m2 = merge[i][1];

        if (m2 >= n) {
            queue.offer(m2);
        } else {
            membership[m2] = id;
        }
    }
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:37,代码来源:HierarchicalClustering.java


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