Refine search
/** * Returns the last element of the specified stream, or {@link OptionalInt#empty} if the stream is * empty. * * <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This * method's runtime will be between O(log n) and O(n), performing better on <a * href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a> * streams. * * @see IntStream#findFirst() * @throws NullPointerException if the last element of the stream is null */ public static OptionalInt findLast(IntStream stream) { // findLast(Stream) does some allocation, so we might as well box some more java.util.Optional<Integer> boxedLast = findLast(stream.boxed()); return boxedLast.isPresent() ? OptionalInt.of(boxedLast.get()) : OptionalInt.empty(); }
public static OptionalInt getConcurrentLifespansPerNode(Session session) { Integer result = session.getSystemProperty(CONCURRENT_LIFESPANS_PER_NODE, Integer.class); if (result == 0) { return OptionalInt.empty(); } else { checkArgument(result > 0, "Concurrent lifespans per node must be positive if set to non-zero"); return OptionalInt.of(result); } }
/** * Parses the specified value into an optional unless it is {@code null}, * in which case an empty optional is returned. * * @param value the value (or null) * @return the wrapped optional */ public static OptionalInt parseInt(String value) { if (value == null) { return OptionalInt.empty(); } else { return OptionalInt.of(Integer.parseInt(value)); } }