Source code: com/trapezium/vrml/visitor/ComplexityData.java
1 /*
2 * @(#)ComplexityData.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.vrml.fields.Field;
14 import com.trapezium.vrml.fields.FieldValue;
15 import java.io.PrintStream;
16 import java.util.Vector;
17
18 /**
19 * Information related to complexity of a scene graph.
20 * <P>
21 * This is used to accumulate error and polygon count information during
22 * the processing of files. The ComplexityVisitor contains a ComplexityData
23 * element where it stores its information.
24 * <P>
25 * If several files are being processed, a single global ComplexityData
26 * object is used to contain the sum of their information. Each
27 * time a ComplexityVisitor completes its traversal of the scene graph,
28 * it updates the global ComplexityData with the data from that single
29 * traversal (see the "addInfo" method).
30 *
31 * @author Johannes N. Johannsen
32 * @version 1.1, 14 Jan 1998
33 *
34 * @since 1.0
35 */
36 public class ComplexityData {
37 int polygonCount;
38 int coneCount;
39 int sphereCount;
40 int cylinderCount;
41 int fileCount; // used when this is also a summary for alot of files
42 int warningCount;
43 int errorCount;
44 int nonconformanceCount;
45 Vector inlineFileList;
46
47 /** class constructor */
48 public ComplexityData() {
49 polygonCount = 0;
50 coneCount = 0;
51 sphereCount = 0;
52 cylinderCount = 0;
53 nonconformanceCount = 0;
54 warningCount = 0;
55 errorCount = 0;
56 fileCount = 0;
57 }
58
59 /** add an inline file if not already in the list */
60 public void incInline( String inlineUrl ) {
61 if ( inlineFileList == null ) {
62 inlineFileList = new Vector();
63 }
64 int inlineFileListSize = inlineFileList.size();
65 for ( int i = 0; i < inlineFileListSize; i++ ) {
66 String test = (String)inlineFileList.elementAt( i );
67 if ( test.compareTo( inlineUrl ) == 0 ) {
68 return;
69 }
70 }
71 inlineFileList.addElement( inlineUrl );
72 }
73
74 /** how many inline files were found? */
75 public int getInlineCount() {
76 if ( inlineFileList == null ) {
77 return( 0 );
78 } else {
79 return( inlineFileList.size() );
80 }
81 }
82
83 /** how many files were processed */
84 public int getFileCount() {
85 return( fileCount );
86 }
87
88 /** increment polygon count */
89 public void incPolygonCount( int inc ) {
90 polygonCount += inc;
91 }
92
93 /** increment cone count */
94 public void incConeCount() {
95 coneCount++;
96 }
97
98 /** increment sphere count */
99 public void incSphereCount() {
100 sphereCount++;
101 }
102
103 /** increment cylinder count */
104 public void incCylinderCount() {
105 cylinderCount++;
106 }
107
108 /** set the warning count, comes from LintVisitor */
109 public void setWarningCount( int wc ) {
110 warningCount = wc;
111 }
112
113 /** set the error count, comes from LintVisitor */
114 public void setErrorCount( int ec ) {
115 errorCount = ec;
116 }
117
118 /** Set the nonconformance count */
119 public void setNonconformanceCount( int ncc ) {
120 nonconformanceCount = ncc;
121 }
122
123 /** how many polygons were found? */
124 public int getPolygonCount() {
125 return( polygonCount );
126 }
127
128 /** how many cones were found? */
129 public int getConeCount() {
130 return( coneCount );
131 }
132
133 /** how many spheres were found? */
134 public int getSphereCount() {
135 return( sphereCount );
136 }
137
138 /** how many cylinders were found? */
139 public int getCylinderCount() {
140 return( cylinderCount );
141 }
142
143 /** how many warnings were encountered? */
144 public int getWarningCount() {
145 return( warningCount );
146 }
147
148 /** how many errors were encountered? */
149 public int getErrorCount() {
150 return( errorCount );
151 }
152
153 /** get nonconformance count */
154 public int getNonconformanceCount() {
155 return( nonconformanceCount );
156 }
157
158 /** add information from another complexity data object */
159 public void addInfo( ComplexityData cd ) {
160 fileCount++;
161 polygonCount += cd.getPolygonCount();
162 coneCount += cd.getConeCount();
163 sphereCount += cd.getSphereCount();
164 cylinderCount += cd.getCylinderCount();
165 warningCount += cd.getWarningCount();
166 nonconformanceCount += cd.getNonconformanceCount();
167 errorCount += cd.getErrorCount();
168 }
169
170 /** print summary information to a PrintStream */
171 public void summary( PrintStream ps ) {
172 if ( fileCount > 1 ) {
173 ps.println( "Summary for " + fileCount + " files:" );
174 if (( warningCount == 1 ) && ( errorCount == 1 )) {
175 ps.println( "1 warning, 1 error." );
176 } else if (( warningCount == 1 ) && ( errorCount > 1 )) {
177 ps.println( "1 warning, " + errorCount + " errors." );
178 } else if (( warningCount > 1 ) && ( errorCount == 1 )) {
179 ps.println( warningCount + " warnings, 1 error." );
180 } else if (( warningCount > 1 ) && ( errorCount > 1 )) {
181 ps.println( warningCount + " warnings, " + errorCount + " errors." );
182 } else if (( warningCount == 0 ) && ( errorCount == 1 )) {
183 ps.println( "1 error." );
184 } else if (( warningCount == 0 ) && ( errorCount > 1 )) {
185 ps.println( errorCount + " errors." );
186 } else if (( warningCount == 1 ) && ( errorCount == 0 )) {
187 ps.println( "1 warning." );
188 } else if (( warningCount > 1 ) && ( errorCount == 0 )) {
189 ps.println( warningCount + " warnings." );
190 }
191 if ( nonconformanceCount == 1 ) {
192 ps.println( "1 nonconformance." );
193 } else if ( nonconformanceCount > 1 ) {
194 ps.println( nonconformanceCount + " nonconformances." );
195 }
196 }
197 StringBuffer sb = new StringBuffer();
198 boolean doComma = false;
199 int totalCount = polygonCount;
200 boolean approx = false;
201 if ( sphereCount > 0 ) {
202 totalCount += sphereCount*40;
203 approx = true;
204 }
205 if ( coneCount > 0 ) {
206 totalCount += coneCount*12;
207 approx = true;
208 }
209 if ( cylinderCount > 0 ) {
210 totalCount += cylinderCount*12;
211 approx = true;
212 }
213 if ( totalCount > 0 ) {
214 if ( totalCount == 1 ) {
215 sb.append( "1 polygon" );
216 } else {
217 if ( approx ) {
218 sb.append( "Approximately " );
219 }
220 sb.append( totalCount + " polygons" );
221 }
222 doComma = true;
223 }
224 /* if ( sphereCount > 0 ) {
225 if ( doComma ) {
226 sb.append( ", " );
227 }
228 if ( sphereCount == 1 ) {
229 sb.append( "1 sphere" );
230 } else {
231 sb.append( sphereCount + " spheres" );
232 }
233 doComma = true;
234 }
235 if ( coneCount > 0 ) {
236 if ( doComma ) {
237 sb.append( ", " );
238 }
239 if ( coneCount == 1 ) {
240 sb.append( "1 cone" );
241 } else {
242 sb.append( coneCount + " cones" );
243 }
244 doComma = true;
245 }
246 if ( cylinderCount > 0 ) {
247 if ( doComma ) {
248 sb.append( ", " );
249 }
250 if ( cylinderCount == 1 ) {
251 sb.append( "1 cylinder" );
252 } else {
253 sb.append( cylinderCount + " cylinders" );
254 }
255 doComma = true;
256 }*/
257 if ( doComma ) {
258 sb.append( "." );
259 }
260 String s = new String( sb );
261 if ( s.length() > 0 ) {
262 ps.println( s );
263 } else if ( fileCount > 1 ) {
264 ps.println( "No polygons." );
265 }
266 }
267 }
268