// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
// 
//     void call();
// }
// 
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
// 
//     void consume(long value);
// }
// 
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
// 
//     long get();
// }
// 
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
// 
//     T get();
// }


import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
/*
 *     Copyright (C) 2016 Hadi Satrio
 *
 *     Permission is hereby granted, free of charge, to any person obtaining a copy
 *     of this software and associated documentation files (the "Software"), to deal
 *     in the Software without restriction, including without limitation the rights
 *     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *     copies of the Software, and to permit persons to whom the Software is
 *     furnished to do so, subject to the following conditions:
 *
 *     The above copyright notice and this permission notice shall be included in all
 *     copies or substantial portions of the Software.
 *
 *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 *     SOFTWARE.
 */

package com.hadisatrio.optional;



/**
 * A container object which may or may not contain a long value.
 * If a value is present, {@code isPresent()} will return {@code true} and
 * {@code get()} will return the value.
 * <p>
 * <p>Additional methods that depend on the presence or absence of a contained
 * value are provided, such as {@link #or(long) orElse()}
 * (return a default value if value not present),
 * {@link #ifPresent(LongConsumer) ifPresent()} (execute a block of code
 * if the value is present), and
 * {@link #ifPresentOrElse(LongConsumer, Function) ifPresentOrElse()} (execute
 * a block of code if the value is present, another block otherwise).
 *
 * @author Hadi Satrio
 */
public final class OptionalLong implements Serializable {

    /**
     * Common instance for {@code OptionalLong}s with no value present / {@link #absent()}.
     */
    private static final OptionalLong ABSENT = new OptionalLong();

    /**
     * Indicates whether or not the value is present.
     */
    private final boolean isPresent;

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

    /**
     * Constructs an absent instance.
     */
    private OptionalLong() {
        this.isPresent = false;
        this.value = 0;
    }

    /**
     * Constructs an instance with the value present.
     *
     * @param value the value to be present
     */
    private OptionalLong(long value) {
        this.isPresent = true;
        this.value = value;
    }

    /**
     * Returns an {@code OptionalLong} with the specified present value.
     *
     * @param value the value to be present
     * @return an {@code OptionalLong} with the value present
     */
    public static OptionalLong of(long value) {
        return new OptionalLong(value);
    }

    /**
     * Returns an absent {@code OptionalLong} instance.  No value is present for this
     * Optional.
     *
     * @return an absent {@code OptionalLong}
     */
    public static OptionalLong absent() {
        return ABSENT;
    }

    /**
     * Return {@code true} if there is a value present, otherwise {@code false}.
     *
     * @return {@code true} if there is a value present, otherwise {@code false}
     */
    public boolean isPresent() {
        return isPresent;
    }

    /**
     * If a value is present in this {@code OptionalLong}, returns the value,
     * otherwise throws {@code IllegalStateException}.
     *
     * @return the value held by this {@code OptionalLong}
     * @throws IllegalStateException if there is no value present
     */
    public long get() {
        if (isPresent()) {
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
// 
//     void call();
// }
// 
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
// 
//     void consume(long value);
// }
// 
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
// 
//     long get();
// }
// 
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
// 
//     T get();
// }


// Path: src/main/java/com/hadisatrio/optional/OptionalLong.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;

/*
 *     Copyright (C) 2016 Hadi Satrio
 *
 *     Permission is hereby granted, free of charge, to any person obtaining a copy
 *     of this software and associated documentation files (the "Software"), to deal
 *     in the Software without restriction, including without limitation the rights
 *     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *     copies of the Software, and to permit persons to whom the Software is
 *     furnished to do so, subject to the following conditions:
 *
 *     The above copyright notice and this permission notice shall be included in all
 *     copies or substantial portions of the Software.
 *
 *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 *     SOFTWARE.
 */

package com.hadisatrio.optional;



/**
 * A container object which may or may not contain a long value.
 * If a value is present, {@code isPresent()} will return {@code true} and
 * {@code get()} will return the value.
 * <p>
 * <p>Additional methods that depend on the presence or absence of a contained
 * value are provided, such as {@link #or(long) orElse()}
 * (return a default value if value not present),
 * {@link #ifPresent(LongConsumer) ifPresent()} (execute a block of code
 * if the value is present), and
 * {@link #ifPresentOrElse(LongConsumer, Function) ifPresentOrElse()} (execute
 * a block of code if the value is present, another block otherwise).
 *
 * @author Hadi Satrio
 */
public final class OptionalLong implements Serializable {

    /**
     * Common instance for {@code OptionalLong}s with no value present / {@link #absent()}.
     */
    private static final OptionalLong ABSENT = new OptionalLong();

    /**
     * Indicates whether or not the value is present.
     */
    private final boolean isPresent;

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

    /**
     * Constructs an absent instance.
     */
    private OptionalLong() {
        this.isPresent = false;
        this.value = 0;
    }

    /**
     * Constructs an instance with the value present.
     *
     * @param value the value to be present
     */
    private OptionalLong(long value) {
        this.isPresent = true;
        this.value = value;
    }

    /**
     * Returns an {@code OptionalLong} with the specified present value.
     *
     * @param value the value to be present
     * @return an {@code OptionalLong} with the value present
     */
    public static OptionalLong of(long value) {
        return new OptionalLong(value);
    }

    /**
     * Returns an absent {@code OptionalLong} instance.  No value is present for this
     * Optional.
     *
     * @return an absent {@code OptionalLong}
     */
    public static OptionalLong absent() {
        return ABSENT;
    }

    /**
     * Return {@code true} if there is a value present, otherwise {@code false}.
     *
     * @return {@code true} if there is a value present, otherwise {@code false}
     */
    public boolean isPresent() {
        return isPresent;
    }

    /**
     * If a value is present in this {@code OptionalLong}, returns the value,
     * otherwise throws {@code IllegalStateException}.
     *
     * @return the value held by this {@code OptionalLong}
     * @throws IllegalStateException if there is no value present
     */
    public long get() {
        if (isPresent()) {
            return value;