01 
02 /*
03  *  JScripter Standard 1.0 - To Script In Java
04  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
05  *  
06  *  This program is free software: you can redistribute it and/or modify
07  *  it under the terms of the GNU Affero General Public License as published by
08  *  the Free Software Foundation, either version 3 of the License, or
09  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU Affero General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU Affero General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 package jsx.motion.reg;
21 
22 import jsx.motion.Regular;
23 
24 /**
25  * <p>An abstract class to define a composite regular function.</p>
26  * 
27  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
28  */
29 public abstract class Composite extends Regular
30 {
31     private final Regular composite;
32 
33     /**
34      * <p>Constructs a regular function of this type with the composite regular function 
35      * predefined for an argument.</p>
36      * <p>Interestingly, the actual composite function is defined and passed as an 
37      * argument of this constructor.</p>
38      * @param composite An actually expected composite function normally defined with a 
39      * anonymous class extending the base abstract class {@link Regular}.
40      * @since 1.0
41      */
42     protected Composite(Regular composite) {
43         this.composite = composite;
44     }
45 
46     /**
47      * <p>Computes and returns the value, depending on a specified variable, of the 
48      * regular function defined by this class.</p>
49      * <p>Interestingly, this method is modified as <tt>final</tt> and simply passes the 
50      * invocation to the regular function that has been passed to the typical constructor 
51      * of this class as argument when the current object is created.</p>
52      * @param x The independent variable.
53      * @return The value, depending on <tt>x</tt>, of the defined regular function.
54      * @since 1.0
55      */
56     @Override
57     protected final double function(double x) {
58         return call(composite, x);
59     }
60 }