001: // ============================================================================
002: // $Id: AdaptorVisitor.java,v 1.7 2006/05/08 02:30:32 davidahall Exp $
003: // Copyright (c) 2005 David A. Hall
004: // ============================================================================
005: // The contents of this file are subject to the Common Development and
006: // Distribution License (CDDL), Version 1.0 (the License); you may not use this
007: // file except in compliance with the License. You should have received a copy
008: // of the the License along with this file: if not, a copy of the License is
009: // available from Sun Microsystems, Inc.
010: //
011: // http://www.sun.com/cddl/cddl.html
012: //
013: // From time to time, the license steward (initially Sun Microsystems, Inc.) may
014: // publish revised and/or new versions of the License. You may not use,
015: // distribute, or otherwise make this file available under subsequent versions
016: // of the License.
017: //
018: // Alternatively, the contents of this file may be used under the terms of the
019: // GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
020: // case the provisions of the LGPL are applicable instead of those above. If you
021: // wish to allow use of your version of this file only under the terms of the
022: // LGPL, and not to allow others to use your version of this file under the
023: // terms of the CDDL, indicate your decision by deleting the provisions above
024: // and replace them with the notice and other provisions required by the LGPL.
025: // If you do not delete the provisions above, a recipient may use your version
026: // of this file under the terms of either the CDDL or the LGPL.
027: //
028: // This library is distributed in the hope that it will be useful,
029: // but WITHOUT ANY WARRANTY; without even the implied warranty of
030: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
031: // ============================================================================
032:
033: package net.sf.jga.fn;
034:
035: import net.sf.jga.fn.adaptor.*;
036: import net.sf.jga.fn.logical.All;
037: import net.sf.jga.fn.logical.Any;
038: import java.util.Iterator;
039:
040: /**
041: * Visitor that performs a walk of compound functor structures. This visitor
042: * implements the Visitor interface associated with all of the compounding
043: * functors in the <a href="adaptor/package-summary.html">net.sf.jga.fn.adaptor</a>
044: * package, as well as the two that are in the
045: * <a href="logical/package-summary.html">net.sf.jga.fn.logical</a> package.
046: * <p>
047: * Basing visitors on this base class will allow most implementations to ignore
048: * the tree structure, and implement visiting the leaf node functors that are
049: * of interest. When used in this way, the tree nodes will be ignored by the
050: * visitor (exception that the visit walks through them). If the tree nodes
051: * are to be considered during the visit, then the implementation can override
052: * methods contained in this class: depending on where in the overridden
053: * implementation the call to super() occurs, either breadth-first, depth-first,
054: * or in-line traversal can be supported.
055: * <p>
056: * Copyright © 2005 David A. Hall
057: * @author <a href="mailto:davidahall@users.sf.net">David A. Hall</a>
058: */
059:
060: public class AdaptorVisitor extends AbstractVisitor implements
061: All.Visitor, AndBinary.Visitor, AndGenerator.Visitor,
062: AndUnary.Visitor, Any.Visitor, ApplyBinary.Visitor,
063: ApplyGenerator.Visitor, ApplyUnary.Visitor, Bind.Visitor,
064: Bind1st.Visitor, Bind2nd.Visitor, ChainBinary.Visitor,
065: ChainUnary.Visitor, ComposeBinary.Visitor,
066: ComposeUnary.Visitor, CompoundBinary.Visitor,
067: CompoundGenerator.Visitor, CompoundUnary.Visitor,
068: ConditionalBinary.Visitor, ConditionalGenerator.Visitor,
069: ConditionalUnary.Visitor, Distribute.Visitor, Generate.Visitor,
070: Generate1st.Visitor, Generate2nd.Visitor,
071: GenerateBinary.Visitor, GenerateUnary.Visitor,
072: OrBinary.Visitor, OrGenerator.Visitor, OrUnary.Visitor {
073: public void visit(All host) {
074: for (Iterator iter = host.branches(); iter.hasNext();) {
075: ((UnaryFunctor) iter.next()).accept(this );
076: }
077: }
078:
079: public void visit(AndBinary host) {
080: host.getFirstFunctor().accept(this );
081: host.getSecondFunctor().accept(this );
082: }
083:
084: public void visit(AndGenerator host) {
085: host.getFirstFunctor().accept(this );
086: host.getSecondFunctor().accept(this );
087: }
088:
089: public void visit(AndUnary host) {
090: host.getFirstFunctor().accept(this );
091: host.getSecondFunctor().accept(this );
092: }
093:
094: public void visit(Any host) {
095: for (Iterator iter = host.branches(); iter.hasNext();) {
096: ((UnaryFunctor) iter.next()).accept(this );
097: }
098: }
099:
100: public void visit(ApplyBinary host) {
101: BinaryFunctor[] fns = host.getFunctors();
102: for (int i = 0; i < fns.length; ++i)
103: fns[i].accept(this );
104: }
105:
106: public void visit(ApplyGenerator host) {
107: Generator[] fns = host.getGenerators();
108: for (int i = 0; i < fns.length; ++i)
109: fns[i].accept(this );
110: }
111:
112: public void visit(ApplyUnary host) {
113: UnaryFunctor[] fns = host.getFunctors();
114: for (int i = 0; i < fns.length; ++i)
115: fns[i].accept(this );
116: }
117:
118: public void visit(Bind host) {
119: host.getFunctor().accept(this );
120: }
121:
122: public void visit(Bind1st host) {
123: host.getFunctor().accept(this );
124: }
125:
126: public void visit(Bind2nd host) {
127: host.getFunctor().accept(this );
128: }
129:
130: public void visit(ChainBinary host) {
131: host.getInnerFunctor().accept(this );
132: host.getOuterFunctor().accept(this );
133: }
134:
135: public void visit(ChainUnary host) {
136: host.getInnerFunctor().accept(this );
137: host.getOuterFunctor().accept(this );
138: }
139:
140: public void visit(ComposeBinary host) {
141: host.getFirstInnerFunctor().accept(this );
142: host.getSecondInnerFunctor().accept(this );
143: host.getOuterFunctor().accept(this );
144: }
145:
146: public void visit(ComposeUnary host) {
147: host.getFirstInnerFunctor().accept(this );
148: host.getSecondInnerFunctor().accept(this );
149: host.getOuterFunctor().accept(this );
150: }
151:
152: public void visit(CompoundBinary host) {
153: host.getFirstFunctor().accept(this );
154: host.getSecondFunctor().accept(this );
155: }
156:
157: public void visit(CompoundGenerator host) {
158: host.getFirstFunctor().accept(this );
159: host.getSecondFunctor().accept(this );
160: }
161:
162: public void visit(CompoundUnary host) {
163: host.getFirstFunctor().accept(this );
164: host.getSecondFunctor().accept(this );
165: }
166:
167: public void visit(ConditionalBinary host) {
168: host.getCondition().accept(this );
169: host.getTrueFunctor().accept(this );
170: host.getFalseFunctor().accept(this );
171: }
172:
173: public void visit(ConditionalGenerator host) {
174: host.getCondition().accept(this );
175: host.getTrueFunctor().accept(this );
176: host.getFalseFunctor().accept(this );
177: }
178:
179: public void visit(ConditionalUnary host) {
180: host.getCondition().accept(this );
181: host.getTrueFunctor().accept(this );
182: host.getFalseFunctor().accept(this );
183: }
184:
185: public void visit(Distribute host) {
186: host.getFirstInnerFunctor().accept(this );
187: host.getSecondInnerFunctor().accept(this );
188: host.getOuterFunctor().accept(this );
189: }
190:
191: public void visit(Generate host) {
192: host.getFunctor().accept(this );
193: host.getGenerator().accept(this );
194: }
195:
196: public void visit(Generate1st host) {
197: host.getFunctor().accept(this );
198: host.getGenerator().accept(this );
199: }
200:
201: public void visit(Generate2nd host) {
202: host.getFunctor().accept(this );
203: host.getGenerator().accept(this );
204: }
205:
206: public void visit(GenerateUnary host) {
207: host.getGenerator().accept(this );
208: }
209:
210: public void visit(GenerateBinary host) {
211: host.getGenerator().accept(this );
212: }
213:
214: public void visit(OrBinary host) {
215: host.getFirstFunctor().accept(this );
216: host.getSecondFunctor().accept(this );
217: }
218:
219: public void visit(OrGenerator host) {
220: host.getFirstFunctor().accept(this );
221: host.getSecondFunctor().accept(this );
222: }
223:
224: public void visit(OrUnary host) {
225: host.getFirstFunctor().accept(this);
226: host.getSecondFunctor().accept(this);
227: }
228: }
|