KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jga > fn > AdaptorVisitor


1 // ============================================================================
2
// $Id: AdaptorVisitor.java,v 1.7 2006/05/08 02:30:32 davidahall Exp $
3
// Copyright (c) 2005 David A. Hall
4
// ============================================================================
5
// The contents of this file are subject to the Common Development and
6
// Distribution License (CDDL), Version 1.0 (the License); you may not use this
7
// file except in compliance with the License. You should have received a copy
8
// of the the License along with this file: if not, a copy of the License is
9
// available from Sun Microsystems, Inc.
10
//
11
// http://www.sun.com/cddl/cddl.html
12
//
13
// From time to time, the license steward (initially Sun Microsystems, Inc.) may
14
// publish revised and/or new versions of the License. You may not use,
15
// distribute, or otherwise make this file available under subsequent versions
16
// of the License.
17
//
18
// Alternatively, the contents of this file may be used under the terms of the
19
// GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
20
// case the provisions of the LGPL are applicable instead of those above. If you
21
// wish to allow use of your version of this file only under the terms of the
22
// LGPL, and not to allow others to use your version of this file under the
23
// terms of the CDDL, indicate your decision by deleting the provisions above
24
// and replace them with the notice and other provisions required by the LGPL.
25
// If you do not delete the provisions above, a recipient may use your version
26
// of this file under the terms of either the CDDL or the LGPL.
27
//
28
// This library is distributed in the hope that it will be useful,
29
// but WITHOUT ANY WARRANTY; without even the implied warranty of
30
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
31
// ============================================================================
32

33 package net.sf.jga.fn;
34
35 import net.sf.jga.fn.adaptor.*;
36 import net.sf.jga.fn.logical.All;
37 import net.sf.jga.fn.logical.Any;
38 import java.util.Iterator JavaDoc;
39
40
41 /**
42  * Visitor that performs a walk of compound functor structures. This visitor
43  * implements the Visitor interface associated with all of the compounding
44  * functors in the <a HREF="adaptor/package-summary.html">net.sf.jga.fn.adaptor</a>
45  * package, as well as the two that are in the
46  * <a HREF="logical/package-summary.html">net.sf.jga.fn.logical</a> package.
47  * <p>
48  * Basing visitors on this base class will allow most implementations to ignore
49  * the tree structure, and implement visiting the leaf node functors that are
50  * of interest. When used in this way, the tree nodes will be ignored by the
51  * visitor (exception that the visit walks through them). If the tree nodes
52  * are to be considered during the visit, then the implementation can override
53  * methods contained in this class: depending on where in the overridden
54  * implementation the call to super() occurs, either breadth-first, depth-first,
55  * or in-line traversal can be supported.
56  * <p>
57  * Copyright &copy; 2005 David A. Hall
58  * @author <a HREF="mailto:davidahall@users.sf.net">David A. Hall</a>
59  */

