當前位置: 首頁>>代碼示例>>Java>>正文


Java Queue.size方法代碼示例

本文整理匯總了Java中java.util.Queue.size方法的典型用法代碼示例。如果您正苦於以下問題:Java Queue.size方法的具體用法?Java Queue.size怎麽用?Java Queue.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Queue的用法示例。


在下文中一共展示了Queue.size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: averageOfLevels

import java.util.Queue; //導入方法依賴的package包/類
public List<Double> averageOfLevels(TreeNode node) {
    List<Double> list = new LinkedList<>();
    if (node == null) return list;
    Queue<TreeNode> q = new LinkedList<>();
    q.offer(node);
    while (!q.isEmpty()) {
        int size = q.size();
        double sum = 0;
        int i = 0;
        while (i < size) {
            TreeNode t = q.poll();
            sum += t.val;
            if (t.left != null) q.offer(t.left);
            if (t.right != null) q.offer(t.right);
            i++;
        }
        list.add(sum / size);
    }
    return list;
}
 
開發者ID:bakhodirsbox,項目名稱:AlgoCS,代碼行數:21,代碼來源:AverageLevelsBin_637.java

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

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

示例4: createEmojiAndTextNode

import java.util.Queue; //導入方法依賴的package包/類
/**
 * 將字符串解析分離成emoji圖片節點和文本節點
 * @param input 輸入字符串
 * @return
 */
public static Node[] createEmojiAndTextNode(String input) {
	Queue<Object> queue = EmojiHandler.getInstance().toEmojiAndText(input);
	Node[] nodes = new Node[queue.size()];
	int i = 0;
	while (!queue.isEmpty()) {
		Object ob = queue.poll();
		if (ob instanceof String) {
			String text = (String) ob;
			nodes[i++] = createTextNode(text);
		} else if (ob instanceof Emoji) {
			Emoji emoji = (Emoji) ob;
			nodes[i++] = createEmojiNode(emoji, 24, 10);
		}
	}
	return nodes;
}
 
開發者ID:Laity000,項目名稱:ChatRoom-JavaFX,代碼行數:22,代碼來源:EmojiDisplayer.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: size

