/** * @return Retrieves the minimum update counter task from queue. */ private Item poll() { return queue.pollFirst(); }
@Nullable @Override public byte[] pollFirst() { return !isEmpty() ? treeSet.pollFirst() : null; }
public void add(T item) { items.add(item); if (items.size() > maxSize) items.pollFirst(); }
@Override public E pollFirst() { return set().pollFirst(); }
private synchronized void trimHead() { if (offsets.size() <= 1) { return; } FileOffset head = offsets.first(); FileOffset head2 = offsets.higher(head); if (head.isNextOffset(head2)) { offsets.pollFirst(); trimHead(); } return; }
sortedPartitions.add(sortedAllPartitions.pollFirst());
@Override public EventDataWrap receive() { if (pending.size() >= config.getMaxPendingMsgsPerPartition()) { return null; } EventDataWrap eventDatawrap; if (toResend.isEmpty()) { eventDatawrap = receiver.receive(); } else { eventDatawrap = toResend.pollFirst(); } if (eventDatawrap != null) { lastOffset = eventDatawrap.getMessageId().getOffset(); pending.put(lastOffset, eventDatawrap); } return eventDatawrap; }
synchronized (taskPending) { while (task == null && taskHasNoException()) { task = taskPending.pollFirst(); if (task == null) taskPending.wait(60000);
public T nextElement() { TreeValue<T> value; if (m_order == Order.ASC) value = m_treeSet.pollFirst(); else value = m_treeSet.pollLast(); if (value == null) return (null); T ret = value.getValue(); if (value.getIterator().hasNext()) { value.setValue(value.getIterator().next()); m_treeSet.add(value); } return (ret); } }
static TreeSet<UUID> add( TreeSet<UUID> a, UUID uuid, boolean reversed, int limit ) { if ( a == null ) { a = new TreeSet<UUID>( new UUIDComparator() ); } if ( uuid == null ) { return a; } // if we have less than the limit, just add it if ( a.size() < limit ) { a.add( uuid ); } else if ( reversed ) { // if reversed, we want to add more recent messages // and eject the oldest if ( UUIDComparator.staticCompare( uuid, a.first() ) > 0 ) { a.pollFirst(); a.add( uuid ); } } else { // add older messages and eject the newset if ( UUIDComparator.staticCompare( uuid, a.last() ) < 0 ) { a.pollLast(); a.add( uuid ); } } return a; }
path = queue.pollFirst();
private void processNext(int partition) { TreeSet<ConsumerRecord<String, String>> pQueue = partitionQueue.get(partition); if (pQueue != null && !pQueue.isEmpty()) { ConsumerRecord<String, String> record = pQueue.first(); messageExecutor.execute(record); inProgress.put(partition, record); pQueue.pollFirst(); } } }
@Override public Set<Color> quantize(Multiset<Color> originalColors, int maxColorCount) { TreeSet<Cluster> clusters = new TreeSet<>(new ClusterSpreadComparator()); clusters.add(new Cluster(originalColors)); while (clusters.size() < maxColorCount) { Cluster clusterWithLargestSpread = clusters.pollFirst(); clusters.addAll(clusterWithLargestSpread.split()); } Set<Color> clusterCentroids = new HashSet<>(); for (Cluster cluster : clusters) { clusterCentroids.add(Color.getCentroid(cluster.colors)); } return clusterCentroids; }
private static Set<InstanceTopicPartitionHolder> balanceAssignment( TreeSet<InstanceTopicPartitionHolder> orderedSet) { while (!isAssignmentBalanced(orderedSet)) { InstanceTopicPartitionHolder lowestInstance = orderedSet.pollFirst(); InstanceTopicPartitionHolder highestInstance = orderedSet.pollLast(); TopicPartition tpi = highestInstance.getServingTopicPartitionSet().iterator().next(); highestInstance.removeTopicPartition(tpi); lowestInstance.addTopicPartition(tpi); orderedSet.add(lowestInstance); orderedSet.add(highestInstance); } return orderedSet; }
@Override public synchronized void add(T key, long count) { Preconditions.checkNotNull(key, "key can't be null"); Preconditions.checkArgument(count >= 0, "count to add must be non-negative, got %s", count); if (count == 0) { return; } Long currentCount = counts.get(key); if (currentCount == null) { currentCount = 0L; } long updatedCount = currentCount + count; counts.put(key, updatedCount); if (topKeys.contains(key)) { topPairs.remove(new ComparablePair<Long, T>(currentCount, key)); topPairs.add(new ComparablePair<Long, T>(updatedCount, key)); } else if (topPairs.size() < k) { topPairs.add(new ComparablePair<Long, T>(updatedCount, key)); topKeys.add(key); smallestTopCount = Math.min(smallestTopCount, updatedCount); } else if (updatedCount > smallestTopCount) { ComparablePair<Long, T> smallestTopPair = topPairs.pollFirst(); topKeys.remove(smallestTopPair.getSecond()); topPairs.add(new ComparablePair<Long, T>(updatedCount, key)); topKeys.add(key); smallestTopCount = topPairs.first().getFirst(); } }
@Override public synchronized void add(Integer key, long count) { Preconditions.checkNotNull(key, "key can't be null"); Preconditions.checkElementIndex(key, counts.length, "key"); Preconditions.checkArgument(count >= 0, "count to add must be non-negative, got %s", count); if (count == 0) { return; } long currentCount = counts[key]; counts[key] += count; if (isInTop[key]) { topPairs.remove(new ComparablePair<Long, Integer>(currentCount, key)); topPairs.add(new ComparablePair<Long, Integer>(counts[key], key)); } else if (topPairs.size() < k) { topPairs.add(new ComparablePair<Long, Integer>(counts[key], key)); isInTop[key] = true; smallestTopCount = Math.min(smallestTopCount, counts[key]); } else if (counts[key] > smallestTopCount) { ComparablePair<Long, Integer> smallestTopPair = topPairs.pollFirst(); isInTop[smallestTopPair.getSecond()] = false; topPairs.add(new ComparablePair<Long, Integer>(counts[key], key)); isInTop[key] = true; smallestTopCount = topPairs.first().getFirst(); } }
flag = true; while (flag && (tmpDocs.size() > 0)){ simpleResult = tmpDocs.pollFirst(); if (this.docs.size() < maxHits) { this.docs.add(simpleResult);
flag = true; while (flag && (tmpDocs.size() > 0)){ simpleResult = tmpDocs.pollFirst(); if (this.docs.size() < maxHits) { this.docs.add(simpleResult);
flag = true; while (flag && (tmpDocs.size() > 0)){ simpleResult = tmpDocs.pollFirst(); if (this.docs.size() < maxHits) { this.docs.add(simpleResult);