/// import { InspectOptions } from 'util'; import { IEquatable, equals } from './Equality'; import { IFilterable } from './IFilterable'; import { IMappable } from './IMappable'; import { IChainable } from './IChainable'; import { Nullable } from './Nullable'; import { Undefinable } from './Undefinable'; import { IEqualityComparer } from './Equality'; import { IInspectable, inspect } from './IInspectable'; import { IInspector } from './IInspector'; /** * Error for the optional values not set */ export declare class OptionalValueNotSetError extends Error { constructor(); } /** * An object to wrap a nullable in an interface to avoid null exeptions. * * @see https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html * @see http://www.baeldung.com/java-optional */ export declare class Optional implements IEquatable>, IFilterable, IMappable, IChainable, IInspectable { private readonly _value; private readonly _equalityComparer; private readonly _inspector; /** * Creates an empty instance of Optional. No value is present for this Optional. * @param equalityComparer An optional equality comparer for the value. * @param inspector An optional inspector for the value. */ constructor(value?: undefined, equalityComparer?: IEqualityComparer, inspector?: IInspector); /** * Creates an instance of Optional describing the specified value, if defined, otherwise returns an empty Optional. * @param value A possibly null value. * @param equalityComparer An optional equality comparer for the value. * @param inspector An optional inspector for the value. */ constructor(value: Undefinable, equalityComparer?: IEqualityComparer, inspector?: IInspector); /** * Creates an instance of Optional with the specified present non-null and defined value. * @param value A non-nullable value. * @param equalityComparer An optional equality comparer for the value. * @param inspector An optional inspector for the value. */ constructor(value: T, equalityComparer?: IEqualityComparer, inspector?: IInspector); /** * Creates an instance of Optional describing the specified value, if non-null, otherwise returns an empty Optional. * @param value A possibly null value. * @param equalityComparer An optional equality comparer for the value. * @param inspector An optional inspector for the value. */ constructor(value: Nullable, equalityComparer?: IEqualityComparer, inspector?: IInspector); constructor(value: Undefinable>, equalityComparer?: IEqualityComparer, inspector?: IInspector); [equals](other: Optional): boolean; [inspect](options?: InspectOptions): string; /** * Check if the value is null. * * @returns True if there is a value present, otherwise false. */ isPresent(): boolean; /** * If a value is present, invoke the specified callback with the value, otherwise do nothing. * * @param callback The callback to invoke. */ ifPresent(callback: (value: T) => void): void; /** * If a value is present, performs the given callback with the value, otherwise performs the given empty-based callback. * * @param callback The callback to be performed, if a value is present. * @param emptyCallback The callback to be performed, if no value is present. */ ifPresentOrElse(callback: (value: T) => void, emptyCallback: () => void): void; /** * If a value is present, returns an Optional describing the value, otherwise returns an Optional produced by the supplying function. * * @param supplier The supplying function that produces an Optional to be returned. * @returns An Optional describing the value of this Optional, if a value is present, otherwise an Optional produced by the supplying function. */ or(supplier: () => Optional): Optional; /** * Return the value if not null or a default. * * @param defaultValue The default value to return. * @returns The value if present, otherwise return the default. * @description The methods orElse and orElseGet are generally preferable to this method, as they return a substitute value if the value is absent, instead of throwing an exception. */ orElse(supplier: T): T; /** * Return the value if not null or a default via a callback, to allow for lazy loading. * * @param callback The callback to invoke to get the default value to return. * @returns The value if present, otherwise return the default. */ orElseGet(callback: () => T): T; /** * Return the contained value, if present, otherwise throw an exception to be created by the provided supplier. * * @param exceptionSupplier The callback to invoke to get the error to throw. * @returns The value if present. */ orElseThrow(exceptionSupplier: () => Error): T; /** * Return the contained value, if present, otherwise return 'undefined'. * * @returns {Undefinable} */ orUndefined(): Undefinable; /** * Return the contained value, if present, otherwise return 'null'. * * @returns {Undefinable} */ orNull(): Nullable; /** * If a value is present in this Optional, returns the value, otherwise throws NoSuchElementException. * * @returns {T} The value if present. */ get(): T; filter(predicate: (value: T) => value is S): Optional; filter(predicate: (value: T) => boolean): Optional; map(callbackfn: (value: T) => U, equalityComparer?: IEqualityComparer): Optional; chain(callbackfn: (value: T) => Optional, equalityComparer?: IEqualityComparer): Optional; chain(callbackfn: (value: T) => U, equalityComparer?: IEqualityComparer): Optional; private isValuePresent; }