All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.landawn.abacus.util.u Maven / Gradle / Ivy

Go to download

A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.

There is a newer version: 2.1.12
Show newest version
/*
 * Copyright (c) 2019, Haiyang Li.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.landawn.abacus.util;

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;

import com.landawn.abacus.util.function.Supplier;

/**
 * The Class u.
 */
public class u {

    /**
     * Instantiates a new u.
     */
    private u() {
        // utility class
    }

    /**
     * The Class Optional.
     *
     * @param 
     */
    public static final class Optional {

        /** Presents {@code Boolean.TRUE}. */
        public static final Optional TRUE = new Optional<>(Boolean.TRUE);

        /** Presents {@code Boolean.FALSE}. */
        public static final Optional FALSE = new Optional<>(Boolean.FALSE);

        /** The Constant EMPTY. */
        private static final Optional EMPTY = new Optional<>();

        /** The value. */
        private final T value;

        /**
         * Instantiates a new optional.
         */
        private Optional() {
            this.value = null;
        }

        /**
         * Instantiates a new optional.
         *
         * @param value
         */
        private Optional(T value) {
            this.value = N.checkArgNotNull(value);
        }

        /**
         *
         * @param 
         * @return
         */
        public static  Optional empty() {
            return (Optional) EMPTY;
        }

        /**
         *
         * @param 
         * @param value
         * @return
         */
        public static  Optional of(T value) {
            return new Optional<>(value);
        }

        /**
         *
         * @param 
         * @param value
         * @return
         */
        public static  Optional ofNullable(T value) {
            if (value == null) {
                return empty();
            }

            return new Optional<>(value);
        }

        /**
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public T get() throws NoSuchElementException {
            return orElseThrow();
        }

        /**
         * Checks if is present.
         *
         * @return true, if is present
         */
        public boolean isPresent() {
            return value != null;
        }

        /**
         * Checks if is empty.
         *
         * @return true, if is empty
         */
        public boolean isEmpty() {
            return value == null;
        }

        /**
         *
         * @param 
         * @param action
         * @return itself
         * @throws E the e
         */
        public  Optional ifPresent(Throwables.Consumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isPresent()) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If present or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return itself
         * @throws E the e
         * @throws E2 the e2
         */
        public  Optional ifPresentOrElse(Throwables.Consumer action,
                Throwables.Runnable emptyAction) throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isPresent()) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  Optional filter(Throwables.Predicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isPresent() && predicate.test(value)) {
                return this;
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable map(final Throwables.Function mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return Nullable. of(mapper.apply(value));
            } else {
                return Nullable. empty();
            }
        }

        /**
         * Map to boolean.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalBoolean mapToBoolean(final Throwables.ToBooleanFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalBoolean.of(mapper.applyAsBoolean(value));
            } else {
                return OptionalBoolean.empty();
            }
        }

        /**
         * Map to char.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalChar mapToChar(final Throwables.ToCharFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalChar.of(mapper.applyAsChar(value));
            } else {
                return OptionalChar.empty();
            }
        }

        /**
         * Map to byte.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalByte mapToByte(final Throwables.ToByteFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalByte.of(mapper.applyAsByte(value));
            } else {
                return OptionalByte.empty();
            }
        }

        /**
         * Map to short.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalShort mapToShort(final Throwables.ToShortFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalShort.of(mapper.applyAsShort(value));
            } else {
                return OptionalShort.empty();
            }
        }

        /**
         * Map to int.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalInt mapToInt(final Throwables.ToIntFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalInt.of(mapper.applyAsInt(value));
            } else {
                return OptionalInt.empty();
            }
        }

        /**
         * Map to long.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalLong mapToLong(final Throwables.ToLongFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalLong.of(mapper.applyAsLong(value));
            } else {
                return OptionalLong.empty();
            }
        }

        /**
         * Map to float.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalFloat mapToFloat(final Throwables.ToFloatFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalFloat.of(mapper.applyAsFloat(value));
            } else {
                return OptionalFloat.empty();
            }
        }

        /**
         * Map to double.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalDouble mapToDouble(final Throwables.ToDoubleFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalDouble.of(mapper.applyAsDouble(value));
            } else {
                return OptionalDouble.empty();
            }
        }

        /**
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Optional flatMap(Throwables.Function, E> mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        public boolean contains(final T element) {
            return isPresent() && N.equals(this.value, element);
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  Optional or(Throwables.Supplier, E> supplier) throws E {
            N.checkArgNotNull(supplier, "supplier");

            if (isPresent()) {
                return this;
            } else {
                return Objects.requireNonNull((Optional) supplier.get());
            }
        }

        /**
         *
         * @return
         */
        public T orNull() {
            return isPresent() ? value : null;
        }

        /**
         *
         * @param other
         * @return
         */
        public T orElse(T other) {
            return isPresent() ? value : other;
        }