60
61 public class AdaptorVisitor extends AbstractVisitor
62         implements
63             All.Visitor,
64             AndBinary.Visitor,
65             AndGenerator.Visitor,
66             AndUnary.Visitor,
67             Any.Visitor,
68             ApplyBinary.Visitor,
69             ApplyGenerator.Visitor,
70             ApplyUnary.Visitor,
71             Bind.Visitor,
72             Bind1st.Visitor,
73             Bind2nd.Visitor,
74             ChainBinary.Visitor,
75             ChainUnary.Visitor,
76             ComposeBinary.Visitor,
77             ComposeUnary.Visitor,
78             CompoundBinary.Visitor,
79             CompoundGenerator.Visitor,
80             CompoundUnary.Visitor,
81             ConditionalBinary.Visitor,
82             ConditionalGenerator.Visitor,
83             ConditionalUnary.Visitor,
84             Distribute.Visitor,
85             Generate.Visitor,
86             Generate1st.Visitor,
87             Generate2nd.Visitor,
88             GenerateBinary.Visitor,
89             GenerateUnary.Visitor,
90             OrBinary.Visitor,
91             OrGenerator.Visitor,
92             OrUnary.Visitor
93 {
94     public void visit(All host) {
95         for(Iterator JavaDoc iter = host.branches(); iter.hasNext(); ) {
96             ((UnaryFunctor) iter.next()).accept(this);
97         }
98     }
99     
100     public void visit(AndBinary host) {
101         host.getFirstFunctor().accept(this);
102         host.getSecondFunctor().accept(this);
103     }
104         
105     public void visit(AndGenerator host) {
106         host.getFirstFunctor().accept(this);
107         host.getSecondFunctor().accept(this);
108     }
109         
110     public void visit(AndUnary host) {
111         host.getFirstFunctor().accept(this);
112         host.getSecondFunctor().accept(this);
113     }
114         
115     public void visit(Any host) {
116         for(Iterator JavaDoc iter = host.branches(); iter.hasNext(); ) {
117             ((UnaryFunctor) iter.next()).accept(this);
118         }
119     }
120     
121     public void visit(ApplyBinary host) {
122         BinaryFunctor[] fns = host.getFunctors();
123         for (int i = 0; i < fns.length; ++i)
124             fns[i].accept(this);
125     }
126
127     public void visit(ApplyGenerator host) {
128         Generator[] fns = host.getGenerators();
129         for (int i = 0; i < fns.length; ++i)
130             fns[i].accept(this);
131     }
132         
133     public void visit(ApplyUnary host) {
134         UnaryFunctor[] fns = host.getFunctors();
135         for (int i = 0; i < fns.length; ++i)
136             fns[i].accept(this);
137     }
138         
139     public void visit(Bind host) {
140         host.getFunctor().accept(this);
141     }
142         
143     public void visit(Bind1st host) {
144         host.getFunctor().accept(this);
145     }
146         
147     public void visit(Bind2nd host) {
148         host.getFunctor().accept(this);
149     }
150         
151     public void visit(ChainBinary host) {
152         host.getInnerFunctor().accept(this);
153         host.getOuterFunctor().accept(this);
154     }
155         
156     public void visit(ChainUnary host) {
157         host.getInnerFunctor().accept(this);
158         host.getOuterFunctor().accept(this);
159     }
160         
161     public void visit(ComposeBinary host) {
162         host.getFirstInnerFunctor().accept(this);
163         host.getSecondInnerFunctor().accept(this);
164         host.getOuterFunctor().accept(this);
165     }
166         
167     public void visit(ComposeUnary host) {
168         host.getFirstInnerFunctor().accept(this);
169         host.getSecondInnerFunctor().accept(this);
170         host.getOuterFunctor().accept(this);
171     }
172         
173     public void visit(CompoundBinary host) {
174         host.getFirstFunctor().accept(this);
175         host.getSecondFunctor().accept(this);
176     }
177         
178     public void visit(CompoundGenerator host) {
179         host.getFirstFunctor().accept(this);
180         host.getSecondFunctor().accept(this);
181     }
182         
183     public void visit(CompoundUnary host) {
184         host.getFirstFunctor().accept(this);
185         host.getSecondFunctor().accept(this);
186     }
187         
188     public void visit(ConditionalBinary host) {
189         host.getCondition().accept(this);
190         host.getTrueFunctor().accept(this);
191         host.getFalseFunctor().accept(this);
192     }
193         
194     public void visit(ConditionalGenerator host) {
195         host.getCondition().accept(this);
196         host.getTrueFunctor().accept(this);
197         host.getFalseFunctor().accept(this);
198     }
199         
200     public void visit(ConditionalUnary host) {
201         host.getCondition().accept(this);
202         host.getTrueFunctor().accept(this);
203         host.getFalseFunctor().accept(this);
204     }
205         
206     public void visit(Distribute host) {
207         host.getFirstInnerFunctor().accept(this);
208         host.getSecondInnerFunctor().accept(this);
209         host.getOuterFunctor().accept(this);
210     }
211         
212     public void visit(Generate host) {
213         host.getFunctor().accept(this);
214         host.getGenerator().accept(this);
215     }
216         
217     public void visit(Generate1st host) {
218         host.getFunctor().accept(this);
219         host.getGenerator().accept(this);
220     }
221         
222     public void visit(Generate2nd host) {
223         host.getFunctor().accept(this);
224         host.getGenerator().accept(this);
225     }
226         
227     public void visit(GenerateUnary host) {
228         host.getGenerator().accept(this);
229     }
230         
231     public void visit(GenerateBinary host) {
232         host.getGenerator().accept(this);
233     }
234
235     public void visit(OrBinary host) {
236         host.getFirstFunctor().accept(this);
237         host.getSecondFunctor().accept(this);
238     }
239         
240     public void visit(OrGenerator host) {
241         host.getFirstFunctor().accept(this);
242         host.getSecondFunctor().accept(this);
243     }
244         
245     public void visit(OrUnary host) {
246         host.getFirstFunctor().accept(this);
247         host.getSecondFunctor().accept(this);
248     }
249 }
250
Popular Tags