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


Java Queue.add方法代码示例

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


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

示例1: subscribe

import java.util.Queue; //导入方法依赖的package包/类
@Override
public <T extends PubSubMessage> void subscribe(String name, final PubSubListener<T> listener, Class<T> clazz) {
    RTopic<T> topic = redissonSub.getTopic(name);
    int regId = topic.addListener(new MessageListener<T>() {
        @Override
        public void onMessage(String channel, T msg) {
            if (!nodeId.equals(msg.getNodeId())) {
                listener.onMessage(msg);
            }
        }
    });

    Queue<Integer> list = map.get(name);
    if (list == null) {
        list = new ConcurrentLinkedQueue<Integer>();
        Queue<Integer> oldList = map.putIfAbsent(name, list);
        if (oldList != null) {
            list = oldList;
        }
    }
    list.add(regId);
}
 
开发者ID:bridgeli,项目名称:netty-socketio-demo,代码行数:23,代码来源:RedissonPubSubStore.java

示例2: floodFill

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Flood fills from a given {@code Position} p, based on
 * connectivity information encoded in boolmap
 *
 * @param boolmap The connectivity information for this floodfill.
 * @param x The starting x coordinate.
 * @param y The starting y coordinate.
 * @param limit Limit to stop flood fill at.
 * @return A boolean[][] of the same size as boolmap, where "true"
 *      means the fill succeeded at that location.
 */
