OptionalDouble (long... numbers) { double sum = 0; long count = 0; for (long x : numbers) { if (x > 0) { double v = x; sum += v; count++; } } return count > 0 ? OptionalDouble.of(sum / count) : OptionalDouble.empty(); }