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


Java Deque.peekLast方法代码示例

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


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

示例1: tryAppend

import java.util.Deque; //导入方法依赖的package包/类
/**
 *  Try to append to a ProducerBatch.
 *
 *  If it is full, we return null and a new batch is created. We also close the batch for record appends to free up
 *  resources like compression buffers. The batch will be fully closed (ie. the record batch headers will be written
 *  and memory records built) in one of the following cases (whichever comes first): right before send,
 *  if it is expired, or when the producer is closed.
 */
// 查找batches集合对应队列的最后一个ProducerBatch
private RecordAppendResult tryAppend(long timestamp, byte[] key, byte[] value, Header[] headers, Callback callback, Deque<ProducerBatch> deque) {
    //拿到消息队列中的最后一个
    ProducerBatch last = deque.peekLast();
    if (last != null) {
        //调用ProducerBatch的tryAppend方法返回 FutureRecordMetadata future,MemoryRecordsBuilder中是还有空间
        FutureRecordMetadata future = last.tryAppend(timestamp, key, value, headers, callback, time.milliseconds());
        if (future == null)
            last.closeForRecordAppends();
        else
            return new RecordAppendResult(future, deque.size() > 1 || last.isFull(), false);

    }
    return null;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:24,代码来源:RecordAccumulator.java

示例2: getNodesWithTimedOutRequests

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Returns a list of nodes with pending in-flight request, that need to be timed out
 *
 * @param now current time in milliseconds
 * @param requestTimeout max time to wait for the request to be completed
 * @return list of nodes
 */
public List<String> getNodesWithTimedOutRequests(long now, int requestTimeout) {
    List<String> nodeIds = new LinkedList<>();
    for (Map.Entry<String, Deque<NetworkClient.InFlightRequest>> requestEntry : requests.entrySet()) {
        String nodeId = requestEntry.getKey();
        Deque<NetworkClient.InFlightRequest> deque = requestEntry.getValue();

        if (!deque.isEmpty()) {
            NetworkClient.InFlightRequest request = deque.peekLast();
            long timeSinceSend = now - request.sendTimeMs;
            if (timeSinceSend > requestTimeout)
                nodeIds.add(nodeId);
        }
    }

    return nodeIds;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:24,代码来源:InFlightRequests.java

示例3: getTrailingAverage

import java.util.Deque; //导入方法依赖的package包/类
private Integer getTrailingAverage(Deque<Entry<Long, Long>> list, int seconds) {
  Entry<Long,Long> latest = list.peekLast();
  Entry<Long,Long> old = list.peekFirst();
  Iterator<Entry<Long,Long>> iter = list.descendingIterator();
  while (iter.hasNext()) {
    Entry<Long,Long> e = iter.next();
    if (e.getKey() - latest.getKey() > seconds * ONE_BILLION) {
      old = e;
      break;
    }
  }

  final long oldKey = old.getKey();
  final long latestKey = latest.getKey();
  if (oldKey == latestKey) {
    return null;
  } else {
    return (int) (100 * (old.getValue() - latest.getValue()) / (oldKey - latestKey));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:21,代码来源:ThreadsStatsCollector.java

示例4: maxSlidingWindow

import java.util.Deque; //导入方法依赖的package包/类
public int[] maxSlidingWindow(int[] nums, int k) {
    int len = nums.length;
    if (len == 0) return nums;
    int[] res = new int[len - k + 1];
    
    Deque<Integer> dq = new LinkedList<Integer>();
    for (int i = 0; i < len; i++) {
    	while (!dq.isEmpty() && dq.peekLast() < nums[i])
    		dq.pollLast();
    	
    	dq.offer(nums[i]);
    	
    	if (i >= k - 1) {
    		res[i - k + 1] = dq.peek();
    		if (nums[i - k + 1] == dq.peek())
    			dq.pollFirst();
    	}
    }
	return res;
}
 
开发者ID:JoeZ-EE,项目名称:Aim2Offer,代码行数:21,代码来源:065_MaxInSlidingWindow.java

示例5: maxSlidingWindow

import java.util.Deque; //导入方法依赖的package包/类
public static int[] maxSlidingWindow(int[] nums, int k) {
    Deque<Integer> deque = new ArrayDeque<>();
    int n = nums.length;
    int[] res = new int[n - k + 1];
    for (int i = 0; i < n; i++) {
        if (!deque.isEmpty() && deque.peek() == i - k) deque.poll();
        while (!deque.isEmpty() && nums[deque.peekLast()] < nums[i]) deque.pollLast();
        deque.offer(i);
        if (i >= k - 1) {
            res[i + 1 - k] = nums[deque.peek()];
        }
    }
    return res;
}
 
开发者ID:xy1m,项目名称:PlayGround,代码行数:15,代码来源:MaxSlidingWindow.java

示例6: deleteDirectoryContents

import java.util.Deque; //导入方法依赖的package包/类
/**
 * Wipes out content of a directory starting from a given directory.
 *
 * @param directory to be cleaned
 * @param retain if true, the given directory will be retained.
 * @throws IOException
 */
public static void deleteDirectoryContents(File directory, boolean retain) throws IOException {
  if (!directory.isDirectory()) {
    throw new IOException("Not a directory: " + directory);
  }

  // avoid using guava's Queues.newArrayDeque() since this is a utility class that can be used in
  // all sorts of
  // contexts, some of which may use clashing guava versions... For example, when explore launches
  // a Hive query,
  // it includes hive-exec.jar which bundles guava 11 in its jar...
  Deque<File> stack = new ArrayDeque<>();
  stack.addAll(listFiles(directory));

  while (!stack.isEmpty()) {
    File file = stack.peekLast();
    List<File> files = listFiles(file);
    if (files.isEmpty()) {
      if (!file.delete()) {
        throw new IOException("Failed to delete file " + file);
      }
      stack.pollLast();
    } else {
      stack.addAll(files);
    }
  }

  if (!retain) {
    if (!directory.delete()) {
      throw new IOException("Failed to delete directory " + directory);
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:40,代码来源:DirUtils.java

示例7: maxSlidingWindow

import java.util.Deque; //导入方法依赖的package包/类
public int[] maxSlidingWindow(int[] nums, int k) {
    if (k == 0) {
        return new int[0];
    }

    int n = nums.length;

    int[] result = new int[n - k + 1];
    int current = 0;

    Deque<Integer> deque = new ArrayDeque<>();

    for (int i = 0; i < n; i++) {
        while (!deque.isEmpty() && deque.peek() < i - k + 1) {
            deque.poll();
        }

        while(!deque.isEmpty() && nums[deque.peekLast()] < nums[i]) {
            deque.pollLast();
        }

        deque.offer(i);

        if (i >= k - 1) { // allowing sliding window to fit in full initially
            result[current++] = nums[deque.peek()];
        }
    }

    return result;
}
 
开发者ID:viatsko,项目名称:hack,代码行数:31,代码来源:SlidingWindowMaximum.java

示例8: getLast

import java.util.Deque; //导入方法依赖的package包/类
public FormValue getLast(String name) {
    final Deque<FormValue> deque = values.get(name);
    return deque == null ? null : deque.peekLast();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:FormData.java

示例9: convertPendingTransactionsToMessages

import java.util.Deque; //导入方法依赖的package包/类
Collection<?> convertPendingTransactionsToMessages(final int maxModificationsPerBatch) {
    final Collection<VersionedExternalizableMessage> messages = new ArrayList<>();
    for (ShardDataTreeCohort cohort : dataTree.getAndClearPendingTransactions()) {
        CohortEntry cohortEntry = cohortCache.remove(cohort.getIdentifier());
        if (cohortEntry == null) {
            continue;
        }

        final Deque<BatchedModifications> newMessages = new ArrayDeque<>();
        cohortEntry.getDataTreeModification().applyToCursor(new AbstractBatchedModificationsCursor() {
            @Override
            protected BatchedModifications getModifications() {
                final BatchedModifications lastBatch = newMessages.peekLast();

                if (lastBatch != null && lastBatch.getModifications().size() >= maxModificationsPerBatch) {
                    return lastBatch;
                }

                // Allocate a new message
                final BatchedModifications ret = new BatchedModifications(cohortEntry.getTransactionId(),
                    cohortEntry.getClientVersion());
                newMessages.add(ret);
                return ret;
            }
        });

        final BatchedModifications last = newMessages.peekLast();
        if (last != null) {
            final boolean immediate = cohortEntry.isDoImmediateCommit();
            last.setDoCommitOnReady(immediate);
            last.setReady(true);
            last.setTotalMessagesSent(newMessages.size());

            messages.addAll(newMessages);

            if (!immediate) {
                switch (cohort.getState()) {
                    case CAN_COMMIT_COMPLETE:
                    case CAN_COMMIT_PENDING:
                        messages.add(new CanCommitTransaction(cohortEntry.getTransactionId(),
                            cohortEntry.getClientVersion()));
                        break;
                    case PRE_COMMIT_COMPLETE:
                    case PRE_COMMIT_PENDING:
                        messages.add(new CommitTransaction(cohortEntry.getTransactionId(),
                            cohortEntry.getClientVersion()));
                        break;
                    default:
                        break;
                }
            }
        }
    }

    return messages;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:57,代码来源:ShardCommitCoordinator.java


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