/** * Return the value if present, otherwise return {@code other}. * * @param other the value to be returned if there is no value present * @return the value, if present, otherwise {@code other} */ public double or(double other) { return isPresent() ? value : other; }
/** * Returns an {@code OptionalShort} with the specified present value. * * @param value the value to be present * @return an {@code OptionalShort} with the value present */ public static OptionalShort of(short value) { return new OptionalShort(value); }
/** * Return the value if present, otherwise return {@code other}. * * @param other the value to be returned if there is no value present * @return the value, if present, otherwise {@code other} */ public byte or(byte other) { return isPresent() ? value : other; }
/** * Returns an {@code Optional} describing the specified value, if non-null, * otherwise returns an absent {@code Optional}. * * @param <T> the class of the value * @param value the possibly-null value to describe * @return an {@code Optional} with a present value if the specified value * is non-null, otherwise an absent {@code Optional} */ public static <T> Optional<T> ofNullable(T value) { return value == null ? (Optional<T>) absent() : of(value); }
/** * Return the contained value, if present, otherwise null. * * @return the present value, if present, otherwise null */ public T orNull() { return isPresent() ? value : null; }
/** * Return the value if present, otherwise return {@code other}. * * @param other the value to be returned if there is no value present * @return the value, if present, otherwise {@code other} */ public float or(float other) { return isPresent() ? value : other; }
/** * Return the value if present, otherwise return {@code other}. * * @param other the value to be returned if there is no value present * @return the value, if present, otherwise {@code other} */ public char or(char other) { return isPresent() ? value : other; }
/** * Return the value if present, otherwise return {@code other}. * * @param other the value to be returned if there is no value present * @return the value, if present, otherwise {@code other} */ public long or(long other) { return isPresent() ? value : other; }
/** * Return the value if present, otherwise return {@code other}. * * @param other the value to be returned if there is no value present * @return the value, if present, otherwise {@code other} */ public short or(short other) { return isPresent() ? value : other; }
/** * Return the value if present, otherwise return {@code other}. * * @param other the value to be returned if there is no value present * @return the value, if present, otherwise {@code other} */ public int or(int other) { return isPresent() ? value : other; }
/** * Returns an {@code OptionalByte} with the specified present value. * * @param value the value to be present * @return an {@code OptionalByte} with the value present */ public static OptionalByte of(byte value) { return new OptionalByte(value); }
/** * Returns an {@code OptionalFloat} with the specified present value. * * @param value the value to be present * @return an {@code OptionalFloat} with the value present */ public static OptionalFloat of(float value) { return new OptionalFloat(value); }
/** * Returns an {@code OptionalChar} with the specified present value. * * @param value the value to be present * @return an {@code OptionalChar} with the value present */ public static OptionalChar of(char value) { return new OptionalChar(value); }
/** * Returns an {@code OptionalDouble} with the specified present value. * * @param value the value to be present * @return an {@code OptionalDouble} with the value present */ public static OptionalDouble of(double value) { return new OptionalDouble(value); }
/** * Returns an {@code Optional} with the specified present non-null value. * * @param <T> the class of the value * @param value the value to be present, which must be non-null * @return an {@code Optional} with the value present * @throws IllegalArgumentException if value is null */ public static <T> Optional<T> of(T value) { return new Optional<>(value); }
/** * Returns an {@code OptionalLong} with the specified present value. * * @param value the value to be present * @return an {@code OptionalLong} with the value present */ public static OptionalLong of(long value) { return new OptionalLong(value); }
/** * Returns an {@code OptionalInt} with the specified present value. * * @param value the value to be present * @return an {@code OptionalInt} with the value present */ public static OptionalInt of(int value) { return new OptionalInt(value); }
/** * Returns the hash code value of the present value, if any, or 0 (zero) if * no value is present. * * @return hash code value of the present value or 0 if no value is present */ @Override public int hashCode() { return isPresent() ? new Byte(value).hashCode() : 0; }
/** * Returns the hash code value of the present value, if any, or 0 (zero) if * no value is present. * * @return hash code value of the present value or 0 if no value is present */ @Override public int hashCode() { return isPresent() ? value.hashCode() : 0; }