Java Code Examples for java.util.stream.Stream#max()

The following examples show how to use java.util.stream.Stream#max() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractQueryEngine.java    From NNAnalytics with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: Translog.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}