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