        /**
         * Or else get.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  T orElseGet(Throwables.Supplier other) throws E {
            if (isPresent()) {
                return value;
            } else {
                return other.get();
            }
        }

        //    public T orElseNull() {
        //        return isPresent() ? value : null;
        //    }

        /**
         * Or else throw.
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public T orElseThrow() throws NoSuchElementException {
            if (isPresent()) {
                return value;
            } else {
                throw new NoSuchElementException("No value is present");
            }
        }

        /**
         * Or else throw.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  T orElseThrow(Supplier exceptionSupplier) throws X {
            if (isPresent()) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         *
         * @return
         */
        public List toList() {
            if (isPresent()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         *
         * @return
         */
        public Set toSet() {
            if (isPresent()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To immutable list.
         *
         * @return
         */
        public ImmutableList toImmutableList() {
            if (isPresent()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList. empty();
            }
        }

        /**
         * To immutable set.
         *
         * @return
         */
        public ImmutableSet toImmutableSet() {
            if (isPresent()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet. empty();
            }
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }

            if (obj instanceof Optional) {
                final Optional other = (Optional) obj;

                return N.equals(value, other.value);
            }

            return false;
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return N.hashCode(isPresent()) * 31 + N.hashCode(value);
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (isPresent()) {
                return String.format("Optional[%s]", N.toString(value));
            }

            return "Optional.empty";
        }
    }

    /**
     * The Class OptionalBoolean.
     */
    public static final class OptionalBoolean implements Comparable {

        /** Presents {@code true}. */
        public static final OptionalBoolean TRUE = new OptionalBoolean(Boolean.TRUE);

        /** Presents {@code true}. */
        public static final OptionalBoolean FALSE = new OptionalBoolean(Boolean.FALSE);

        /** The Constant EMPTY. */
        private static final OptionalBoolean EMPTY = new OptionalBoolean();

        /** The value. */
        private final boolean value;

        /** The is present. */
        private final boolean isPresent;

        /**
         * Instantiates a new optional boolean.
         */
        private OptionalBoolean() {
            this.value = false;
            this.isPresent = false;
        }

        /**
         * Instantiates a new optional boolean.
         *
         * @param value
         */
        private OptionalBoolean(boolean value) {
            this.value = value;
            this.isPresent = true;
        }

        /**
         *
         * @return
         */
        public static OptionalBoolean empty() {
            return EMPTY;
        }

        /**
         *
         * @param value
         * @return
         */
        public static OptionalBoolean of(boolean value) {
            return value ? TRUE : FALSE;
        }

        /**
         *
         * @param val
         * @return
         */
        public static OptionalBoolean ofNullable(Boolean val) {
            if (val == null) {
                return empty();
            } else {
                return of(val);
            }
        }

        /**
         *
         * @return true, if successful
         * @throws NoSuchElementException the no such element exception
         */
        public boolean get() throws NoSuchElementException {
            return orElseThrow();
        }

        /**
         * Checks if is present.
         *
         * @return true, if is present
         */
        public boolean isPresent() {
            return isPresent;
        }

        /**
         *
         * @param 
         * @param action
         * @return
         * @throws E the e
         */
        public  OptionalBoolean ifPresent(Throwables.BooleanConsumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isPresent) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If present or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return
         * @throws E the e
         * @throws E2 the e2
         */
        public  OptionalBoolean ifPresentOrElse(Throwables.BooleanConsumer action,
                Throwables.Runnable emptyAction) throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isPresent) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  OptionalBoolean filter(Throwables.BooleanPredicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isPresent && predicate.test(value)) {
                return this;
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalBoolean map(final Throwables.BooleanUnaryOperator mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalBoolean.of(mapper.applyAsBoolean(value));
            } else {
                return empty();
            }
        }

        /**
         * Map to obj.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable mapToObj(final Throwables.BooleanFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Nullable.of(mapper.apply(value));
            } else {
                return Nullable. empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalBoolean flatMap(Throwables.BooleanFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  OptionalBoolean or(Throwables.Supplier supplier) throws E {
            if (isPresent) {
                return this;
            } else {
                return Objects.requireNonNull(supplier.get());
            }
        }

        /**
         *
         * @return true, if successful
         */
        public boolean orFalse() {
            return isPresent ? value : false;
        }

        //    public boolean orElseFalse() {
        //        return isPresent ? value : false;
        //    }

        /**
         *
         * @return true, if successful
         */
        public boolean orTrue() {
            return isPresent ? value : true;
        }

        //    public boolean orElseTrue() {
        //        return isPresent ? value : true;
        //    }

        /**
         * Or else throw.
         *
         * @return true, if successful
         * @throws NoSuchElementException the no such element exception
         */
        public boolean orElseThrow() throws NoSuchElementException {
            if (isPresent) {
                return value;
            } else {
                throw new NoSuchElementException("No value present");
            }
        }

        /**
         *
         * @param other
         * @return true, if successful
         */
        public boolean orElse(boolean other) {
            return isPresent ? value : other;
        }

        /**
         * Or else get.
         *
         * @param 
         * @param other
         * @return true, if successful
         * @throws E the e
         */
        public  boolean orElseGet(Throwables.BooleanSupplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isPresent) {
                return value;
            } else {
                return other.getAsBoolean();
            }
        }

        /**
         * Or else throw.
         *
         * @param 
         * @param exceptionSupplier
         * @return true, if successful
         * @throws X the x
         */
        public  boolean orElseThrow(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isPresent) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         *
         * @return
         */
        public List toList() {
            if (isPresent()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         *
         * @return
         */
        public Set toSet() {
            if (isPresent()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To immutable list.
         *
         * @return
         */
        public ImmutableList toImmutableList() {
            if (isPresent()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList. empty();
            }
        }

        /**
         * To immutable set.
         *
         * @return
         */
        public ImmutableSet toImmutableSet() {
            if (isPresent()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet. empty();
            }
        }

        /**
         *
         * @return
         */
        public Optional boxed() {
            if (isPresent) {
                return Optional.of(value);
            } else {
                return Optional. empty();
            }
        }

        /**
         *
         * @param optional
         * @return
         */
        @Override
        public int compareTo(OptionalBoolean optional) {
            if (optional == null || optional.isPresent == false) {
                return isPresent ? 1 : 0;
            }

            if (isPresent == false) {
                return -1;
            }

            return Boolean.compare(this.get(), optional.get());
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }

            if (obj instanceof OptionalBoolean) {
                final OptionalBoolean other = (OptionalBoolean) obj;

                return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent;
            }

            return false;
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return N.hashCode(isPresent) * 31 + N.hashCode(value);
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (isPresent) {
                return String.format("OptionalBoolean[%s]", value);
            }

            return "OptionalBoolean.empty";
        }
    }

    /**
     * The Class OptionalChar.
     */
    public static final class OptionalChar implements Comparable {

        /** The Constant EMPTY. */
        private static final OptionalChar EMPTY = new OptionalChar();

        /** The Constant CHAR_0. */
        private static final OptionalChar CHAR_0 = new OptionalChar(N.CHAR_0);

        /** The value. */
        private final char value;

        /** The is present. */
        private final boolean isPresent;

        /**
         * Instantiates a new optional char.
         */
        private OptionalChar() {
            this.value = 0;
            this.isPresent = false;
        }

        /**
         * Instantiates a new optional char.
         *
         * @param value
         */
        private OptionalChar(char value) {
            this.value = value;
            this.isPresent = true;
        }

        /**
         *
         * @return
         */
        public static OptionalChar empty() {
            return EMPTY;
        }

        /**
         *
         * @param value
         * @return
         */
        public static OptionalChar of(char value) {
            return value == N.CHAR_0 ? CHAR_0 : new OptionalChar(value);
        }

        /**
         *
         * @param val
         * @return
         */
        public static OptionalChar ofNullable(Character val) {
            if (val == null) {
                return empty();
            } else {
                return of(val);
            }
        }

        /**
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public char get() throws NoSuchElementException {
            return orElseThrow();
        }

        /**
         * Checks if is present.
         *
         * @return true, if is present
         */
        public boolean isPresent() {
            return isPresent;
        }

        /**
         *
         * @param 
         * @param action
         * @return
         * @throws E the e
         */
        public  OptionalChar ifPresent(Throwables.CharConsumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isPresent()) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If present or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return
         * @throws E the e
         * @throws E2 the e2
         */
        public  OptionalChar ifPresentOrElse(Throwables.CharConsumer action, Throwables.Runnable emptyAction)
                throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isPresent()) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  OptionalChar filter(Throwables.CharPredicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isPresent() && predicate.test(value)) {
                return this;
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalChar map(final Throwables.CharUnaryOperator mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalChar.of(mapper.applyAsChar(value));
            } else {
                return empty();
            }
        }

        /**
         * Map to int.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalInt mapToInt(final Throwables.ToIntFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalInt.of(mapper.applyAsInt(value));
            } else {
                return OptionalInt.empty();
            }
        }

        /**
         * Map to obj.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable mapToObj(final Throwables.CharFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return Nullable.of(mapper.apply(value));
            } else {
                return Nullable. empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalChar flatMap(Throwables.CharFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  OptionalChar or(Throwables.Supplier supplier) throws E {
            if (isPresent()) {
                return this;
            } else {
                return Objects.requireNonNull(supplier.get());
            }
        }

        /**
         *
         * @return
         */
        public char orZero() {
            return isPresent() ? value : 0;
        }

        //    public char orElseZero() {
        //        return isPresent() ? value : 0;
        //    }

        /**
         * Or else throw.
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public char orElseThrow() throws NoSuchElementException {
            if (isPresent()) {
                return value;
            } else {
                throw new NoSuchElementException("No value present");
            }
        }

        /**
         *
         * @param other
         * @return
         */
        public char orElse(char other) {
            return isPresent() ? value : other;
        }

        /**
         * Or else get.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  char orElseGet(Throwables.CharSupplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isPresent()) {
                return value;
            } else {
                return other.getAsChar();
            }
        }

        /**
         * Or else throw.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  char orElseThrow(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isPresent()) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         *
         * @return
         */
        public List toList() {
            if (isPresent()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         *
         * @return
         */
        public Set toSet() {
            if (isPresent()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To immutable list.
         *
         * @return
         */
        public ImmutableList toImmutableList() {
            if (isPresent()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList. empty();
            }
        }

        /**
         * To immutable set.
         *
         * @return
         */
        public ImmutableSet toImmutableSet() {
            if (isPresent()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet. empty();
            }
        }

        /**
         *
         * @return
         */
        public Optional boxed() {
            if (isPresent()) {
                return Optional.of(value);
            } else {
                return Optional. empty();
            }
        }

        /**
         *
         * @param optional
         * @return
         */
        @Override
        public int compareTo(OptionalChar optional) {
            if (optional == null || optional.isPresent() == false) {
                return isPresent ? 1 : 0;
            }

            if (isPresent == false) {
                return -1;
            }

            return Character.compare(this.get(), optional.get());
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }

            if (obj instanceof OptionalChar) {
                final OptionalChar other = (OptionalChar) obj;

                return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent;
            }

            return false;
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return N.hashCode(isPresent()) * 31 + N.hashCode(value);
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (isPresent()) {
                return String.format("OptionalChar[%s]", value);
            }

            return "OptionalChar.empty";
        }
    }

    /**
     * The Class OptionalByte.
     */
    public static final class OptionalByte implements Comparable {

        /** The Constant EMPTY. */
        private static final OptionalByte EMPTY = new OptionalByte();

        /** The Constant POOL. */
        private static final OptionalByte[] POOL = new OptionalByte[256];

        static {
            for (int i = 0; i < 256; i++) {
                POOL[i] = new OptionalByte((byte) (i - 128));
            }
        }

        /** The value. */
        private final byte value;

        /** The is present. */
        private final boolean isPresent;

        /**
         * Instantiates a new optional byte.
         */
        private OptionalByte() {
            this.value = 0;
            this.isPresent = false;
        }

        /**
         * Instantiates a new optional byte.
         *
         * @param value
         */
        private OptionalByte(byte value) {
            this.value = value;
            this.isPresent = true;
        }

        /**
         *
         * @return
         */
        public static OptionalByte empty() {
            return EMPTY;
        }

        /**
         *
         * @param value
         * @return
         */
        public static OptionalByte of(byte value) {
            return POOL[value - Byte.MIN_VALUE];
        }

        /**
         *
         * @param val
         * @return
         */
        public static OptionalByte ofNullable(Byte val) {
            if (val == null) {
                return empty();
            } else {
                return OptionalByte.of(val);
            }
        }

        /**
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public byte get() throws NoSuchElementException {
            return orElseThrow();
        }

        /**
         * Checks if is present.
         *
         * @return true, if is present
         */
        public boolean isPresent() {
            return isPresent;
        }

        /**
         *
         * @param 
         * @param action
         * @return
         * @throws E the e
         */
        public  OptionalByte ifPresent(Throwables.ByteConsumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isPresent) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If present or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return
         * @throws E the e
         * @throws E2 the e2
         */
        public  OptionalByte ifPresentOrElse(Throwables.ByteConsumer action, Throwables.Runnable emptyAction)
                throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isPresent) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  OptionalByte filter(Throwables.BytePredicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isPresent && predicate.test(value)) {
                return this;
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalByte map(final Throwables.ByteUnaryOperator mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalByte.of(mapper.applyAsByte(value));
            } else {
                return empty();
            }
        }

        /**
         * Map to int.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalInt mapToInt(final Throwables.ToIntFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalInt.of(mapper.applyAsInt(value));
            } else {
                return OptionalInt.empty();
            }
        }

        /**
         * Map to obj.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable mapToObj(final Throwables.ByteFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Nullable.of(mapper.apply(value));
            } else {
                return Nullable. empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalByte flatMap(Throwables.ByteFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  OptionalByte or(Throwables.Supplier supplier) throws E {
            if (isPresent) {
                return this;
            } else {
                return Objects.requireNonNull(supplier.get());
            }
        }

        /**
         *
         * @return
         */
        public byte orZero() {
            return isPresent ? value : 0;
        }

        //    public byte orElseZero() {
        //        return isPresent ? value : 0;
        //    }

        /**
         * Or else throw.
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public byte orElseThrow() throws NoSuchElementException {
            if (isPresent) {
                return value;
            } else {
                throw new NoSuchElementException("No value present");
            }
        }

        /**
         *
         * @param other
         * @return
         */
        public byte orElse(byte other) {
            return isPresent ? value : other;
        }

        /**
         * Or else get.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  byte orElseGet(Throwables.ByteSupplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isPresent) {
                return value;
            } else {
                return other.getAsByte();
            }
        }

        /**
         * Or else throw.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  byte orElseThrow(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isPresent) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         *
         * @return
         */
        public List toList() {
            if (isPresent()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         *
         * @return
         */
        public Set toSet() {
            if (isPresent()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To immutable list.
         *
         * @return
         */
        public ImmutableList toImmutableList() {
            if (isPresent()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList. empty();
            }
        }

        /**
         * To immutable set.
         *
         * @return
         */
        public ImmutableSet toImmutableSet() {
            if (isPresent()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet. empty();
            }
        }

        /**
         *
         * @return
         */
        public Optional boxed() {
            if (isPresent) {
                return Optional.of(value);
            } else {
                return Optional. empty();
            }
        }

        /**
         *
         * @param optional
         * @return
         */
        @Override
        public int compareTo(OptionalByte optional) {
            if (optional == null || optional.isPresent == false) {
                return isPresent ? 1 : 0;
            }

            if (isPresent == false) {
                return -1;
            }

            return Byte.compare(this.get(), optional.get());
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }

            if (obj instanceof OptionalByte) {
                final OptionalByte other = (OptionalByte) obj;

                return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent;
            }

            return false;
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return N.hashCode(isPresent) * 31 + N.hashCode(value);
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (isPresent) {
                return String.format("OptionalByte[%s]", value);
            }

            return "OptionalByte.empty";
        }
    }

    /**
     * The Class OptionalShort.
     */
    public static final class OptionalShort implements Comparable {

        /** The Constant EMPTY. */
        private static final OptionalShort EMPTY = new OptionalShort();

        /** The value. */
        private final short value;

        /** The is present. */
        private final boolean isPresent;

        /**
         * Instantiates a new optional short.
         */
        private OptionalShort() {
            this.value = 0;
            this.isPresent = false;
        }

        /**
         * Instantiates a new optional short.
         *
         * @param value
         */
        private OptionalShort(short value) {
            this.value = value;
            this.isPresent = true;
        }

        /**
         *
         * @return
         */
        public static OptionalShort empty() {
            return EMPTY;
        }

        /**
         *
         * @param value
         * @return
         */
        public static OptionalShort of(short value) {
            return new OptionalShort(value);
        }

        /**
         *
         * @param val
         * @return
         */
        public static OptionalShort ofNullable(Short val) {
            if (val == null) {
                return empty();
            } else {
                return OptionalShort.of(val);
            }
        }

        /**
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public short get() throws NoSuchElementException {
            return orElseThrow();
        }

        /**
         * Checks if is present.
         *
         * @return true, if is present
         */
        public boolean isPresent() {
            return isPresent;
        }

        /**
         *
         * @param 
         * @param action
         * @return
         * @throws E the e
         */
        public  OptionalShort ifPresent(Throwables.ShortConsumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isPresent) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If present or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return
         * @throws E the e
         * @throws E2 the e2
         */
        public  OptionalShort ifPresentOrElse(Throwables.ShortConsumer action,
                Throwables.Runnable emptyAction) throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isPresent) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  OptionalShort filter(Throwables.ShortPredicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isPresent && predicate.test(value)) {
                return this;
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalShort map(final Throwables.ShortUnaryOperator mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalShort.of(mapper.applyAsShort(value));
            } else {
                return empty();
            }
        }

        /**
         * Map to int.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalInt mapToInt(final Throwables.ToIntFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalInt.of(mapper.applyAsInt(value));
            } else {
                return OptionalInt.empty();
            }
        }

        /**
         * Map to obj.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable mapToObj(final Throwables.ShortFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Nullable.of(mapper.apply(value));
            } else {
                return Nullable. empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalShort flatMap(Throwables.ShortFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  OptionalShort or(Throwables.Supplier supplier) throws E {
            if (isPresent) {
                return this;
            } else {
                return Objects.requireNonNull(supplier.get());
            }
        }

        /**
         *
         * @return
         */
        public short orZero() {
            return isPresent ? value : 0;
        }

        //    public short orElseZero() {
        //        return isPresent ? value : 0;
        //    }

        /**
         * Or else throw.
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public short orElseThrow() throws NoSuchElementException {
            if (isPresent) {
                return value;
            } else {
                throw new NoSuchElementException("No value present");
            }
        }

        /**
         *
         * @param other
         * @return
         */
        public short orElse(short other) {
            return isPresent ? value : other;
        }

        /**
         * Or else get.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  short orElseGet(Throwables.ShortSupplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isPresent) {
                return value;
            } else {
                return other.getAsShort();
            }
        }

        /**
         * Or else throw.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  short orElseThrow(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isPresent) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         *
         * @return
         */
        public List toList() {
            if (isPresent()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         *
         * @return
         */
        public Set toSet() {
            if (isPresent()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To immutable list.
         *
         * @return
         */
        public ImmutableList toImmutableList() {
            if (isPresent()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList. empty();
            }
        }

        /**
         * To immutable set.
         *
         * @return
         */
        public ImmutableSet toImmutableSet() {
            if (isPresent()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet. empty();
            }
        }

        /**
         *
         * @return
         */
        public Optional boxed() {
            if (isPresent) {
                return Optional.of(value);
            } else {
                return Optional. empty();
            }
        }

        /**
         *
         * @param optional
         * @return
         */
        @Override
        public int compareTo(OptionalShort optional) {
            if (optional == null || optional.isPresent == false) {
                return isPresent ? 1 : 0;
            }

            if (isPresent == false) {
                return -1;
            }

            return Short.compare(this.get(), optional.get());
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }

            if (obj instanceof OptionalShort) {
                final OptionalShort other = (OptionalShort) obj;

                return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent;
            }

            return false;
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return N.hashCode(isPresent) * 31 + N.hashCode(value);
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (isPresent) {
                return String.format("OptionalShort[%s]", value);
            }

            return "OptionalShort.empty";
        }
    }

    /**
     * The Class OptionalInt.
     */
    public static final class OptionalInt implements Comparable {

        /** The Constant EMPTY. */
        private static final OptionalInt EMPTY = new OptionalInt();

        /** The Constant MIN_CACHED_VALUE. */
        private static final int MIN_CACHED_VALUE = -128;

        /** The Constant MAX_CACHED_VALUE. */
        private static final int MAX_CACHED_VALUE = 1025;

        /** The Constant POOL. */
        private static final OptionalInt[] POOL = new OptionalInt[MAX_CACHED_VALUE - MIN_CACHED_VALUE];

        static {
            for (int i = 0, to = MAX_CACHED_VALUE - MIN_CACHED_VALUE; i < to; i++) {
                POOL[i] = new OptionalInt(i + MIN_CACHED_VALUE);
            }
        }

        /** The value. */
        private final int value;

        /** The is present. */
        private final boolean isPresent;

        /**
         * Instantiates a new optional int.
         */
        private OptionalInt() {
            this.value = 0;
            this.isPresent = false;
        }

        /**
         * Instantiates a new optional int.
         *
         * @param value
         */
        private OptionalInt(int value) {
            this.value = value;
            this.isPresent = true;
        }

        /**
         *
         * @return
         */
        public static OptionalInt empty() {
            return EMPTY;
        }

        /**
         *
         * @param value
         * @return
         */
        public static OptionalInt of(int value) {
            return value >= MIN_CACHED_VALUE && value < MAX_CACHED_VALUE ? POOL[value - MIN_CACHED_VALUE] : new OptionalInt(value);
        }

        /**
         *
         * @param val
         * @return
         */
        public static OptionalInt ofNullable(Integer val) {
            if (val == null) {
                return empty();
            } else {
                return OptionalInt.of(val);
            }
        }

        /**
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public int get() throws NoSuchElementException {
            return orElseThrow();
        }

        /**
         * Checks if is present.
         *
         * @return true, if is present
         */
        public boolean isPresent() {
            return isPresent;
        }

        /**
         *
         * @param 
         * @param action
         * @return
         * @throws E the e
         */
        public  OptionalInt ifPresent(Throwables.IntConsumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isPresent) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If present or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return
         * @throws E the e
         * @throws E2 the e2
         */
        public  OptionalInt ifPresentOrElse(Throwables.IntConsumer action, Throwables.Runnable emptyAction)
                throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isPresent) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  OptionalInt filter(Throwables.IntPredicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isPresent && predicate.test(value)) {
                return this;
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalInt map(final Throwables.IntUnaryOperator mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalInt.of(mapper.applyAsInt(value));
            } else {
                return empty();
            }
        }

        /**
         * Map to long.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalLong mapToLong(final Throwables.ToLongFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalLong.of(mapper.applyAsLong(value));
            } else {
                return OptionalLong.empty();
            }
        }

        /**
         * Map to double.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalDouble mapToDouble(final Throwables.ToDoubleFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalDouble.of(mapper.applyAsDouble(value));
            } else {
                return OptionalDouble.empty();
            }
        }

        /**
         * Map to obj.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable mapToObj(final Throwables.IntFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Nullable.of(mapper.apply(value));
            } else {
                return Nullable. empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalInt flatMap(Throwables.IntFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  OptionalInt or(Throwables.Supplier supplier) throws E {
            if (isPresent) {
                return this;
            } else {
                return Objects.requireNonNull(supplier.get());
            }
        }

        /**
         *
         * @return
         */
        public int orZero() {
            return isPresent ? value : 0;
        }

        //    public int orElseZero() {
        //        return isPresent ? value : 0;
        //    }

        /**
         * Or else throw.
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public int orElseThrow() throws NoSuchElementException {
            if (isPresent) {
                return value;
            } else {
                throw new NoSuchElementException("No value present");
            }
        }

        /**
         *
         * @param other
         * @return
         */
        public int orElse(int other) {
            return isPresent ? value : other;
        }

        /**
         * Or else get.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  int orElseGet(Throwables.IntSupplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isPresent) {
                return value;
            } else {
                return other.getAsInt();
            }
        }

        /**
         * Or else throw.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  int orElseThrow(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isPresent) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         *
         * @return
         */
        public List toList() {
            if (isPresent()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         *
         * @return
         */
        public Set toSet() {
            if (isPresent()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To immutable list.
         *
         * @return
         */
        public ImmutableList toImmutableList() {
            if (isPresent()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList. empty();
            }
        }

        /**
         * To immutable set.
         *
         * @return
         */
        public ImmutableSet toImmutableSet() {
            if (isPresent()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet. empty();
            }
        }

        /**
         *
         * @return
         */
        public Optional boxed() {
            if (isPresent) {
                return Optional.of(value);
            } else {
                return Optional. empty();
            }
        }

        /**
         *
         * @param optional
         * @return
         */
        @Override
        public int compareTo(OptionalInt optional) {
            if (optional == null || optional.isPresent == false) {
                return isPresent ? 1 : 0;
            }

            if (isPresent == false) {
                return -1;
            }

            return Integer.compare(this.get(), optional.get());
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }

            if (obj instanceof OptionalInt) {
                final OptionalInt other = (OptionalInt) obj;

                return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent;
            }

            return false;
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return N.hashCode(isPresent) * 31 + N.hashCode(value);
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (isPresent) {
                return String.format("OptionalInt[%s]", value);
            }

            return "OptionalInt.empty";
        }
    }

    /**
     * The Class OptionalLong.
     */
    public static final class OptionalLong implements Comparable {

        /** The Constant EMPTY. */
        private static final OptionalLong EMPTY = new OptionalLong();

        /** The value. */
        private final long value;

        /** The is present. */
        private final boolean isPresent;

        /**
         * Instantiates a new optional long.
         */
        private OptionalLong() {
            this.value = 0;
            this.isPresent = false;
        }

        /**
         * Instantiates a new optional long.
         *
         * @param value
         */
        private OptionalLong(long value) {
            this.value = value;
            this.isPresent = true;
        }

        /**
         *
         * @return
         */
        public static OptionalLong empty() {
            return EMPTY;
        }

        /**
         *
         * @param value
         * @return
         */
        public static OptionalLong of(long value) {
            return new OptionalLong(value);
        }

        /**
         *
         * @param val
         * @return
         */
        public static OptionalLong ofNullable(Long val) {
            if (val == null) {
                return empty();
            } else {
                return OptionalLong.of(val);
            }
        }

        /**
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public long get() throws NoSuchElementException {
            return orElseThrow();
        }

        /**
         * Checks if is present.
         *
         * @return true, if is present
         */
        public boolean isPresent() {
            return isPresent;
        }

        /**
         *
         * @param 
         * @param action
         * @return
         * @throws E the e
         */
        public  OptionalLong ifPresent(Throwables.LongConsumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isPresent) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If present or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return
         * @throws E the e
         * @throws E2 the e2
         */
        public  OptionalLong ifPresentOrElse(Throwables.LongConsumer action, Throwables.Runnable emptyAction)
                throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isPresent) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  OptionalLong filter(Throwables.LongPredicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isPresent && predicate.test(value)) {
                return this;
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalLong map(final Throwables.LongUnaryOperator mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalLong.of(mapper.applyAsLong(value));
            } else {
                return empty();
            }
        }

        /**
         * Map to int.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalInt mapToInt(final Throwables.ToIntFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalInt.of(mapper.applyAsInt(value));
            } else {
                return OptionalInt.empty();
            }
        }

        /**
         * Map to double.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalDouble mapToDouble(final Throwables.ToDoubleFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalDouble.of(mapper.applyAsDouble(value));
            } else {
                return OptionalDouble.empty();
            }
        }

        /**
         * Map to obj.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable mapToObj(final Throwables.LongFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Nullable.of(mapper.apply(value));
            } else {
                return Nullable. empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalLong flatMap(Throwables.LongFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  OptionalLong or(Throwables.Supplier supplier) throws E {
            if (isPresent) {
                return this;
            } else {
                return Objects.requireNonNull(supplier.get());
            }
        }

        /**
         *
         * @return
         */
        public long orZero() {
            return isPresent ? value : 0;
        }

        //    public long orElseZero() {
        //        return isPresent ? value : 0;
        //    }

        /**
         * Or else throw.
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public long orElseThrow() throws NoSuchElementException {
            if (isPresent) {
                return value;
            } else {
                throw new NoSuchElementException("No value present");
            }
        }

        /**
         *
         * @param other
         * @return
         */
        public long orElse(long other) {
            return isPresent ? value : other;
        }

        /**
         * Or else get.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  long orElseGet(Throwables.LongSupplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isPresent) {
                return value;
            } else {
                return other.getAsLong();
            }
        }

        /**
         * Or else throw.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  long orElseThrow(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isPresent) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         *
         * @return
         */
        public List toList() {
            if (isPresent()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         *
         * @return
         */
        public Set toSet() {
            if (isPresent()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To immutable list.
         *
         * @return
         */
        public ImmutableList toImmutableList() {
            if (isPresent()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList. empty();
            }
        }

        /**
         * To immutable set.
         *
         * @return
         */
        public ImmutableSet toImmutableSet() {
            if (isPresent()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet. empty();
            }
        }

        /**
         *
         * @return
         */
        public Optional boxed() {
            if (isPresent) {
                return Optional.of(value);
            } else {
                return Optional. empty();
            }
        }

        /**
         *
         * @param optional
         * @return
         */
        @Override
        public int compareTo(OptionalLong optional) {
            if (optional == null || optional.isPresent == false) {
                return isPresent ? 1 : 0;
            }

            if (isPresent == false) {
                return -1;
            }

            return Long.compare(this.get(), optional.get());
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }

            if (obj instanceof OptionalLong) {
                final OptionalLong other = (OptionalLong) obj;

                return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent;
            }

            return false;
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return N.hashCode(isPresent) * 31 + N.hashCode(value);
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (isPresent) {
                return String.format("OptionalLong[%s]", value);
            }

            return "OptionalLong.empty";
        }
    }

    /**
     * The Class OptionalFloat.
     */
    public static final class OptionalFloat implements Comparable {

        /** The Constant EMPTY. */
        private static final OptionalFloat EMPTY = new OptionalFloat();

        /** The value. */
        private final float value;

        /** The is present. */
        private final boolean isPresent;

        /**
         * Instantiates a new optional float.
         */
        private OptionalFloat() {
            this.value = 0;
            this.isPresent = false;
        }

        /**
         * Instantiates a new optional float.
         *
         * @param value
         */
        private OptionalFloat(float value) {
            this.value = value;
            this.isPresent = true;
        }

        /**
         *
         * @return
         */
        public static OptionalFloat empty() {
            return EMPTY;
        }

        /**
         *
         * @param value
         * @return
         */
        public static OptionalFloat of(float value) {
            return new OptionalFloat(value);
        }

        /**
         *
         * @param val
         * @return
         */
        public static OptionalFloat ofNullable(Float val) {
            if (val == null) {
                return empty();
            } else {
                return OptionalFloat.of(val);
            }
        }

        /**
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public float get() throws NoSuchElementException {
            return orElseThrow();
        }

        /**
         * Checks if is present.
         *
         * @return true, if is present
         */
        public boolean isPresent() {
            return isPresent;
        }

        /**
         *
         * @param 
         * @param action
         * @return
         * @throws E the e
         */
        public  OptionalFloat ifPresent(Throwables.FloatConsumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isPresent) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If present or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return
         * @throws E the e
         * @throws E2 the e2
         */
        public  OptionalFloat ifPresentOrElse(Throwables.FloatConsumer action,
                Throwables.Runnable emptyAction) throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isPresent) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  OptionalFloat filter(Throwables.FloatPredicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isPresent && predicate.test(value)) {
                return this;
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalFloat map(final Throwables.FloatUnaryOperator mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalFloat.of(mapper.applyAsFloat(value));
            } else {
                return empty();
            }
        }

        /**
         * Map to double.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalDouble mapToDouble(final Throwables.ToDoubleFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalDouble.of(mapper.applyAsDouble(value));
            } else {
                return OptionalDouble.empty();
            }
        }

        /**
         * Map to obj.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable mapToObj(final Throwables.FloatFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Nullable.of(mapper.apply(value));
            } else {
                return Nullable. empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalFloat flatMap(Throwables.FloatFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  OptionalFloat or(Throwables.Supplier supplier) throws E {
            if (isPresent) {
                return this;
            } else {
                return Objects.requireNonNull(supplier.get());
            }
        }

        /**
         *
         * @return
         */
        public float orZero() {
            return isPresent ? value : 0;
        }

        //    public float orElseZero() {
        //        return isPresent ? value : 0;
        //    }

        /**
         * Or else throw.
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public float orElseThrow() throws NoSuchElementException {
            if (isPresent) {
                return value;
            } else {
                throw new NoSuchElementException("No value present");
            }
        }

        /**
         *
         * @param other
         * @return
         */
        public float orElse(float other) {
            return isPresent ? value : other;
        }

        /**
         * Or else get.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  float orElseGet(Throwables.FloatSupplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isPresent) {
                return value;
            } else {
                return other.getAsFloat();
            }
        }

        /**
         * Or else throw.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  float orElseThrow(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isPresent) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         *
         * @return
         */
        public List toList() {
            if (isPresent()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         *
         * @return
         */
        public Set toSet() {
            if (isPresent()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To immutable list.
         *
         * @return
         */
        public ImmutableList toImmutableList() {
            if (isPresent()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList. empty();
            }
        }

        /**
         * To immutable set.
         *
         * @return
         */
        public ImmutableSet toImmutableSet() {
            if (isPresent()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet. empty();
            }
        }

        /**
         *
         * @return
         */
        public Optional boxed() {
            if (isPresent) {
                return Optional.of(value);
            } else {
                return Optional. empty();
            }
        }

        /**
         *
         * @param optional
         * @return
         */
        @Override
        public int compareTo(OptionalFloat optional) {
            if (optional == null || optional.isPresent == false) {
                return isPresent ? 1 : 0;
            }

            if (isPresent == false) {
                return -1;
            }

            return Float.compare(this.get(), optional.get());
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }

            if (obj instanceof OptionalFloat) {
                final OptionalFloat other = (OptionalFloat) obj;

                return (isPresent && other.isPresent) ? N.equals(value, other.value) : isPresent == other.isPresent;
            }

            return false;
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return N.hashCode(isPresent) * 31 + N.hashCode(value);
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (isPresent) {
                return String.format("OptionalFloat[%s]", value);
            }

            return "OptionalFloat.empty";
        }
    }

    /**
     * The Class OptionalDouble.
     */
    public static final class OptionalDouble implements Comparable {

        /** The Constant EMPTY. */
        private static final OptionalDouble EMPTY = new OptionalDouble();

        /** The value. */
        private final double value;

        /** The is present. */
        private final boolean isPresent;

        /**
         * Instantiates a new optional double.
         */
        private OptionalDouble() {
            this.value = 0;
            this.isPresent = false;
        }

        /**
         * Instantiates a new optional double.
         *
         * @param value
         */
        private OptionalDouble(double value) {
            this.value = value;
            this.isPresent = true;
        }

        /**
         *
         * @return
         */
        public static OptionalDouble empty() {
            return EMPTY;
        }

        /**
         *
         * @param value
         * @return
         */
        public static OptionalDouble of(double value) {
            return new OptionalDouble(value);
        }

        /**
         *
         * @param val
         * @return
         */
        public static OptionalDouble ofNullable(Double val) {
            if (val == null) {
                return empty();
            } else {
                return OptionalDouble.of(val);
            }
        }

        /**
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public double get() throws NoSuchElementException {
            return orElseThrow();
        }

        /**
         * Checks if is present.
         *
         * @return true, if is present
         */
        public boolean isPresent() {
            return isPresent;
        }

        /**
         *
         * @param 
         * @param action
         * @return
         * @throws E the e
         */
        public  OptionalDouble ifPresent(Throwables.DoubleConsumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isPresent) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If present or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return
         * @throws E the e
         * @throws E2 the e2
         */
        public  OptionalDouble ifPresentOrElse(Throwables.DoubleConsumer action,
                Throwables.Runnable emptyAction) throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isPresent) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  OptionalDouble filter(Throwables.DoublePredicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isPresent && predicate.test(value)) {
                return this;
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalDouble map(final Throwables.DoubleUnaryOperator mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalDouble.of(mapper.applyAsDouble(value));
            } else {
                return empty();
            }
        }

        /**
         * Map to int.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalInt mapToInt(final Throwables.ToIntFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalInt.of(mapper.applyAsInt(value));
            } else {
                return OptionalInt.empty();
            }
        }

        /**
         * Map to long.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalLong mapToLong(final Throwables.ToLongFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return OptionalLong.of(mapper.applyAsLong(value));
            } else {
                return OptionalLong.empty();
            }
        }

        /**
         * Map to obj.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable mapToObj(final Throwables.DoubleFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Nullable.of(mapper.apply(value));
            } else {
                return Nullable. empty();
            }
        }

        /**
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalDouble flatMap(Throwables.DoubleFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  OptionalDouble or(Throwables.Supplier supplier) throws E {
            if (isPresent) {
                return this;
            } else {
                return Objects.requireNonNull(supplier.get());
            }
        }

        /**
         *
         * @return
         */
        public double orZero() {
            return isPresent ? value : 0;
        }

        //    public double orElseZero() {
        //        return isPresent ? value : 0;
        //    }

        /**
         * Or else throw.
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public double orElseThrow() throws NoSuchElementException {
            if (isPresent) {
                return value;
            } else {
                throw new NoSuchElementException("No value present");
            }
        }

        /**
         *
         * @param other
         * @return
         */
        public double orElse(double other) {
            return isPresent ? value : other;
        }

        /**
         * Or else get.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  double orElseGet(Throwables.DoubleSupplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isPresent) {
                return value;
            } else {
                return other.getAsDouble();
            }
        }

        /**
         * Or else throw.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  double orElseThrow(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isPresent) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         *
         * @return
         */
        public List toList() {
            if (isPresent()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         *
         * @return
         */
        public Set toSet() {
            if (isPresent()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To immutable list.
         *
         * @return
         */
        public ImmutableList toImmutableList() {
            if (isPresent()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList. empty();
            }
        }

        /**
         * To immutable set.
         *
         * @return
         */
        public ImmutableSet toImmutableSet() {
            if (isPresent()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet. empty();
            }
        }

        /**
         *
         * @return
         */
        public Optional boxed() {
            if (isPresent) {
                return Optional.of(value);
            } else {
                return Optional. empty();
            }
        }

        /**
         *
         * @param optional
         * @return
         */
        @Override
        public int compareTo(OptionalDouble optional) {
            if (optional == null || optional.isPresent == false) {
                return isPresent ? 1 : 0;
            }

            if (isPresent == false) {
                return -1;
            }

            return Double.compare(this.get(), optional.get());
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }

            if (obj instanceof OptionalDouble) {
                final OptionalDouble other = (OptionalDouble) obj;

                return (isPresent && other.isPresent) ? N.equals(value, other.value) : isPresent == other.isPresent;
            }

            return false;
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return N.hashCode(isPresent) * 31 + N.hashCode(value);
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (isPresent) {
                return String.format("OptionalDouble[%s]", value);
            }

            return "OptionalDouble.empty";
        }
    }

    /**
     * The Class Nullable.
     *
     * @param 
     */
    public static final class Nullable {

        /** Presents {@code Boolean.TRUE}. */
        public static final Nullable TRUE = new Nullable<>(Boolean.TRUE);

        /** Presents {@code Boolean.FALSE}. */
        public static final Nullable FALSE = new Nullable<>(Boolean.FALSE);

        /** The Constant EMPTY. */
        private static final Nullable EMPTY = new Nullable<>();

        /** The value. */
        private final T value;

        /** The is present. */
        private final boolean isPresent;

        /**
         * Instantiates a new nullable.
         */
        private Nullable() {
            this.value = null;
            this.isPresent = false;
        }

        /**
         * Instantiates a new nullable.
         *
         * @param value
         */
        private Nullable(T value) {
            this.value = value;
            this.isPresent = true;
        }

        /**
         *
         * @param 
         * @return
         */
        public static  Nullable empty() {
            return (Nullable) EMPTY;
        }

        /**
         *
         * @param 
         * @param value
         * @return
         */
        public static  Nullable of(T value) {
            return new Nullable<>(value);
        }

        /**
         *
         * @param 
         * @param optional
         * @return
         */
        public static  Nullable from(Optional optional) {
            if (optional.isPresent()) {
                return new Nullable<>(optional.get());
            } else {
                return Nullable. empty();
            }
        }

        /**
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public T get() throws NoSuchElementException {
            return orElseThrow();
        }

        /**
         * Returns {@code true} if the value is present, otherwise returns {@code false}.
         *
         * @return true, if is present
         */
        public boolean isPresent() {
            return isPresent;
        }

        /**
         * Returns {@code true} if the value is not present, otherwise returns {@code false}.
         *
         * @return true, if is not present
         */
        public boolean isNotPresent() {
            return isPresent == false;
        }

        /**
         * Returns {@code true} if the value is not present, otherwise returns {@code false}.
         *
         * @return true, if is empty
         * @deprecated replaced by {@link #isNotPresent()}
         */
        @Deprecated
        public boolean isEmpty() {
            return isPresent == false;
        }

        /**
         * Returns {@code true} if the value is not present, or it is present but it's {@code null}, otherwise returns {@code false}.
         *
         * @return true, if is null
         */
        public boolean isNull() {
            return value == null;
        }

        /**
         * Returns {@code true} if the value is present and it's not {@code null}, otherwise returns {@code false}.
         *
         * @return true, if is not null
         */
        public boolean isNotNull() {
            return value != null;
        }

        /**
         *
         * @param 
         * @param action
         * @return itself
         * @throws E the e
         */
        public  Nullable ifPresent(Throwables.Consumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isPresent()) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If present or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return itself
         * @throws E the e
         * @throws E2 the e2
         */
        public  Nullable ifPresentOrElse(Throwables.Consumer action,
                Throwables.Runnable emptyAction) throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isPresent()) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         * If not null.
         *
         * @param 
         * @param action
         * @return itself
         * @throws E the e
         */
        public  Nullable ifNotNull(Throwables.Consumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isNotNull()) {
                action.accept(value);
            }

            return this;
        }

        /**
         * If not null or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @return itself
         * @throws E the e
         * @throws E2 the e2
         */
        public  Nullable ifNotNullOrElse(Throwables.Consumer action,
                Throwables.Runnable emptyAction) throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isNotNull()) {
                action.accept(value);
            } else {
                emptyAction.run();
            }

            return this;
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  Nullable filter(Throwables.Predicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isPresent() && predicate.test(value)) {
                return this;
            } else {
                return empty();
            }
        }

        /**
         * Filter if not null.
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  Optional filterIfNotNull(Throwables.Predicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isNotNull() && predicate.test(value)) {
                return Optional.of(value);
            } else {
                return Optional.empty();
            }
        }

        /**
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable map(Throwables.Function mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return Nullable.of((U) mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         * Map to boolean.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalBoolean mapToBoolean(final Throwables.ToBooleanFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalBoolean.of(mapper.applyAsBoolean(value));
            } else {
                return OptionalBoolean.empty();
            }
        }

        /**
         * Map to char.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalChar mapToChar(final Throwables.ToCharFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalChar.of(mapper.applyAsChar(value));
            } else {
                return OptionalChar.empty();
            }
        }

        /**
         * Map to byte.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalByte mapToByte(final Throwables.ToByteFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalByte.of(mapper.applyAsByte(value));
            } else {
                return OptionalByte.empty();
            }
        }

        /**
         * Map to short.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalShort mapToShort(final Throwables.ToShortFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalShort.of(mapper.applyAsShort(value));
            } else {
                return OptionalShort.empty();
            }
        }

        /**
         * Map to int.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalInt mapToInt(final Throwables.ToIntFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalInt.of(mapper.applyAsInt(value));
            } else {
                return OptionalInt.empty();
            }
        }

        /**
         * Map to long.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalLong mapToLong(final Throwables.ToLongFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalLong.of(mapper.applyAsLong(value));
            } else {
                return OptionalLong.empty();
            }
        }

        /**
         * Map to float.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalFloat mapToFloat(final Throwables.ToFloatFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalFloat.of(mapper.applyAsFloat(value));
            } else {
                return OptionalFloat.empty();
            }
        }

        /**
         * Map to double.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalDouble mapToDouble(final Throwables.ToDoubleFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return OptionalDouble.of(mapper.applyAsDouble(value));
            } else {
                return OptionalDouble.empty();
            }
        }

        /**
         * Map if not null.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable mapIfNotNull(Throwables.Function mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return Nullable.of((U) mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         * Map to boolean if not null.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalBoolean mapToBooleanIfNotNull(final Throwables.ToBooleanFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return OptionalBoolean.of(mapper.applyAsBoolean(value));
            } else {
                return OptionalBoolean.empty();
            }
        }

        /**
         * Map to char if not null.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalChar mapToCharIfNotNull(final Throwables.ToCharFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return OptionalChar.of(mapper.applyAsChar(value));
            } else {
                return OptionalChar.empty();
            }
        }

        /**
         * Map to byte if not null.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalByte mapToByteIfNotNull(final Throwables.ToByteFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return OptionalByte.of(mapper.applyAsByte(value));
            } else {
                return OptionalByte.empty();
            }
        }

        /**
         * Map to short if not null.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalShort mapToShortIfNotNull(final Throwables.ToShortFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return OptionalShort.of(mapper.applyAsShort(value));
            } else {
                return OptionalShort.empty();
            }
        }

        /**
         * Map to int if not null.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalInt mapToIntIfNotNull(final Throwables.ToIntFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return OptionalInt.of(mapper.applyAsInt(value));
            } else {
                return OptionalInt.empty();
            }
        }

        /**
         * Map to long if not null.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalLong mapToLongIfNotNull(final Throwables.ToLongFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return OptionalLong.of(mapper.applyAsLong(value));
            } else {
                return OptionalLong.empty();
            }
        }

        /**
         * Map to float if not null.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalFloat mapToFloatIfNotNull(final Throwables.ToFloatFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return OptionalFloat.of(mapper.applyAsFloat(value));
            } else {
                return OptionalFloat.empty();
            }
        }

        /**
         * Map to double if not null.
         *
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  OptionalDouble mapToDoubleIfNotNull(final Throwables.ToDoubleFunction mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return OptionalDouble.of(mapper.applyAsDouble(value));
            } else {
                return OptionalDouble.empty();
            }
        }

        /**
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable flatMap(Throwables.Function, E> mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isPresent()) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        /**
         * Flat map if not null.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable flatMapIfNotNull(Throwables.Function, E> mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return Objects.requireNonNull(mapper.apply(value));
            } else {
                return empty();
            }
        }

        public boolean contains(final T element) {
            return isPresent() && N.equals(this.value, element);
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  Nullable or(Throwables.Supplier, E> supplier) throws E {
            N.checkArgNotNull(supplier, "supplier");

            if (isPresent()) {
                return this;
            } else {
                return Objects.requireNonNull((Nullable) supplier.get());
            }
        }

        /**
         * Or if null.
         *
         * @param 
         * @param supplier
         * @return
         * @throws E the e
         */
        public  Nullable orIfNull(Throwables.Supplier, E> supplier) throws E {
            N.checkArgNotNull(supplier, "supplier");

            if (isNotNull()) {
                return this;
            } else {
                return Objects.requireNonNull((Nullable) supplier.get());
            }
        }

        /**
         *
         * @return
         */
        public T orNull() {
            return isPresent() ? value : null;
        }

        //    public T orElseNull() {
        //        return isPresent() ? value : null;
        //    }

        /**
         *
         * @param other
         * @return
         */
        public T orElse(T other) {
            return isPresent() ? value : other;
        }

        /**
         * Or else get.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  T orElseGet(Throwables.Supplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isPresent()) {
                return value;
            } else {
                return other.get();
            }
        }

        /**
         * Or else throw.
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public T orElseThrow() throws NoSuchElementException {
            if (isPresent()) {
                return value;
            } else {
                throw new NoSuchElementException("No value is present");
            }
        }

        /**
         * Or else throw.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  T orElseThrow(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isPresent()) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         * Or else if null.
         *
         * @param other
         * @return
         */
        public T orElseIfNull(T other) {
            return isNotNull() ? value : other;
        }

        /**
         * Or else get if null.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  T orElseGetIfNull(Throwables.Supplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isNotNull()) {
                return value;
            } else {
                return other.get();
            }
        }

        /**
         * Or else throw if null.
         *
         * @return
         * @throws NoSuchElementException the no such element exception
         */
        public T orElseThrowIfNull() throws NoSuchElementException {
            if (isNotNull()) {
                return value;
            } else {
                throw new NoSuchElementException("No value is present");
            }
        }

        /**
         * Or else throw if null.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  T orElseThrowIfNull(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isNotNull()) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         *
         * @return
         */
        public List toList() {
            if (isPresent()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         * To list if not null.
         *
         * @return
         */
        public List toListIfNotNull() {
            if (isNotNull()) {
                return N.asList(value);
            } else {
                return new ArrayList<>();
            }
        }

        /**
         *
         * @return
         */
        public Set toSet() {
            if (isPresent()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To set if not null.
         *
         * @return
         */
        public Set toSetIfNotNull() {
            if (isNotNull()) {
                return N.asSet(value);
            } else {
                return N.newHashSet();
            }
        }

        /**
         * To immutable list.
         *
         * @return
         */
        public ImmutableList toImmutableList() {
            if (isPresent()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList.empty();
            }
        }

        /**
         * To immutable list if not null.
         *
         * @return
         */
        public ImmutableList toImmutableListIfNotNull() {
            if (isNotNull()) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList.empty();
            }
        }

        /**
         * To immutable set.
         *
         * @return
         */
        public ImmutableSet toImmutableSet() {
            if (isPresent()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet.empty();
            }
        }

        /**
         * To immutable set if not null.
         *
         * @return
         */
        public ImmutableSet toImmutableSetIfNotNull() {
            if (isNotNull()) {
                return ImmutableSet.of(value);
            } else {
                return ImmutableSet.empty();
            }
        }

        /**
         *
         * @return
         */
        public Optional toOptional() {
            if (value == null) {
                return Optional. empty();
            } else {
                return Optional.of(value);
            }
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }

            if (obj instanceof Nullable) {
                final Nullable other = (Nullable) obj;

                return N.equals(isPresent, other.isPresent) && N.equals(value, other.value);
            }

            return false;
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return N.hashCode(isPresent) * 31 + N.hashCode(value);
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (value == null) {
                return isPresent ? "Nullable[null]" : "Nullable.empty";
            } else {
                return String.format("Nullable[%s]", N.toString(value));
            }
        }
    }

    /**
     * The Class Holder.
     *
     * @param 
     */
    public static final class Holder extends Reference> {

        /**
         * Instantiates a new holder.
         */
        public Holder() {
            this(null);
        }

        /**
         * Instantiates a new holder.
         *
         * @param value
         */
        Holder(T value) {
            super(value);
        }

        /**
         *
         * @param 
         * @param value
         * @return
         */
        public static  Holder of(T value) {
            return new Holder<>(value);
        }
    }

    /**
     * The Class R.
     *
     * @param 
     */
    public static final class R extends Reference> {

        /**
         * Instantiates a new r.
         */
        public R() {
            this(null);
        }

        /**
         * Instantiates a new r.
         *
         * @param value
         */
        R(T value) {
            super(value);
        }

        /**
         *
         * @param 
         * @param value
         * @return
         */
        public static  R of(T value) {
            return new R<>(value);
        }
    }

    /**
     * The Class Reference.
     *
     * @param 
     * @param 
     */
    static abstract class Reference> {

        /** The value. */
        private T value;

        /**
         * Instantiates a new reference.
         */
        protected Reference() {
            this(null);
        }

        /**
         * Instantiates a new reference.
         *
         * @param value
         */
        protected Reference(T value) {
            this.value = value;
        }

        /**
         *
         * @return
         */
        public T value() {
            return value;
        }

        /**
         * Gets the value.
         *
         * @return
         * @deprecated replace by {@link #value()}.
         */
        @Deprecated
        public T getValue() {
            return value;
        }

        /**
         * Sets the value.
         *
         * @param value the new value
         */
        public void setValue(final T value) {
            this.value = value;
        }

        /**
         * Gets the and set.
         *
         * @param value
         * @return
         */
        public T getAndSet(final T value) {
            final T result = this.value;
            this.value = value;
            return result;
        }

        /**
         * Sets the and get.
         *
         * @param value
         * @return
         */
        public T setAndGet(final T value) {
            this.value = value;
            return this.value;
        }

        /**
         * Gets the and update.
         *
         * @param 
         * @param updateFunction
         * @return
         * @throws E the e
         */
        public final  T getAndUpdate(Throwables.UnaryOperator updateFunction) throws E {
            final T res = value;
            this.value = updateFunction.apply(value);
            return res;
        }

        /**
         * Update and get.
         *
         * @param 
         * @param updateFunction
         * @return
         * @throws E the e
         */
        public final  T updateAndGet(Throwables.UnaryOperator updateFunction) throws E {
            this.value = updateFunction.apply(value);
            return value;
        }

        /**
         * Set with the specified new value and returns true if predicate returns true.
         * Otherwise just return false without setting the value to new value.
         *
         * @param 
         * @param newValue
         * @param predicate - test the current value.
         * @return true, if successful
         * @throws E the e
         */
        public  boolean setIf(final T newValue, final Throwables.Predicate predicate) throws E {
            if (predicate.test(value)) {
                this.value = newValue;
                return true;
            }

            return false;
        }

        /**
         * Set with the specified new value and returns true if predicate returns true.
         * Otherwise just return false without setting the value to new value.
         *
         * @param 
         * @param newValue
         * @param predicate the first parameter is the current value, the second parameter is the new value.
         * @return true, if successful
         * @throws E the e
         */
        public  boolean setIf(final T newValue, final Throwables.BiPredicate predicate) throws E {
            if (predicate.test(value, newValue)) {
                this.value = newValue;
                return true;
            }

            return false;
        }

        /**
         * Checks if is null.
         *
         * @return true, if is null
         */
        public boolean isNull() {
            return value == null;
        }

        /**
         * Checks if is not null.
         *
         * @return true, if is not null
         */
        public boolean isNotNull() {
            return value != null;
        }

        /**
         * If not null.
         *
         * @param 
         * @param action
         * @throws E the e
         */
        public  void ifNotNull(Throwables.Consumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isNotNull()) {
                action.accept(value);
            }
        }

        /**
         * If not null or else.
         *
         * @param 
         * @param 
         * @param action
         * @param emptyAction
         * @throws E the e
         * @throws E2 the e2
         */
        public  void ifNotNullOrElse(Throwables.Consumer action, Throwables.Runnable emptyAction)
                throws E, E2 {
            N.checkArgNotNull(action, "action");
            N.checkArgNotNull(emptyAction, "emptyAction");

            if (isNotNull()) {
                action.accept(value);
            } else {
                emptyAction.run();
            }
        }

        /**
         *
         * @param 
         * @param action
         * @throws E the e
         */
        public  void accept(final Throwables.Consumer action) throws E {
            action.accept(value);
        }

        /**
         * Accept if not null.
         *
         * @param 
         * @param action
         * @throws E the e
         * @deprecated replaced by {@link #ifNotNull(com.landawn.abacus.util.Throwables.Consumer)}
         */
        @Deprecated
        public  void acceptIfNotNull(final Throwables.Consumer action) throws E {
            N.checkArgNotNull(action, "action");

            if (isNotNull()) {
                action.accept(value);
            }
        }

        /**
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  U map(final Throwables.Function mapper) throws E {
            return mapper.apply(value);
        }

        /**
         * Map if not null.
         *
         * @param 
         * @param 
         * @param mapper
         * @return
         * @throws E the e
         */
        public  Nullable mapIfNotNull(final Throwables.Function mapper) throws E {
            N.checkArgNotNull(mapper, "mapper");

            if (isNotNull()) {
                return Nullable.of((U) mapper.apply(value));
            } else {
                return Nullable. empty();
            }
        }

        /**
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  Nullable filter(final Throwables.Predicate predicate) throws E {
            if (predicate.test(value)) {
                return Nullable.of(value);
            } else {
                return Nullable. empty();
            }
        }

        /**
         * Filter if not null.
         *
         * @param 
         * @param predicate
         * @return
         * @throws E the e
         */
        public  Optional filterIfNotNull(final Throwables.Predicate predicate) throws E {
            N.checkArgNotNull(predicate, "predicate");

            if (isNotNull() && predicate.test(value)) {
                return Optional.of(value);
            } else {
                return Optional. empty();
            }
        }

        /**
         * Or else if null.
         *
         * @param other
         * @return
         */
        public T orElseIfNull(T other) {
            return isNotNull() ? value : other;
        }

        /**
         * Or else get if null.
         *
         * @param 
         * @param other
         * @return
         * @throws E the e
         */
        public  T orElseGetIfNull(Throwables.Supplier other) throws E {
            N.checkArgNotNull(other, "other");

            if (isNotNull()) {
                return value;
            } else {
                return other.get();
            }
        }

        /**
         * Or else throw if null.
         *
         * @param 
         * @param exceptionSupplier
         * @return
         * @throws X the x
         */
        public  T orElseThrowIfNull(Supplier exceptionSupplier) throws X {
            N.checkArgNotNull(exceptionSupplier, "exceptionSupplier");

            if (isNotNull()) {
                return value;
            } else {
                throw exceptionSupplier.get();
            }
        }

        /**
         * Returns a non-empty {@code Nullable} with the {@code value}.
         *
         * @return
         */
        public Nullable toNullable() {
            return Nullable.of(value);
        }

        /**
         * Returns an {@code Optional} with the {@code value} if {@code value} is not null, otherwise an empty {@code Optional} is returned.
         *
         * @return
         */
        public Optional toOptional() {
            return Optional.ofNullable(value);
        }

        /**
         *
         * @return
         */
        @Override
        public int hashCode() {
            return (value == null) ? 0 : value.hashCode();
        }

        /**
         *
         * @param obj
         * @return true, if successful
         */
        @SuppressWarnings("rawtypes")
        @Override
        public boolean equals(final Object obj) {
            return this == obj || (obj instanceof Reference && N.equals(((Reference) obj).value, value));
        }

        /**
         *
         * @return
         */
        @Override
        public String toString() {
            if (value == null) {
                return "Reference[null]";
            } else {
                return String.format("Reference[%s]", N.toString(value));
            }
        }
    }

    //    public static final class t extends u {
    //        private t() {
    //            // utility class
    //        }
    //    }
    //
    //    public static final class m extends u {
    //        private m() {
    //            // utility class
    //        }
    //    }
}