@SuppressWarnings("EqualsBetweenInconvertibleTypes") @Test public void testEquals() { assertEquals(OptionalInt.empty(), OptionalInt.empty()); assertNotEquals(OptionalInt.empty(), Optional.empty()); assertEquals(OptionalInt.of(42), OptionalInt.of(42)); assertNotEquals(OptionalInt.of(41), OptionalInt.of(42)); assertNotEquals(OptionalInt.of(0), OptionalInt.empty()); }
@Override public boolean equals(Object obj) { if(this == obj) { return true; } if(!(obj instanceof OptionalInt)) { return false; } OptionalInt other = (OptionalInt) obj; return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent; }
OptionalInt { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(!(obj instanceof OptionalInt)) { return false; } OptionalInt other = (OptionalInt) obj; return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent; } }
OptionalInt { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(!(obj instanceof OptionalInt)) { return false; } OptionalInt other = (OptionalInt) obj; return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent; } private  OptionalInt(); private  OptionalInt(int value); }
OptionalInt { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(!(obj instanceof OptionalInt)) { return false; } OptionalInt other = (OptionalInt) obj; return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent; } 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 { @Override public boolean equals(Object obj) { if(this == obj) { return true; } if(!(obj instanceof OptionalInt)) { return false; } OptionalInt other = (OptionalInt) obj; return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent; } 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();  }