/** * If a value is present, invoke the specified consumer with the value, * otherwise invoke the function passed as the second parameter. * * @param consumer block to be executed if a value is present * @param function block to be executed if a value is absent */ public void ifPresentOrElse(DoubleConsumer consumer, Function function) { if (isPresent()) { consumer.consume(value); } else { function.call(); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise invoke the function passed as the second parameter. * * @param consumer block to be executed if a value is present * @param function block to be executed if a value is absent */ public void ifPresentOrElse(IntConsumer consumer, Function function) { if (isPresent()) { consumer.consume(value); } else { function.call(); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise invoke the function passed as the second parameter. * * @param consumer block to be executed if a value is present * @param function block to be executed if a value is absent */ public void ifPresentOrElse(ShortConsumer consumer, Function function) { if (isPresent()) { consumer.consume(value); } else { function.call(); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise invoke the function passed as the second parameter. * * @param consumer block to be executed if a value is present * @param function block to be executed if a value is absent */ public void ifPresentOrElse(Consumer<T> consumer, Function function) { if (isPresent()) { consumer.consume(value); } else { function.call(); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise invoke the function passed as the second parameter. * * @param consumer block to be executed if a value is present * @param function block to be executed if a value is absent */ public void ifPresentOrElse(ByteConsumer consumer, Function function) { if (isPresent()) { consumer.consume(value); } else { function.call(); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise invoke the function passed as the second parameter. * * @param consumer block to be executed if a value is present * @param function block to be executed if a value is absent */ public void ifPresentOrElse(CharConsumer consumer, Function function) { if (isPresent()) { consumer.consume(value); } else { function.call(); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise invoke the function passed as the second parameter. * * @param consumer block to be executed if a value is present * @param function block to be executed if a value is absent */ public void ifPresentOrElse(FloatConsumer consumer, Function function) { if (isPresent()) { consumer.consume(value); } else { function.call(); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise invoke the function passed as the second parameter. * * @param consumer block to be executed if a value is present * @param function block to be executed if a value is absent */ public void ifPresentOrElse(LongConsumer consumer, Function function) { if (isPresent()) { consumer.consume(value); } else { function.call(); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise do nothing. * * @param consumer block to be executed if a value is present */ public void ifPresent(FloatConsumer consumer) { if (isPresent()) { consumer.consume(value); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise do nothing. * * @param consumer block to be executed if a value is present */ public void ifPresent(LongConsumer consumer) { if (isPresent()) { consumer.consume(value); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise do nothing. * * @param consumer block to be executed if a value is present */ public void ifPresent(DoubleConsumer consumer) { if (isPresent()) { consumer.consume(value); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise do nothing. * * @param consumer block to be executed if a value is present */ public void ifPresent(Consumer<T> consumer) { if (isPresent()) { consumer.consume(value); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise do nothing. * * @param consumer block to be executed if a value is present */ public void ifPresent(ByteConsumer consumer) { if (isPresent()) { consumer.consume(value); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise do nothing. * * @param consumer block to be executed if a value is present */ public void ifPresent(CharConsumer consumer) { if (isPresent()) { consumer.consume(value); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise do nothing. * * @param consumer block to be executed if a value is present */ public void ifPresent(ShortConsumer consumer) { if (isPresent()) { consumer.consume(value); } }
/** * If a value is present, invoke the specified consumer with the value, * otherwise do nothing. * * @param consumer block to be executed if a value is present */ public void ifPresent(IntConsumer consumer) { if (isPresent()) { consumer.consume(value); } }
/** * Return the value if present, otherwise invoke {@code otherSupplier} and return * the result of that invocation. * * @param otherSupplier a {@code Supplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code otherSupplier.get()} * @throws IllegalArgumentException if {@code otherSupplier} is null */ public int or(IntSupplier otherSupplier) { if (otherSupplier == null) { throw new IllegalArgumentException("null may not be passed as an argument."); } return isPresent() ? value : otherSupplier.get(); }
/** * Return the value if present, otherwise invoke {@code otherSupplier} and return * the result of that invocation. * * @param otherSupplier a {@code Supplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code otherSupplier.get()} * @throws IllegalArgumentException if {@code otherSupplier} is null */ public char or(CharSupplier otherSupplier) { if (otherSupplier == null) { throw new IllegalArgumentException("null may not be passed as an argument."); } return isPresent() ? value : otherSupplier.get(); }
/** * Return the value if present, otherwise invoke {@code otherSupplier} and return * the result of that invocation. * * @param otherSupplier a {@code Supplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code otherSupplier.get()} * @throws IllegalArgumentException if {@code otherSupplier} is null */ public T or(Supplier<T> otherSupplier) { if (otherSupplier == null) { throw new IllegalArgumentException("null may not be passed as an argument; use orNull() instead."); } return isPresent() ? value : otherSupplier.get(); }
/** * Return the value if present, otherwise invoke {@code otherSupplier} and return * the result of that invocation. * * @param otherSupplier a {@code Supplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code otherSupplier.get()} * @throws IllegalArgumentException if {@code otherSupplier} is null */ public long or(LongSupplier otherSupplier) { if (otherSupplier == null) { throw new IllegalArgumentException("null may not be passed as an argument."); } return isPresent() ? value : otherSupplier.get(); }