Coverage Report - net.sourceforge.combean.mathprog.grooml.GDynamicSet
 
Classes in this File Line Coverage Branch Coverage Complexity
GDynamicSet
71%
5/7
67%
8/12
0
GDynamicSet$_evaluate_closure1
100%
1/1
75%
3/4
0
 
 1  
 /*
 2  
     This file is part of Combean.
 3  
 
 4  
     Combean is free software; you can redistribute it and/or modify
 5  
     it under the terms of the GNU General Public License as published by
 6  
     the Free Software Foundation; either version 2 of the License, or
 7  
     (at your option) any later version.
 8  
 
 9  
     Combean is distributed in the hope that it will be useful,
 10  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  
     GNU General Public License for more details.
 13  
 
 14  
     You should have received a copy of the GNU General Public License
 15  
     along with Foobar; if not, write to the Free Software
 16  
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 17  
 */
 18  
 package net.sourceforge.combean.mathprog.grooml;
 19  
 
 20  
 
 21  
 import net.sourceforge.combean.mathprog.grooml.GSet;
 22  
 
 23  
 /**
 24  
  * A set with a dynamic definition that is evaluated when the elements of the
 25  
  * set are being accessed.
 26  
  */
 27  
 class GDynamicSet extends GSet {
 28  
 
 29  
     private Closure genSet;
 30  
     
 31  
     /**
 32  
      * Constructor
 33  
      * 
 34  
      * @params genSet the closure that defines the set (must return a value that
 35  
      * is convertable to a set)
 36  
      */
 37  
     public GDynamicSet(Closure genSet) {
 38  60
         this.genSet = genSet;
 39  
     }
 40  
 
 41  
     public Iterator evaluate(Object env) {
 42  125
         this.genSet.delegate = env;
 43  125
         Object setDef = null;
 44  125
         use (GModelArithmeticCategory) {
 45  125
                 setDef = this.genSet.call();
 46  
         }
 47  125
         return GSet.convert(setDef).evaluate(env);
 48  
     }
 49  
     
 50  
     public String toString() {
 51  0
         String result = "dynSet { ${genSet.class.name} }";
 52  0
         return result;
 53  
     }
 54  
 }