# OptionalDouble

public final class **OptionalDouble** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
A container object which may or may not contain a `double` value.
If a value is present, `isPresent()` will return `true` and
`getAsDouble()` will return the value.

Additional methods that depend on the presence or absence of a contained
value are provided, such as `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#orElse(double)`
(return a default value if value not present) and
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#ifPresent(java.util.function.DoubleConsumer)` (execute a block
of code if the value is present).

### Public Method Summary

|---|---|
| static [OptionalDouble](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html) | [empty](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#empty())() Returns an empty `OptionalDouble` instance. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Indicates whether some other object is "equal to" this OptionalDouble. |
| double | [getAsDouble](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#getAsDouble())() If a value is present in this `OptionalDouble`, returns the value, otherwise throws `NoSuchElementException`. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#hashCode())() Returns the hash code value of the present value, if any, or 0 (zero) if no value is present. |
| void | [ifPresent](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#ifPresent(java.util.function.DoubleConsumer))([DoubleConsumer](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/DoubleConsumer.html) consumer) Have the specified consumer accept the value if a value is present, otherwise do nothing. |
| boolean | [isPresent](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#isPresent())() Return `true` if there is a value present, otherwise `false`. |
| static [OptionalDouble](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html) | [of](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#of(double))(double value) Return an `OptionalDouble` with the specified value present. |
| double | [orElse](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#orElse(double))(double other) Return the value if present, otherwise return `other`. |
| double | [orElseGet](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#orElseGet(java.util.function.DoubleSupplier))([DoubleSupplier](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/DoubleSupplier.html) other) Return the value if present, otherwise invoke `other` and return the result of that invocation. |
| \<X extends [Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html)\> double | [orElseThrow](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#orElseThrow(java.util.function.Supplier<X>))([Supplier](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/Supplier.html)\<X\> exceptionSupplier) Return the contained value, if present, otherwise throw an exception to be created by the provided supplier. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#toString())() Returns a string containing a concise, human-readable description of this object. Returns a non-empty string representation of this object suitable for debugging. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Methods

#### public static [OptionalDouble](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html)
**empty**
()

Returns an empty `OptionalDouble` instance. No value is present for this
OptionalDouble.

##### Returns

- an empty `OptionalDouble`.

#### public boolean
**equals**
([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj)

Indicates whether some other object is "equal to" this OptionalDouble. The
other object is considered equal if:

- it is also an `OptionalDouble` and;
- both instances have no value present or;
- the present values are "equal to" each other via `Double.compare() == 0`.

<br />

##### Parameters

| obj | an object to be tested for equality |
|---|---|

##### Returns

- {code true} if the other object is "equal to" this object otherwise `false`

#### public double
**getAsDouble**
()

If a value is present in this `OptionalDouble`, returns the value,
otherwise throws `NoSuchElementException`.

##### Returns

- the value held by this `OptionalDouble`

##### Throws

| [NoSuchElementException](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/NoSuchElementException.html) | if there is no value present |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html#isPresent()`

#### public int
**hashCode**
()

Returns the hash code value of the present value, if any, or 0 (zero) if
no value is present.

##### Returns

- hash code value of the present value or 0 if no value is present

#### public void
**ifPresent**
([DoubleConsumer](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/DoubleConsumer.html) consumer)

Have the specified consumer accept the value if a value is present,
otherwise do nothing.

##### Parameters

| consumer | block to be executed if a value is present |
|---|---|

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if value is present and `consumer` is null |
|---|---|

#### public boolean
**isPresent**
()

Return `true` if there is a value present, otherwise `false`.

##### Returns

- `true` if there is a value present, otherwise `false`

#### public static [OptionalDouble](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/OptionalDouble.html)
**of**
(double value)

Return an `OptionalDouble` with the specified value present.

##### Parameters

| value | the value to be present |
|---|---|

##### Returns

- an `OptionalDouble` with the value present

#### public double
**orElse**
(double other)

Return the value if present, otherwise return `other`.

##### Parameters

| other | the value to be returned if there is no value present |
|---|---|

##### Returns

- the value, if present, otherwise `other`

#### public double
**orElseGet**
([DoubleSupplier](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/DoubleSupplier.html) other)

Return the value if present, otherwise invoke `other` and return
the result of that invocation.

##### Parameters

| other | a `DoubleSupplier` whose result is returned if no value is present |
|---|---|

##### Returns

- the value if present otherwise the result of `other.getAsDouble()`

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if value is not present and `other` is null |
|---|---|

#### public double
**orElseThrow**
([Supplier](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/function/Supplier.html)\<X\> exceptionSupplier)

Return the contained value, if present, otherwise throw an exception
to be created by the provided supplier.

##### Parameters

| exceptionSupplier | The supplier which will return the exception to be thrown |
|---|---|

##### Returns

- the present value

##### Throws

|   | if there is no value present |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if no value is present and `exceptionSupplier` is null |
| [Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) |   |
|---|---|

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**toString**
()

Returns a string containing a concise, human-readable description of this
object. Subclasses are encouraged to override this method and provide an
implementation that takes into account the object's type and data. The
default implementation is equivalent to the following expression:

```
   getClass().getName() + '@' + Integer.toHexString(hashCode())
```

See [Writing a useful
`toString` method](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#writing_toString)
if you intend implementing your own `toString` method.

Returns a non-empty string representation of this object suitable for
debugging. The exact presentation format is unspecified and may vary
between implementations and versions.

##### Returns

- the string representation of this instance