@Test public void testMap() { final IntUnaryOperator negatorFunction = new IntUnaryOperator() { @Override public int applyAsInt(int operand) { return -operand; } }; OptionalInt result; result = OptionalInt.empty().map(negatorFunction); assertThat(result, isEmpty()); result = OptionalInt.of(10).map(negatorFunction); assertThat(result, hasValue(-10)); }
@NotNull public OptionalInt map(@NotNull IntUnaryOperator mapper) { if (!isPresent()) return empty(); return OptionalInt.of(mapper.applyAsInt(value)); }
OptionalInt { @NotNull public OptionalInt map(@NotNull IntUnaryOperator mapper) { if (!isPresent()) return empty(); return OptionalInt.of(mapper.applyAsInt(value)); } }
OptionalInt { @NotNull public OptionalInt map(@NotNull IntUnaryOperator mapper) { if (!isPresent()) return empty(); return OptionalInt.of(mapper.applyAsInt(value)); } private  OptionalInt(); private  OptionalInt(int value); }
OptionalInt { @NotNull public OptionalInt map(@NotNull IntUnaryOperator mapper) { if (!isPresent()) return empty(); return OptionalInt.of(mapper.applyAsInt(value)); } private  OptionalInt(); private  OptionalInt(int value); @NotNull static OptionalInt empty(); @NotNull static OptionalInt of(int value); @NotNull static OptionalInt ofNullable(@Nullable Integer value); int getAsInt(); boolean isPresent(); boolean isEmpty(); void ifPresent(@NotNull IntConsumer consumer); void ifPresentOrElse(@NotNull IntConsumer consumer, @NotNull Runnable emptyAction); @NotNull OptionalInt executeIfPresent(@NotNull IntConsumer consumer); @NotNull OptionalInt executeIfAbsent(@NotNull Runnable action); @Nullable R custom(@NotNull Function<OptionalInt, R> function); @NotNull OptionalInt filter(@NotNull IntPredicate predicate); @NotNull OptionalInt filterNot(@NotNull IntPredicate predicate); @NotNull OptionalInt map(@NotNull IntUnaryOperator mapper); @NotNull Optional<U> mapToObj(@NotNull IntFunction<U> mapper); @NotNull OptionalLong mapToLong(@NotNull IntToLongFunction mapper); @NotNull OptionalDouble mapToDouble(@NotNull IntToDoubleFunction mapper); @NotNull IntStream stream(); @NotNull OptionalInt or(@NotNull Supplier<OptionalInt> supplier); int orElse(int other); int orElseGet(@NotNull IntSupplier other); int orElseThrow(); int orElseThrow(@NotNull Supplier<X> exceptionSupplier); @Override boolean equals(Object obj); @Override int hashCode(); @NotNull @Override String toString(); }
OptionalInt { @NotNull public OptionalInt map(@NotNull IntUnaryOperator mapper) { if (!isPresent()) return empty(); return OptionalInt.of(mapper.applyAsInt(value)); } private  OptionalInt(); private  OptionalInt(int value); @NotNull static OptionalInt empty(); @NotNull static OptionalInt of(int value); @NotNull static OptionalInt ofNullable(@Nullable Integer value); int getAsInt(); boolean isPresent(); boolean isEmpty(); void ifPresent(@NotNull IntConsumer consumer); void ifPresentOrElse(@NotNull IntConsumer consumer, @NotNull Runnable emptyAction); @NotNull OptionalInt executeIfPresent(@NotNull IntConsumer consumer); @NotNull OptionalInt executeIfAbsent(@NotNull Runnable action); @Nullable R custom(@NotNull Function<OptionalInt, R> function); @NotNull OptionalInt filter(@NotNull IntPredicate predicate); @NotNull OptionalInt filterNot(@NotNull IntPredicate predicate); @NotNull OptionalInt map(@NotNull IntUnaryOperator mapper); @NotNull Optional<U> mapToObj(@NotNull IntFunction<U> mapper); @NotNull OptionalLong mapToLong(@NotNull IntToLongFunction mapper); @NotNull OptionalDouble mapToDouble(@NotNull IntToDoubleFunction mapper); @NotNull IntStream stream(); @NotNull OptionalInt or(@NotNull Supplier<OptionalInt> supplier); int orElse(int other); int orElseGet(@NotNull IntSupplier other); int orElseThrow(); int orElseThrow(@NotNull Supplier<X> exceptionSupplier); @Override boolean equals(Object obj); @Override int hashCode(); @NotNull @Override String toString();  }