Source code: com/trapezium/vrml/visitor/ChildCounter.java
1 /*
2 * @(#)ChildCounter.java
3 *
4 * Copyright (c) 1998 by Trapezium Development LLC. All Rights Reserved.
5 *
6 * The information in this file is the property of Trapezium Development LLC
7 * and may be used only in accordance with the terms of the license granted
8 * by Trapezium.
9 *
10 */
11 package com.trapezium.vrml.visitor;
12
13 import com.trapezium.pattern.Visitor;
14
15 import com.trapezium.parse.TokenEnumerator;
16 import com.trapezium.vrml.LeftBrace;
17 import com.trapezium.vrml.LeftBracket;
18 import com.trapezium.vrml.RightBrace;
19 import com.trapezium.vrml.RightBracket;
20
21 /**
22 * Counts all children that aren't brackets or braces.
23 *
24 * Probably should get rid of this, can be done more simply.
25 *
26 * @author Johannes N. Johannsen
27 * @version 1.1, 31 Oct 1997
28 *
29 * @since 1.0
30 */
31 public class ChildCounter extends Visitor {
32 int childCount;
33
34 /** class constructor */
35 public ChildCounter( TokenEnumerator v ) {
36 super( v );
37 childCount = 0;
38 }
39
40 /** visit an object, only down one level.
41 * <P>
42 * "visitLevel" is handled by Visitor class, is incremented each
43 * time we drop down a level in the scene graph, and is decremented
44 * each time we go up a level in the scene graph.
45 */
46 public boolean visitObject( Object a ) {
47 if ( visitLevel == 1 ) {
48 return( true );
49 } else {
50 if ( !(( a instanceof LeftBrace ) || ( a instanceof RightBrace ) ||
51 ( a instanceof LeftBracket ) || ( a instanceof RightBracket ))) {
52 childCount++;
53 }
54 return( false );
55 }
56 }
57
58 /** how many children VrmlElements were found? */
59 public int getChildCount() {
60 return( childCount );
61 }
62 }
63