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 BNFOptionalTest 00029 extends BNFAbstractTest { 00038 public BNFOptionalTest(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 if(collecting){collectedData.add(tests[nextTest].collect());} 00068 if(isLastTest()) { 00069 result.addCommittableTokens(committed); 00070 result.addReplayableTokens(playable); 00071 result.setResult(result.FINISHED); 00072 reset(); 00073 playable.clear(); 00074 committed.clear(); 00075 } else { 00076 result.setResult(result.UNFINISHED); 00077 nextTest++; 00078 00079 continue; 00080 } 00081 } else { 00082 committed.addAll(childResult.getCommittableTokens()); 00083 playable.addAll(0, childResult.getReplayableTokens()); 00084 result.addReplayableTokens(committed); 00085 result.addReplayableTokens(playable); 00086 result.setResult(result.FINISHED); 00087 collectedData.clear(); 00088 reset(); 00089 playable.clear(); 00090 committed.clear(); 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 BNFOptionalTest 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 */