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 00028 public class BNFOneOfManyRequiredTest 00029 extends BNFAbstractTest { 00038 public BNFOneOfManyRequiredTest(BNFTestImplementor tests[]) 00039 throws BNFTestException{super(tests);} 00040 00058 public BNFTestResult test(BNFTestableObject obj) { 00059 playable.add(0, obj); 00060 while(playable.size() > 0) { 00061 BNFTestableObject crntToken = playable.remove(0); 00062 BNFTestResult childResult = tests[nextTest].test(crntToken); 00063 if(childResult.isUnfinished()){result.setResult(result.UNFINISHED);} 00064 else if(childResult.isFinished()) { 00065 committed.addAll(childResult.getCommittableTokens()); 00066 playable.addAll(0, childResult.getReplayableTokens()); 00067 result.addCommittableTokens(committed); 00068 result.addReplayableTokens(playable); 00069 result.setResult(result.FINISHED); 00070 if(collecting){collectedData.add(tests[nextTest].collect());} 00071 reset(); 00072 playable.clear(); 00073 committed.clear(); 00074 } else { 00075 committed.addAll(childResult.getCommittableTokens()); 00076 playable.addAll(0, childResult.getReplayableTokens()); 00077 if(isLastTest()) { 00078 result.addReplayableTokens(committed); 00079 result.addReplayableTokens(playable); 00080 result.setResult(result.FAILED); 00081 collectedData.clear(); 00082 reset(); 00083 playable.clear(); 00084 committed.clear(); 00085 } else { 00086 result.setResult(result.UNFINISHED); 00087 nextTest++; 00088 00089 continue; 00090 } 00091 } 00092 } // end while 00093 BNFTestResult testResult = result; 00094 result = new BNFTestResult(); 00095 00096 return testResult; 00097 } // end method test 00098 00104 public String toString(){return super.toString();} 00105 } // end class BNFOneOfManyRequiredTest 00106 00107 00108 /* This material is distributed under the GNU General Public License. 00109 * For more information please go to http://www.gnu.org/copyleft/gpl.html 00110 */