java.util.stream.Stream#max ( )源码实例Demo

下面列出了java.util.stream.Stream#max ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: NNAnalytics   文件: AbstractQueryEngine.java
/**
 * Perform the find operation on a /filter endpoint call.
 *
 * @param inodes set of inodes to work on
 * @param find the find operation to perform
 * @return the result of the find operation
 */
@Override // QueryEngine
public Collection<INode> findFilter(Collection<INode> inodes, String find) {
  if (find == null || find.isEmpty()) {
    return inodes;
  }

  String[] findOps = find.split(":");
  Function<INode, Long> findToLong = getFilterFunctionToLongForINode(findOps[1]);

  long start = System.currentTimeMillis();
  Optional<INode> optional;
  try {
    Stream<INode> stream = inodes.parallelStream();
    switch (findOps[0]) {
      case "max":
        optional = stream.max(Comparator.comparingLong(findToLong::apply));
        break;
      case "min":
        optional = stream.min(Comparator.comparingLong(findToLong::apply));
        break;
      default:
        throw new IllegalArgumentException("Unknown find query type: " + findOps[0]);
    }
  } finally {
    long end = System.currentTimeMillis();
    LOG.info("Performing find: {} took: {} ms.", Arrays.asList(findOps), (end - start));
  }

  return optional.<Collection<INode>>map(Collections::singleton).orElseGet(Collections::emptySet);
}
 
源代码2 项目: crate   文件: Translog.java
/**
 * Ensures that all locations in the given stream have been synced / written to the underlying storage.
 * This method allows for internal optimization to minimize the amount of fsync operations if multiple
 * locations must be synced.
 *
 * @return Returns <code>true</code> iff this call caused an actual sync operation otherwise <code>false</code>
 */
public boolean ensureSynced(Stream<Location> locations) throws IOException {
    final Optional<Location> max = locations.max(Location::compareTo);
    // we only need to sync the max location since it will sync all other
    // locations implicitly
    if (max.isPresent()) {
        return ensureSynced(max.get());
    } else {
        return false;
    }
}