Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

com/ohrasys/cad/bnf/BNFAbstractTest.java

Go to the documentation of this file.
00001 /* Copyright (C) 2004 Thomas N. Valine
00002  * tvaline@users.sourceforge.net
00003  *
00004  * This program is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License as published by the
00006  * Free Software Foundation; either version 2 of the License, or (at your
00007  * option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License along
00015  * with this program; if not, write to the Free Software Foundation, Inc.,
00016  * 59 Temple Place - Suite 330, Boston, MA
00017  * 02111-1307, USA. */
00018 
00019 package com.ohrasys.cad.bnf;
00020 import java.util.*;
00021 
00029 public abstract class BNFAbstractTest
00030 implements BNFTestImplementor {
00032   protected static BNFI18NFactory i18n;
00033 
00035   protected List<Object> collectedData;
00036 
00038   protected boolean collecting;
00039   protected boolean formatting;
00040 
00042   protected List<BNFTestableObject> committed;
00043 
00045   protected int nextTest;
00046 
00048   protected List<BNFTestableObject> playable;
00049 
00051   protected BNFTestResult result;
00052 
00054   protected BNFTestImplementor tests[];
00055 
00064   public BNFAbstractTest(BNFTestImplementor tests[])
00065     throws BNFTestException {
00066     this.collecting    = false;
00067     this.tests         = tests;
00068     this.result        = new BNFTestResult();
00069     this.playable      = new Vector<BNFTestableObject>();
00070     this.committed     = new Vector<BNFTestableObject>();
00071     this.collectedData = new Vector<Object>();
00072     checkTests();
00073     reset();
00074   }
00075 
00086   public abstract BNFTestResult test(BNFTestableObject obj);
00087 
00094   public Object collect() {
00095     List<Object> result;
00096     if(collecting) {
00097       result        = collectedData;
00098       collectedData = new Vector<Object>();
00099     } else{result = new Vector<Object>(0);}
00100 
00101     return result;
00102   }
00103 
00105   public void reset() {
00106     nextTest = 0;
00107     if(tests != null) {
00108       for(int i = 0;i < tests.length;i++) {
00109         if(tests[i] != null){tests[i].reset();}
00110       }
00111     }
00112   }
00113 
00120   public void setCollecting(boolean isCollecting) {
00121     collecting = isCollecting;
00122     if(tests != null) {
00123       for(int i = 0;i < tests.length;i++) {
00124         tests[i].setCollecting(isCollecting);
00125       }
00126     }
00127   }
00128   public void setFormatting(boolean isFormatting) {
00129     formatting = isFormatting;
00130     if(tests != null) {
00131       for(int i = 0;i < tests.length;i++) {
00132         tests[i].setFormatting(isFormatting);
00133       }
00134     }
00135   }
00136 
00142   public String toString() {
00143     String name     = getClass().getName();
00144     int    numtests = tests.length;
00145 
00146     return String.format(i18n.getString(i18n.i18n_CHLD_TSTS), name,
00147         numtests);
00148   }
00149 
00156   protected void checkTests()
00157     throws BNFTestException {
00158     if((tests == null) || (tests.length == 0)) {
00159       throw new BNFTestException(
00160         i18n.getString(i18n.i18n_TST_REQD));
00161     }
00162     for(int i = 0;i < tests.length;i++) {
00163       if(tests[i] == null) {
00164         throw new BNFTestException(
00165           i18n.getString(i18n.i18n_TST_REQD));
00166       }
00167     }
00168   }
00169 
00175   protected boolean isFirstTest() {
00176     if((tests == null) || (tests.length == 0)){return true;}
00177     else{return nextTest == 0;}
00178   }
00179 
00185   protected boolean isLastTest() {
00186     if((tests == null) || (tests.length == 0)){return true;}
00187     else{return nextTest == (tests.length - 1);}
00188   }
00189 
00196   protected boolean isNotLastTest(){return !isLastTest();}
00197 } // end class BNFAbstractTest
00198 
00199 
00200 /* This material is distributed under the GNU General Public License.
00201  * For more information please go to http://www.gnu.org/copyleft/gpl.html
00202  */

Generated on Sun Nov 13 10:13:03 2005 for JavaBackus-NaurTestAPI(JBNT) by  doxygen 1.4.2