Options
All
  • Public
  • Public/Protected
  • All
Menu

Implementation of the Java 8+ Optional class. Documentation mostly copied from Javadoc

Type parameters

  • T

    Type of the stored value.

Hierarchy

  • Optional

Methods

filter

If a value is present and the value matches the given predicate return an Optional describing the value, otherwise return an empty Optional.

Parameters

Returns Optional<T>

Optional containing the original value or empty. Based on original existence and passing filter.

flatMap

If a value is present, apply the provided Optional-bearing mapping function to it, return that result, otherwise return an empty Optional.

Type parameters

  • S

    The new value's type.

Parameters

Returns Optional<S>

A new Optional containing the transformed value or empty.

get

  • get(): T

If a value is present in this Optional, returns the value, otherwise throws Error.

Returns T

The stored value.

ifPresent

  • ifPresent(consumer: Consumer<T>): void

If a value is present, invoke the specified consumer with the value, otherwise do nothing.

Parameters

  • consumer: Consumer<T>

    Method that will be provided with Optional's value if it's present.

Returns void

isPresent

  • isPresent(): boolean

Returns if the Optional contains a value.

Returns boolean

true if there is a value present, otherwise false.

map

If a value is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result.

Type parameters

  • S

    The new value's type.

Parameters

  • mapper: Mapper<T, S>

    Method to transform the Optional's value from and returns a new value.

Returns Optional<S>

A new Optional containing the transformed value or empty.

orElse

  • orElse(other: T): T

Return the value if present, otherwise return other.

Parameters

  • other: T

    Value to be returned if Optional does not contain a value.

Returns T

Either the Optional's value or, if it doesn't exist, the provided value.

orElseGet

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

Parameters

  • getValue: Provider<T>

    Method that provides a value if Optional does not contain a value.

Returns T

Either the Optional's value or, if it doesn't exist, the value from the provided method.

orElseThrow

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

Parameters

  • errProvider: Provider<Error>

    Method provides an error that will be throw if the Optional doesn't contain a value.

Returns T

The Optional's value.

Static empty

Returns an Optional that is empty.

Type parameters

  • T

Returns Optional<T>

Static of

Returns an Optional with the given value.

Type parameters

  • T

Parameters

  • value: T

    Stored value.

Returns Optional<T>

  • Inherited
  • Protected
  • Private
  • Static
  • Module
  • Object
  • Property
  • Function
  • Variable
  • Index
  • Type
  • Class
  • Interface
  • Enum
  • Constructor
  • Getter/Setter
Made with ❤️ by pirix-gh. Documentation generated by TypeDoc.