import java.util.Queue; //導入方法依賴的package包/類
@Override
public int size() {
    int total = 0;
    for (final Queue queue: messageBuffer.values()) {
        total += queue.size();
    }
    return total;
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:9,代碼來源:RoundRobinBuffer.java

示例7: search

import java.util.Queue; //導入方法依賴的package包/類
public static Node search(Node root, int taskId) {
  Queue<Node> queue = new LinkedList<>();
  queue.add(root);

  while (queue.size() > 0) {
    Node current = queue.poll();
    if (taskId >= 0 && current.getTaskId() == taskId) {
      return current;
    } else {
      queue.addAll(current.getChildren());
    }
  }

  return null;
}
 
開發者ID:DSC-SPIDAL,項目名稱:twister2,代碼行數:16,代碼來源:BinaryTree.java

示例8: countBuffersOfSize

import java.util.Queue; //導入方法依賴的package包/類
/**
 * Return the number of available buffers of a given size.
 * This is used only for tests.
 */
@VisibleForTesting
int countBuffersOfSize(int size) {
  Queue<WeakReference<ByteBuffer>> list = buffersBySize.get(size);
  if (list == null) {
    return 0;
  }
  
  return list.size();
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:14,代碼來源:DirectBufferPool.java

示例9: count

import java.util.Queue; //導入方法依賴的package包/類
public int count() {
    Queue<Object> q = this.queue;
    if (q == null) {
        return 0;
    }
    return q.size();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:8,代碼來源:RxRingBuffer.java

示例10: computeOperations

import java.util.Queue; //導入方法依賴的package包/類
/**
 * Compute Operations with values
 */
protected float computeOperations(Queue<Float> values, Queue<String> operations) {
    String operation;
    float calculation = 0;
    // base case when no operators on screen
    if (operations.size() == 0 && values.size() == 1) {
        return values.remove();
    }
    int i = 0;
    while (operations.size() > 0) {
        operation = operations.remove();
        switch (operation) {
            case MINUS_CHAR:
                //first iteration two values can be used at the same time
                if (i == 0 && values.size() >= 2) {
                    calculation = computeSubsctraction(values.remove(), values.remove());
                } else if (values.size() > 0) {
                    calculation = computeSubsctraction(calculation, values.remove());
                }
                break;
            case PLUS_CHAR:
            default:
                //first iteration two values can be used at the same time
                if (i == 0 && values.size() >= 2) {
                    calculation = computeAddition(values.remove(), values.remove());
                } else if (values.size() > 0) {
                    calculation = computeAddition(calculation, values.remove());
                }
                break;
        }
        i++;
    }
    return calculation;
}
 
開發者ID:raulh82vlc,項目名稱:SimpleCalculator,代碼行數:37,代碼來源:OperationsStrategyImpl.java

示例11: getGameElementCount

import java.util.Queue; //導入方法依賴的package包/類
@Override
public synchronized int getGameElementCount() {
	int size = 0;
	for (Queue<GameElement> queue : this.gameElements) {
		size += queue.size();
	}
	return size;
}
 
開發者ID:rekit-group,項目名稱:rekit-game,代碼行數:9,代碼來源:Scene.java

示例12: bfsTraverse

import java.util.Queue; //導入方法依賴的package包/類
/**
 * <strong>使用廣度優先搜索收集</strong>當前實體及其所有子孫實體到集合,葉子實體排在最前麵<br/>
 * 這樣才能保證先刪除子孫節點,後刪除父節點,避免違反外鍵約束
 * @param currentEntity 存放當前實體及其所有子孫實體的集合
 * @param treeEntities 所有實體的集合
 * @return 當前實體及其所有子孫實體的集合,葉子實體排在集合最前麵
 */
@SuppressWarnings("unchecked")
@Transactional
private LinkedList<SelfReference<T>> bfsTraverse(SelfReference<T> currentEntity, LinkedList<SelfReference<T>> treeEntities) {

    // 無法獲取子孫類目時,在事務中重新獲取當前節點
    try {
        currentEntity.getChildren().size();
    } catch (LazyInitializationException e) {
        ID id = (ID) ((BaseEntity)currentEntity).getId();
        currentEntity = (SelfReference<T>) findOne(id);
    }

    // 隊列,用於廣度優先遍曆。每一時刻,隊列所包含的節點是那些本身已經被訪問,而它的鄰居(這裏即子節點)還有未被訪問的節點
    Queue<SelfReference<T>> queue = new ArrayDeque<>();
    treeEntities.addFirst(currentEntity); // 對當前遍曆到的元素執行的操作:加在頭部,後續用於刪除節點(避免違反外鍵約束)
    queue.add(currentEntity); // 加在尾部

    while (queue.size() != 0) { // 直到隊列為空
        SelfReference<T> parent = queue.remove(); // 移除在隊列頭部的節點

        if(parent.getChildren().size() != 0) {
            parent.getChildren().forEach(child -> {
                treeEntities.addFirst((SelfReference<T>) child); // 對當前遍曆到的元素執行的操作:加在頭部
                queue.add((SelfReference<T>) child); // 加在尾部
            });
        }
    }

    return treeEntities;
}
 
開發者ID:chaokunyang,項目名稱:amanda,代碼行數:38,代碼來源:AbstractSelfReferenceRepository.java

示例13: remove

import java.util.Queue; //導入方法依賴的package包/類
private static void remove(Iterator<Integer> it,
                           Queue<Integer> q) {
    int size = q.size();
    it.remove();
    removeIsCurrentlyIllegal(it);
    equal(size, q.size()+1);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:ForgetMeNot.java

示例14: onReceiveComplete

import java.util.Queue; //導入方法依賴的package包/類
@Override
  public void onReceiveComplete(int id, int e, MPIBuffer buffer) {
    lock.lock();
    try {
      // we need to try to build the message here, we may need many more messages to complete
//      LOG.info(String.format("%d received message from %d", executor, id));
      MPIMessage currentMessage = currentMessages.get(id);
      ByteBuffer byteBuffer = buffer.getByteBuffer();
      byteBuffer.position(buffer.getSize());
      byteBuffer.flip();
      if (currentMessage == null) {
        currentMessage = new MPIMessage(id, type, MPIMessageDirection.IN, this);
        if (isKeyed) {
          currentMessage.setKeyType(keyType);
        }
        currentMessages.put(id, currentMessage);
        MessageHeader header = messageDeSerializer.buildHeader(buffer, e);
//        LOG.info(String.format("%d header source %d length %d", executor,
//            header.getSourceId(), header.getLength()));
        currentMessage.setHeader(header);
        currentMessage.setHeaderSize(16);
      }
      // lets rewind to 0
      currentMessage.addBuffer(buffer);
      currentMessage.build();

      if (currentMessage.isComplete()) {
//        LOG.info(String.format("%d completed recv ", executor));
        currentMessages.remove(id);
        Queue<MPIMessage> deserializeQueue = pendingReceiveDeSerializations.get(id);
        if (!deserializeQueue.offer(currentMessage)) {
          throw new RuntimeException(executor + " We should have enough space: "
              + deserializeQueue.size());
        }
      }
    } finally {
      lock.unlock();
    }
  }
 
開發者ID:DSC-SPIDAL,項目名稱:twister2,代碼行數:40,代碼來源:MPIDataFlowOperation.java

示例15: takeQueue

import java.util.Queue; //導入方法依賴的package包/類
private static <V> List<V> takeQueue(Queue<V> queue) {
    int size = queue.size();

    if (size == 0) {
        return null;
    }
    List<V> result = new ArrayList<>(size);

    for (int i = 0; i < size; i++) {
        result.add(queue.poll());
    }
    return result;
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:14,代碼來源:StatisticsUpdater.java


注:本文中的java.util.Queue.size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。