// Path: src/main/java/jp/root42/indolently/function/Statement.java
// @FunctionalInterface
// public interface Statement
//     extends Runnable {
// 
//     Statement NOP = () -> {};
// 
//     /**
//      * Perform this operation.
//      *
//      * @throws Exception any exception which this statement would throw
//      */
//     void exec() throws Exception;
// 
//     /**
//      * Perform this operation.
//      */
//     @Override
//     default void run() {
//         try {
//             this.exec();
//         } catch (final Exception e) {
//             Expressive.raise(e);
//         }
//     }
// 
//     /**
//      * Returns composed statement which execute this statement then execute {@code after}.
//      *
//      * @param after statement which execute after this statement
//      * @return composed statement
//      */
//     default Statement andThen(final Statement after) {
// 
//         Objects.requireNonNull(after);
// 
//         return () -> {
//             this.run();
//             after.run();
//         };
//     }
// }


import java.util.function.Predicate;
import jp.root42.indolently.function.Statement;
import java.util.function.BooleanSupplier;
// Copyright 2014 takahashikzn
//
// 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 jp.root42.indolently.ref;




/**
 * @author takahashikzn
 * @version $Id$
 */
@SuppressWarnings("ComparableImplementedButEqualsNotOverridden")
public class $bool
    extends AbstractRef<Boolean, $bool>
    implements Comparable<$bool>, BooleanSupplier {

    private static final long serialVersionUID = 8087914133902951131L;

    /** the value. */
    @SuppressWarnings("PublicField")
    public boolean $; // NOPMD

    /**
     * constructor.
     */
    protected $bool() { this(false); }

    /**
     * constructor.
     *
     * @param $ the value.
     */
    protected $bool(final boolean $) { this.$ = $; }

    @Override
    public void accept(final Boolean $) { this.$ = $; }

    /**
     * set value then return this instance.
     *
     * @param $ value
     * @return {@code this}
     */
    public $bool set(final boolean $) {
        this.$ = $;
        return this;
    }

    @Override
    public Boolean get() { return this.$; }

    @Override
    public boolean getAsBoolean() { return this.$; }

    @Override
    public int compareTo(final $bool that) { return this.compareTo(that.$); }

    public int compareTo(final boolean that) { return Boolean.compare(this.$, that); }

    /**
     * execute the procedure then negate the value if and only if the condition satisfied.
     *
     * @param cond condition
     * @param f a procedure
     */
// Path: src/main/java/jp/root42/indolently/function/Statement.java
// @FunctionalInterface
// public interface Statement
//     extends Runnable {
// 
//     Statement NOP = () -> {};
// 
//     /**
//      * Perform this operation.
//      *
//      * @throws Exception any exception which this statement would throw
//      */
//     void exec() throws Exception;
// 
//     /**
//      * Perform this operation.
//      */
//     @Override
//     default void run() {
//         try {
//             this.exec();
//         } catch (final Exception e) {
//             Expressive.raise(e);
//         }
//     }
// 
//     /**
//      * Returns composed statement which execute this statement then execute {@code after}.
//      *
//      * @param after statement which execute after this statement
//      * @return composed statement
//      */
//     default Statement andThen(final Statement after) {
// 
//         Objects.requireNonNull(after);
// 
//         return () -> {
//             this.run();
//             after.run();
//         };
//     }
// }


// Path: src/main/java/jp/root42/indolently/ref/$bool.java
import java.util.function.Predicate;
import jp.root42.indolently.function.Statement;
import java.util.function.BooleanSupplier;

// Copyright 2014 takahashikzn
//
// 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 jp.root42.indolently.ref;




/**
 * @author takahashikzn
 * @version $Id$
 */
@SuppressWarnings("ComparableImplementedButEqualsNotOverridden")
public class $bool
    extends AbstractRef<Boolean, $bool>
    implements Comparable<$bool>, BooleanSupplier {

    private static final long serialVersionUID = 8087914133902951131L;

    /** the value. */
    @SuppressWarnings("PublicField")
    public boolean $; // NOPMD

    /**
     * constructor.
     */
    protected $bool() { this(false); }

    /**
     * constructor.
     *
     * @param $ the value.
     */
    protected $bool(final boolean $) { this.$ = $; }

    @Override
    public void accept(final Boolean $) { this.$ = $; }

    /**
     * set value then return this instance.
     *
     * @param $ value
     * @return {@code this}
     */
    public $bool set(final boolean $) {
        this.$ = $;
        return this;
    }

    @Override
    public Boolean get() { return this.$; }

    @Override
    public boolean getAsBoolean() { return this.$; }

    @Override
    public int compareTo(final $bool that) { return this.compareTo(that.$); }

    public int compareTo(final boolean that) { return Boolean.compare(this.$, that); }

    /**
     * execute the procedure then negate the value if and only if the condition satisfied.
     *
     * @param cond condition
     * @param f a procedure
     */
    public void negateIf(final boolean cond, final Statement f) { this.negateIf(x -> x == cond, f); }