001: package de.java2html.javasource;
002:
003: /**
004: * Simple statistics information that can be created when parsing a java source code using the
005: * {@link de.java2html.javasource.JavaSourceParser}.
006: * @author Markus Gebhard
007: */
008: public class JavaSourceStatistic {
009: private int commentLineCount = -1;
010: private int lineCount = -1;
011: private int codeLineCount = -1;
012: private int emptyLineCount = -1;
013: private int maxLineLength = -1;
014: private int characterCount = -1;
015: private String packageName = null;
016: private String fileName = null;
017:
018: public JavaSourceStatistic() {
019: //nothing to do
020: }
021:
022: /**
023: * Returns the codeLineCount.
024: * @return int
025: */
026: public int getCodeLineCount() {
027: return codeLineCount;
028: }
029:
030: /**
031: * Returns the commentLineCount.
032: * @return int
033: */
034: public int getCommentLineCount() {
035: return commentLineCount;
036: }
037:
038: /**
039: * Returns the emptyLineCount.
040: * @return int
041: */
042: public int getEmptyLineCount() {
043: return emptyLineCount;
044: }
045:
046: /**
047: * Returns the lineCount.
048: * @return int
049: */
050: public int getLineCount() {
051: return lineCount;
052: }
053:
054: /**
055: * Returns the maxLineLength.
056: * @return int
057: */
058: public int getMaxLineLength() {
059: return maxLineLength;
060: }
061:
062: /**
063: * Sets the codeLineCount.
064: * @param codeLineCount The codeLineCount to set
065: */
066: public void setCodeLineCount(int codeLineCount) {
067: this .codeLineCount = codeLineCount;
068: }
069:
070: /**
071: * Sets the commentLineCount.
072: * @param commentLineCount The commentLineCount to set
073: */
074: public void setCommentLineCount(int commentLineCount) {
075: this .commentLineCount = commentLineCount;
076: }
077:
078: /**
079: * Sets the emptyLineCount.
080: * @param emptyLineCount The emptyLineCount to set
081: */
082: public void setEmptyLineCount(int emptyLineCount) {
083: this .emptyLineCount = emptyLineCount;
084: }
085:
086: /**
087: * Sets the lineCount.
088: * @param lineCount The lineCount to set
089: */
090: public void setLineCount(int lineCount) {
091: this .lineCount = lineCount;
092: }
093:
094: /**
095: * Sets the maxLineLength.
096: * @param maxLineLength The maxLineLength to set
097: */
098: public void setMaxLineLength(int maxLineLength) {
099: this .maxLineLength = maxLineLength;
100: }
101:
102: /**
103: * Returns the fileName.
104: * @return String
105: */
106: public String getFileName() {
107: return fileName;
108: }
109:
110: /**
111: * Sets the fileName.
112: * @param fileName The fileName to set
113: */
114: public void setFileName(String fileName) {
115: this .fileName = fileName;
116: }
117:
118: public void clear() {
119: maxLineLength = 0;
120: lineCount = 0;
121: commentLineCount = 0;
122: codeLineCount = 0;
123: emptyLineCount = 0;
124: }
125:
126: public String getScreenString(String lineSeparator) {
127: StringBuffer result = new StringBuffer();
128: result.append(" Package: " + toString(packageName)
129: + " Filename: " + toString(fileName) + lineSeparator);
130: result.append(" Lines total: " + lineCount + " Code: "
131: + codeLineCount + " Comments: " + commentLineCount
132: + " Empty: " + emptyLineCount + lineSeparator);
133: result
134: .append(" " + characterCount
135: + " Characters, Maximum line length: "
136: + maxLineLength);
137: return result.toString();
138: }
139:
140: private String toString(Object value) {
141: return value == null ? "" : value.toString();
142: }
143:
144: public static String getExcelHeader() {
145: StringBuffer result = new StringBuffer();
146: result.append("package");
147: result.append("\t");
148: result.append("file");
149: result.append("\t");
150: result.append("lines total");
151: result.append("\t");
152: result.append("code lines");
153: result.append("\t");
154: result.append("comment lines");
155: result.append("\t");
156: result.append("empty lines");
157: result.append("\t");
158: result.append("characters total");
159: result.append("\t");
160: result.append("maximum line length");
161: return result.toString();
162: }
163:
164: public String getExcelString() {
165: StringBuffer result = new StringBuffer();
166: result.append(packageName);
167: result.append("\t");
168: result.append(fileName);
169: result.append("\t");
170: result.append(String.valueOf(lineCount));
171: result.append("\t");
172: result.append(String.valueOf(codeLineCount));
173: result.append("\t");
174: result.append(String.valueOf(commentLineCount));
175: result.append("\t");
176: result.append(String.valueOf(emptyLineCount));
177: result.append("\t");
178: result.append(String.valueOf(characterCount));
179: result.append("\t");
180: result.append(String.valueOf(maxLineLength));
181: return result.toString();
182: }
183:
184: /**
185: * Returns the characterCount.
186: * @return int
187: */
188: public int getCharacterCount() {
189: return characterCount;
190: }
191:
192: /**
193: * Sets the characterCount.
194: * @param characterCount The characterCount to set
195: */
196: public void setCharacterCount(int characterCount) {
197: this .characterCount = characterCount;
198: }
199:
200: /**
201: * Returns the packageName.
202: * @return String
203: */
204: public String getPackageName() {
205: return packageName;
206: }
207:
208: /**
209: * Sets the packageName.
210: * @param packageName The packageName to set
211: */
212: public void setPackageName(String packageName) {
213: this.packageName = packageName;
214: }
215:
216: }
|