/*
 * Copyright (c) 2009 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 *
 */

package com.jscape.util.functor;

import java.io.Serializable;

/**
 * @author Alex Usun
 */
public abstract class UnaryProcedure<V>
        implements Serializable {

    /**
     * @param value value
     */
    public abstract void evaluate(V value);

    /**
     * @param next next
     *
     * @return UnaryProcedure instance
     */
    public UnaryProcedure<V> then(UnaryProcedure<? super V> next) {
        return new Chain<V>(this, next);
    }

    /**
     * @param <T> <T>
     */
    public static class Chain<T>
            extends UnaryProcedure<T> {

        private UnaryProcedure<? super T> first;
        private UnaryProcedure<? super T> second;

        /**
         * @param first  first
         * @param second second
         */
        private Chain(UnaryProcedure<? super T> first, UnaryProcedure<? super T> second) {
            this.first = first;
            this.second = second;
        }

        /**
         * @param value value
         */
        public void evaluate(T value) {
            this.first.evaluate(value);
            this.second.evaluate(value);
        }

    }


}