public static boolean[][] floodFill(boolean[][] boolmap, int x, int y,
    int limit) {
    final int xmax = boolmap.length, ymax = boolmap[0].length;
    boolean[][] visited = new boolean[xmax][ymax];
    Queue<Position> q = new LinkedList<>();

    visited[x][y] = true;
    for (Position p = new Position(x, y); p != null && --limit > 0;
         p = q.poll()) {
        for (Direction d : Direction.values()) {
            final Position np = new Position(p, d);
            if (np.isValid(xmax, ymax)
                && boolmap[np.getX()][np.getY()]
                && !visited[np.getX()][np.getY()]) {
                visited[np.getX()][np.getY()] = true;
                q.add(np);
            }
        }
    }
    return visited;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:33,代码来源:Map.java

示例3: whenGatewayEventUnableToResolveFromOffHeapTheStatForNotQueuedConflatedShouldBeIncremented

import java.util.Queue; //导入方法依赖的package包/类
@Test
public void whenGatewayEventUnableToResolveFromOffHeapTheStatForNotQueuedConflatedShouldBeIncremented()
    throws Exception {
  GatewaySenderStats stats = mockGatewaySenderStats();

  GatewaySenderEventImpl event = mock(GatewaySenderEventImpl.class);
  when(event.makeHeapCopyIfOffHeap()).thenReturn(null);
  GatewaySenderEventImpl eventResolvesFromOffHeap = mock(GatewaySenderEventImpl.class);
  when(eventResolvesFromOffHeap.makeHeapCopyIfOffHeap()).thenReturn(eventResolvesFromOffHeap);
  Queue backingList = new LinkedList();
  backingList.add(event);
  backingList.add(eventResolvesFromOffHeap);

  BucketRegionQueue bucketRegionQueue = mockBucketRegionQueue(backingList);

  TestableParallelGatewaySenderQueue queue = new TestableParallelGatewaySenderQueue(sender,
      Collections.emptySet(), 0, 1, metaRegionFactory);
  queue.setMockedAbstractBucketRegionQueue(bucketRegionQueue);

  List peeked = queue.peek(1, 1000);
  assertEquals(1, peeked.size());
  verify(stats, times(1)).incEventsNotQueuedConflated();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:24,代码来源:ParallelGatewaySenderQueueJUnitTest.java

示例4: handleGaze

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Finds the control under the specified screen coordinates and calls its
 * gaze handler on the localized point. Returns the gaze response or null if
 * the gaze is not handled.
 */
private IGazeResponse handleGaze(int screenX, int screenY, Gaze gaze){
	Queue<Control[]> childrenQueue = new LinkedList<Control[]>();
	childrenQueue.add(rootShell.getChildren());
	Rectangle monitorBounds = rootShell.getMonitor().getBounds();
    while (!childrenQueue.isEmpty()) {
        for (Control child : childrenQueue.remove()) {
            Rectangle childScreenBounds = child.getBounds();
            Point screenPos = child.toDisplay(0, 0);
            childScreenBounds.x = screenPos.x - monitorBounds.x;
            childScreenBounds.y = screenPos.y - monitorBounds.y;
            if (childScreenBounds.contains(screenX, screenY)) {
                if (child instanceof Composite) {
                    Control[] nextChildren =
                            ((Composite) child).getChildren();
                    if (nextChildren.length > 0 && nextChildren[0] != null) {
                        childrenQueue.add(nextChildren);
                    }
                }
                IGazeHandler handler =
                        (IGazeHandler) child
                                .getData(HandlerBindManager.KEY_HANDLER);
                if (child.isVisible() && handler != null) {
                    return handler.handleGaze(screenX, screenY,
                            screenX - childScreenBounds.x, screenY
                                    - childScreenBounds.y, gaze);
                }
            }
        }
    }
    return null;
}
 
开发者ID:SERESLab,项目名称:iTrace-Archive,代码行数:37,代码来源:ITrace.java

示例5: impliedFeatures

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Given a set of features, return a new set of all features directly or
 * indirectly implied by any of them.
 * @param features the set of features whose implications to find
 * @return the implied set of features
 */
public static Set<Feature<?>> impliedFeatures(Set<Feature<?>> features) {
  Set<Feature<?>> impliedSet = new LinkedHashSet<Feature<?>>();
  Queue<Feature<?>> queue = new ArrayDeque<Feature<?>>(features);
  while (!queue.isEmpty()) {
    Feature<?> feature = queue.remove();
    for (Feature<?> implied : feature.getImpliedFeatures()) {
      if (!features.contains(implied) && impliedSet.add(implied)) {
        queue.add(implied);
      }
    }
  }
  return impliedSet;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:FeatureUtil.java

示例6: fillOcean

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Flood fill ocean regions.
 *
 * @param map The {@code Map} to fill in.
 * @param tile A valid starting {@code Tile}.
 * @param region A {@code ServerRegion} to fill with.
 * @param bounds A {@code Rectangle} that bounds the filling.
 * @return The number of tiles filled.
 */
private static int fillOcean(Map map, Tile tile, ServerRegion region,
                             Rectangle bounds) {
    Queue<Tile> q = new LinkedList<>();
    int n = 0;
    boolean[][] visited = new boolean[map.getWidth()][map.getHeight()];
    visited[tile.getX()][tile.getY()] = true;
    q.add(tile);

    while ((tile = q.poll()) != null) {
        region.addTile(tile);
        n++;

        for (Direction direction : Direction.values()) {
            Tile t = map.getAdjacentTile(tile, direction);
            if (t != null
                && !visited[t.getX()][t.getY()]
                && bounds.contains(t.getX(), t.getY())) {
                visited[t.getX()][t.getY()] = true;
                if ((t.getRegion() == null || t.getRegion() == region)
                    && !t.isLand()) {
                    q.add(t);
                }
            }
        }
    }
    return n;
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:37,代码来源:ServerRegion.java

示例7: test

import java.util.Queue; //导入方法依赖的package包/类
static <E> void test(Queue<E> queue, Supplier<E> supplier,
                     BiConsumer<? super Queue<E>, Throwable> checker) {
    Throwable x = null;
    try { queue.add(supplier.get()); }
    catch (Throwable e) { x = e; }
    checker.accept(queue, x);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:AddNonComparable.java

示例8: pushMessageTo

import java.util.Queue; //导入方法依赖的package包/类
public void pushMessageTo(BaseKey recipient, Object message) {
    Queue<Object> messageQueue = messages.get(recipient);
    if(messageQueue == null) {
        messageQueue = new ConcurrentLinkedQueue<>();
        messages.put(recipient, messageQueue);
    }
    messageQueue.add(message);
}
 
开发者ID:Zhuinden,项目名称:simple-stack,代码行数:9,代码来源:MessageQueue.java

示例9: getActions

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Returns the set of actions occurring on control edges,
 * either on this level or recursively within function calls.
 */
public Set<Action> getActions() {
    Set<Action> result = new LinkedHashSet<>();
    Set<Function> seen = new HashSet<>();
    Queue<Template> todo = new LinkedList<>();
    todo.add(this);
    while (!todo.isEmpty()) {
        Template t = todo.poll();
        for (Location loc : t.getLocations()) {
            if (!loc.isTrial()) {
                continue;
            }
            for (SwitchStack swit : loc.getAttempt()) {
                Callable unit = swit.getBottomCall()
                    .getUnit();
                if (unit instanceof Action) {
                    result.add((Action) unit);
                } else {
                    Function function = (Function) unit;
                    Template fresh = ((Function) unit).getTemplate();
                    if (seen.add(function) && fresh != null) {
                        todo.add(fresh);
                    }
                }
            }
        }
    }
    return result;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:33,代码来源:Template.java

示例10: computeEU

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Constructs the bit set for the EU operator.
 */
private BitSet computeEU(BitSet arg1, BitSet arg2) {
    BitSet result = new BitSet(this.nodeCount);
    BitSet arg1Marking = arg1;
    BitSet arg2Marking = arg2;
    // mark the states that satisfy the second operand
    Queue<Integer> newStates = new LinkedList<>();
    for (int i = 0; i < this.nodeCount; i++) {
        if (arg2Marking.get(i)) {
            result.set(i);
            newStates.add(i);
        }
    }
    // recurse to the predecessors of newly marked states
    while (!newStates.isEmpty()) {
        int newState = newStates.poll();
        int[] preds = this.backward[newState];
        for (int b = 0; b < preds.length; b++) {
            int pred = preds[b];
            // mark the predecessor, if it satisfies the first operand
            // and it is not yet marked
            if (arg1Marking.get(pred) && !result.get(pred)) {
                result.set(pred);
                newStates.add(pred);
            }
        }
    }
    return result;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:32,代码来源:CTLMarker.java

示例11: addListener

import java.util.Queue; //导入方法依赖的package包/类
public void addListener(String channelName, RedisPubSubListener<?> listener) {
    if (listener == null) {
        return;
    }
    
    Queue<RedisPubSubListener<?>> queue = channelListeners.get(channelName);
    if (queue == null) {
        queue = new ConcurrentLinkedQueue<RedisPubSubListener<?>>();
        Queue<RedisPubSubListener<?>> oldQueue = channelListeners.putIfAbsent(channelName, queue);
        if (oldQueue != null) {
            queue = oldQueue;
        }
    }

    boolean deleted = false;
    synchronized (queue) {
        if (channelListeners.get(channelName) != queue) {
            deleted = true;
        } else {
            queue.add(listener);
        }
    }
    if (deleted) {
        addListener(channelName, listener);
        return;
    }

    conn.addListener(listener);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:30,代码来源:PubSubConnectionEntry.java

示例12: searchCurrency

import java.util.Queue; //导入方法依赖的package包/类
/**
 * BSF (Breadth Search First) algorithm which uses a queue
 *
 * @param currencyFrom currency from where to start to look for a currency
 * @param currencyTo   currency to where we would like to achieve
 * @return big precision decimal with final concurrency
 */
public BigDecimal searchCurrency(String currencyFrom, String currencyTo) {
    BigDecimal weight = new BigDecimal(1);
    if (currencyFrom.equals(currencyTo)) {
        return weight;
    }
    VertexDomain vertexDomain = new VertexDomain(currencyFrom);
    if (rateGraph.containsKey(vertexDomain)) {
        Queue<VertexDomain> queue = new LinkedList<>();
        queue.add(vertexDomain);
        // Marking visited ones is the way of following up the currencies of interest
        Map<String, BigDecimal> visited = new HashMap<>();
        while (!queue.isEmpty()) {
            // gets the first element of the queue and removes / uses it
            VertexDomain currentVertexDomain = queue.remove();
            // if current vertex is the one we are looking for, we stop
            if (currentVertexDomain.equals(new VertexDomain(currencyTo))) {
                // we check how many visited vertex and we determine if there is
                // a direct combination = USD - GBP without intermediate jumps is a direct combination
                if (visited.size() > NO_DIRECT_COMBINATION) {
                    return calculateIntermediateCurrenciesValues(visited);
                } else {
                    return visited.get(currencyTo);
                }
            }
            List<EdgeDomain> edgeDomains = rateGraph.get(currentVertexDomain);
            for (EdgeDomain edgeDomain : edgeDomains) {
                VertexDomain adjacentVertexDomain = edgeDomain.getDestination();
                String adjacentVertexId = adjacentVertexDomain.getId();
                if (!visited.containsKey(adjacentVertexId)) {
                    visited.put(adjacentVertexId, edgeDomain.getWeight());
                    queue.add(adjacentVertexDomain);
                }
            }
        }
    }
    return weight;
}
 
开发者ID:raulh82vlc,项目名称:Transactions-Viewer,代码行数:45,代码来源:GraphDomain.java

示例13: popInner

import java.util.Queue; //导入方法依赖的package包/类
private T popInner(Queue<T> queue1, Queue<T> queue2) {
    int size = queue1.size();
    for (int i = 0; i < size - 1; i++) {
        T poll = queue1.poll();
        queue2.add(poll);
    }
    return queue1.poll();
}
 
开发者ID:pop1234o,项目名称:BestPracticeApp,代码行数:9,代码来源:N7_1_StackWithTwoQueues.java

示例14: getPendingDependents

import java.util.Queue; //导入方法依赖的package包/类
@DatabaseExecutor
private Queue<MessageId> getPendingDependents(Transaction txn, MessageId m)
		throws DbException {
	Queue<MessageId> pending = new LinkedList<MessageId>();
	Map<MessageId, State> states = db.getMessageDependents(txn, m);
	for (Entry<MessageId, State> e : states.entrySet()) {
		if (e.getValue() == PENDING) pending.add(e.getKey());
	}
	return pending;
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:11,代码来源:ValidationManagerImpl.java

示例15: addNode

import java.util.Queue; //导入方法依赖的package包/类
/**
 * Adds a node to the control graph under construction.
 */
private static <P extends Position<P,A>,A extends Stage<P,A>> ControlNode addNode(
    ControlGraph graph, Map<P,ControlNode> nodeMap, P pos, Queue<P> fresh) {
    ControlNode result = nodeMap.get(pos);
    if (result == null) {
        nodeMap.put(pos, result = new ControlNode(graph, pos));
        fresh.add(pos);
        if (pos.isStart()) {
            graph.setStart(result);
        }
    }
    return result;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:16,代码来源:ControlGraph.java


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