| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.phoenix.report; |
| 34 | | | |
| 35 | | | import java.io.Serializable; |
| 36 | | | import java.text.DecimalFormat; |
| 37 | | | import java.text.NumberFormat; |
| 38 | | | import java.util.Comparator; |
| 39 | | | import java.util.Iterator; |
| 40 | | | |
| 41 | | | import org.jcoderz.commons.util.Assert; |
| 42 | | | import org.jcoderz.commons.util.StringUtil; |
| 43 | | | import org.jcoderz.phoenix.report.jaxb.File; |
| 44 | | | import org.jcoderz.phoenix.report.jaxb.Item; |
| 45 | | | |
| 46 | | | |
| 47 | | | |
| 48 | | | |
| 49 | | | |
| 50 | | | <p> |
| 51 | | | </p> |
| 52 | | | |
| 53 | | | @author |
| 54 | | | |
| 55 | | | public final class FileSummary |
| 56 | | | implements Comparable<FileSummary> |
| 57 | | | { |
| 58 | | | |
| 59 | | | private static final int STRING_BUFFER_SIZE = 256; |
| 60 | | | |
| 61 | | | |
| 62 | | | private static final int MAX_PERCENTAGE = 100; |
| 63 | | | |
| 64 | | | private static final float MAX_PERCENTAGE_FLOAT = 100; |
| 65 | | | |
| 66 | 100 | | private final NumberFormat mCoveragePercantageFormatter = |
| 67 | | | new DecimalFormat("##0.00"); |
| 68 | | | |
| 69 | | | |
| 70 | 100 | | private int mFiles = 0; |
| 71 | | | |
| 72 | | | |
| 73 | | | private int mLinesOfCode; |
| 74 | | | |
| 75 | | | |
| 76 | | | |
| 77 | | | |
| 78 | | | |
| 79 | | | private int mCoveredLinesOfCode; |
| 80 | | | |
| 81 | | | |
| 82 | | | |
| 83 | | | |
| 84 | 100 | | private int[] mViolations = new int[Severity.VALUES.size()]; |
| 85 | | | |
| 86 | | | |
| 87 | | | |
| 88 | | | <code></code> |
| 89 | | | |
| 90 | | | |
| 91 | 100 | | private int[] mPercent = new int[Severity.VALUES.size()]; |
| 92 | 100 | | private boolean mPercentUpToDate = false; |
| 93 | | | |
| 94 | | | private final String mClassName; |
| 95 | | | private final String mPackage; |
| 96 | | | private final String mDetailedFile; |
| 97 | | | private boolean mCoverageData; |
| 98 | | | |
| 99 | | | |
| 100 | | | |
| 101 | | | |
| 102 | | | |
| 103 | | | public FileSummary () |
| 104 | | | { |
| 105 | 100 | | this ("Global Summary", "all", null, 0, false); |
| 106 | 100 | | } |
| 107 | | | |
| 108 | | | |
| 109 | | | |
| 110 | | | |
| 111 | | | |
| 112 | | | @param |
| 113 | | | |
| 114 | | | |
| 115 | | | public FileSummary (String packagename) |
| 116 | | | { |
| 117 | 0 | | this ("Package Summary", packagename, null, 0, false); |
| 118 | 0 | | } |
| 119 | | | |
| 120 | | | |
| 121 | | | |
| 122 | | | |
| 123 | | | |
| 124 | | | @param |
| 125 | | | |
| 126 | | | @param |
| 127 | | | |
| 128 | | | @param |
| 129 | | | |
| 130 | | | @param |
| 131 | | | @param |
| 132 | | | |
| 133 | | | |
| 134 | | | public FileSummary (String className, String packagename, |
| 135 | | | String reportfile, int linesOfCode, boolean withCoverage) |
| 136 | 100 | | { |
| 137 | 100 | | mClassName = className; |
| 138 | 100 | | mPackage = packagename; |
| 139 | 100 | | mDetailedFile = reportfile; |
| 140 | 100 | | mLinesOfCode = linesOfCode; |
| 141 | 100 | | mCoverageData = withCoverage; |
| 142 | 100 | | } |
| 143 | | | |
| 144 | | | |
| 145 | | | |
| 146 | | | @param |
| 147 | | | |
| 148 | | | @param |
| 149 | | | |
| 150 | | | |
| 151 | | | @return |
| 152 | | | |
| 153 | | | public static float calculateQuality (int loc, int[] violations) |
| 154 | | | { |
| 155 | 0 | | float quality = 0; |
| 156 | 0 | | if (loc > 0) |
| 157 | | | { |
| 158 | 0 | | quality = calcUnweightedQuality(loc, violations); |
| 159 | 0 | | quality = (quality * MAX_PERCENTAGE) / loc; |
| 160 | | | } |
| 161 | 0 | | return quality; |
| 162 | | | } |
| 163 | | | |
| 164 | | | |
| 165 | | | |
| 166 | | | <code></code><code></code> |
| 167 | | | @param |
| 168 | | | |
| 169 | | | @param |
| 170 | | | |
| 171 | | | |
| 172 | | | @return |
| 173 | | | |
| 174 | | | private static int calcUnweightedQuality (int loc, int[] violations) |
| 175 | | | { |
| 176 | 0 | | Assert.assertEquals( |
| 177 | | | "Violations array length must match number of severities.", |
| 178 | | | Severity.VALUES.size(), violations.length); |
| 179 | 0 | | int quality = loc * Severity.PENALTY_SCALE; |
| 180 | 0 | | for (int i = 0; i < Severity.VALUES.size() && quality > 0; i++) |
| 181 | | | { |
| 182 | | | |
| 183 | | | |
| 184 | 0 | | quality -= violations[i] * Severity.fromInt(i).getPenalty(); |
| 185 | | | } |
| 186 | 0 | | if (quality < 0) |
| 187 | | | { |
| 188 | 0 | | quality = 0; |
| 189 | | | } |
| 190 | | | else |
| 191 | | | { |
| 192 | 0 | | quality /= Severity.PENALTY_SCALE; |
| 193 | | | } |
| 194 | 0 | | return quality; |
| 195 | | | } |
| 196 | | | |
| 197 | | | |
| 198 | | | |
| 199 | | | <code></code><code></code> |
| 200 | | | @param |
| 201 | | | |
| 202 | | | @param |
| 203 | | | @param |
| 204 | | | @param |
| 205 | | | @param |
| 206 | | | @param |
| 207 | | | @param |
| 208 | | | @param |
| 209 | | | @param |
| 210 | | | @return |
| 211 | | | |
| 212 | | | public static float calculateQuality (int loc, int info, int warning, |
| 213 | | | int error, int coverage, int filtered, int codestyle, int design, |
| 214 | | | int cpd) |
| 215 | | | { |
| 216 | 0 | | final int[] violations = new int[Severity.VALUES.size()]; |
| 217 | 0 | | violations[Severity.INFO.toInt()] = info; |
| 218 | 0 | | violations[Severity.COVERAGE.toInt()] = coverage; |
| 219 | 0 | | violations[Severity.WARNING.toInt()] = warning; |
| 220 | 0 | | violations[Severity.ERROR.toInt()] = error; |
| 221 | 0 | | violations[Severity.FILTERED.toInt()] = filtered; |
| 222 | 0 | | violations[Severity.CODE_STYLE.toInt()] = codestyle; |
| 223 | 0 | | violations[Severity.DESIGN.toInt()] = design; |
| 224 | 0 | | violations[Severity.CPD.toInt()] = cpd; |
| 225 | 0 | | return FileSummary.calculateQuality(loc, violations); |
| 226 | | | } |
| 227 | | | |
| 228 | | | |
| 229 | | | @return |
| 230 | | | public String getClassName () |
| 231 | | | { |
| 232 | 0 | | return mClassName; |
| 233 | | | } |
| 234 | | | |
| 235 | | | @return |
| 236 | | | public String getPackage () |
| 237 | | | { |
| 238 | 0 | | return mPackage; |
| 239 | | | } |
| 240 | | | |
| 241 | | | @return |
| 242 | | | public int getNumberOfFiles () |
| 243 | | | { |
| 244 | 0 | | return mFiles; |
| 245 | | | } |
| 246 | | | |
| 247 | | | {@inheritDoc} |
| 248 | | | public String toString () |
| 249 | | | { |
| 250 | 0 | | final StringBuilder result = new StringBuilder(); |
| 251 | 0 | | calcPercent(); |
| 252 | | | |
| 253 | 0 | | result.append(getFullClassName()); |
| 254 | 0 | | result.append("{ LOC:"); |
| 255 | 0 | | result.append(mLinesOfCode); |
| 256 | 0 | | result.append('('); |
| 257 | 0 | | result.append(mViolations[Severity.OK.toInt()]); |
| 258 | 0 | | result.append("%)"); |
| 259 | 0 | (1) | final Iterator<Severity> i = Severity.VALUES.iterator(); |
| 260 | 0 | | while (i.hasNext()) |
| 261 | | | { |
| 262 | 0 | | final Severity s = i.next(); |
| 263 | 0 | | if (mViolations[s.toInt()] != 0) |
| 264 | | | { |
| 265 | 0 | | result.append(", "); |
| 266 | 0 | | result.append(s.toString()); |
| 267 | 0 | | result.append(':'); |
| 268 | 0 | | result.append(mViolations[s.toInt()]); |
| 269 | 0 | | result.append('('); |
| 270 | 0 | | result.append(mPercent[s.toInt()]); |
| 271 | 0 | | result.append("%)"); |
| 272 | | | } |
| 273 | 0 | | } |
| 274 | 0 | | result.append('}'); |
| 275 | 0 | | return result.toString(); |
| 276 | | | } |
| 277 | | | |
| 278 | | | |
| 279 | | | |
| 280 | | | @param |
| 281 | | | |
| 282 | | | public void add (FileSummary other) |
| 283 | | | { |
| 284 | 0 | | for (int i = 0; i < mViolations.length; i++) |
| 285 | | | { |
| 286 | 0 | | mViolations[i] += other.mViolations[i]; |
| 287 | | | } |
| 288 | 0 | | mLinesOfCode += other.mLinesOfCode; |
| 289 | 0 | | mCoveredLinesOfCode += other.mCoveredLinesOfCode; |
| 290 | 0 | | mPercentUpToDate = false; |
| 291 | 0 | | mFiles++; |
| 292 | 0 | | if (mCoverageData || other.isWithCoverage() |
| 293 | | | || mCoveredLinesOfCode > 0 |
| 294 | | | || getNotCoveredLinesOfCode() > 0) |
| 295 | | | { |
| 296 | 0 | | mCoverageData = true; |
| 297 | | | } |
| 298 | 0 | | } |
| 299 | | | |
| 300 | | | |
| 301 | | | |
| 302 | | | @param |
| 303 | | | |
| 304 | | | public void add (File file) |
| 305 | | | { |
| 306 | 0 | | mFiles++; |
| 307 | 0 | | mLinesOfCode += file.getLoc(); |
| 308 | 0 | (2) | final Iterator<Item> i = file.getItem().iterator(); |
| 309 | 0 | | while (i.hasNext()) |
| 310 | | | { |
| 311 | 0 | | final Item item = i.next(); |
| 312 | 0 | | final Severity severity = item.getSeverity(); |
| 313 | 0 | | addViolation(severity); |
| 314 | 0 | | } |
| 315 | 0 | | } |
| 316 | | | |
| 317 | | | |
| 318 | | | |
| 319 | | | @return |
| 320 | | | |
| 321 | | | public boolean isWithCoverage () |
| 322 | | | { |
| 323 | 0 | | return mCoverageData; |
| 324 | | | } |
| 325 | | | |
| 326 | | | |
| 327 | | | public void addCoveredLine () |
| 328 | | | { |
| 329 | 0 | | mPercentUpToDate = false; |
| 330 | 0 | | mCoveredLinesOfCode++; |
| 331 | 0 | | } |
| 332 | | | |
| 333 | | | |
| 334 | | | |
| 335 | | | @param |
| 336 | | | |
| 337 | | | public void addViolation (Severity severity) |
| 338 | | | { |
| 339 | 100 | | Assert.notNull(severity, "severity"); |
| 340 | 100 | | mPercentUpToDate = false; |
| 341 | 100 | | mViolations[severity.toInt()]++; |
| 342 | 100 | | } |
| 343 | | | |
| 344 | | | |
| 345 | | | @return |
| 346 | | | |
| 347 | | | public String getFullClassName () |
| 348 | | | { |
| 349 | | | final String fullClassName; |
| 350 | 0 | | if (StringUtil.isEmptyOrNull(mPackage)) |
| 351 | | | { |
| 352 | 0 | | fullClassName = mClassName; |
| 353 | | | } |
| 354 | | | else |
| 355 | | | { |
| 356 | 0 | | fullClassName = mPackage + "." + mClassName; |
| 357 | | | } |
| 358 | 0 | | return fullClassName; |
| 359 | | | } |
| 360 | | | |
| 361 | | | @return |
| 362 | | | public String getHtmlLink () |
| 363 | | | { |
| 364 | 0 | | return mDetailedFile; |
| 365 | | | } |
| 366 | | | |
| 367 | | | @return |
| 368 | | | public int getLinesOfCode () |
| 369 | | | { |
| 370 | 0 | | return mLinesOfCode; |
| 371 | | | } |
| 372 | | | |
| 373 | | | |
| 374 | | | |
| 375 | | | |
| 376 | | | |
| 377 | | | @return |
| 378 | | | |
| 379 | | | public int getQuality () |
| 380 | | | { |
| 381 | 0 | | int quality = 0; |
| 382 | 0 | | if (mLinesOfCode > 0) |
| 383 | | | { |
| 384 | 0 | | quality = calcUnweightedQuality(mLinesOfCode, mViolations); |
| 385 | 0 | | quality = (quality * MAX_PERCENTAGE) / mLinesOfCode; |
| 386 | | | } |
| 387 | 0 | | return quality; |
| 388 | | | } |
| 389 | | | |
| 390 | | | |
| 391 | | | |
| 392 | | | |
| 393 | | | |
| 394 | | | @return |
| 395 | | | |
| 396 | | | public float getQualityAsFloat () |
| 397 | | | { |
| 398 | | | |
| 399 | 0 | | return FileSummary.calculateQuality (mLinesOfCode, mViolations); |
| 400 | | | } |
| 401 | | | |
| 402 | | | |
| 403 | | | |
| 404 | | | |
| 405 | | | @return |
| 406 | | | |
| 407 | | | public String getPercentBar () |
| 408 | | | { |
| 409 | 0 | | calcPercent(); |
| 410 | 0 | | final StringBuilder sb = new StringBuilder(STRING_BUFFER_SIZE); |
| 411 | 0 | | sb.append("<table width='100%' cellspacing='0' cellpadding='0' " |
| 412 | | | + "summary='quality-bar'><tr valign='middle'>"); |
| 413 | 0 | | for (int i = Severity.OK.toInt(); i < Severity.MAX_SEVERITY_INT; i++) |
| 414 | | | { |
| 415 | 0 | | if (mPercent[i] > 0) |
| 416 | | | { |
| 417 | 0 | | sb.append("<td class='"); |
| 418 | 0 | | sb.append(Severity.fromInt(i).toString()); |
| 419 | 0 | | sb.append("' width='"); |
| 420 | 0 | | sb.append(mPercent[i]); |
| 421 | 0 | | sb.append("%' height='10'></td>"); |
| 422 | | | } |
| 423 | | | } |
| 424 | 0 | | sb.append("</tr></table>"); |
| 425 | 0 | | return sb.toString(); |
| 426 | | | } |
| 427 | | | |
| 428 | | | |
| 429 | | | |
| 430 | | | |
| 431 | | | |
| 432 | | | @return |
| 433 | | | |
| 434 | | | public String getCoverageBar () |
| 435 | | | { |
| 436 | 0 | | final int notCovered = MAX_PERCENTAGE - getCoverage(); |
| 437 | | | |
| 438 | 0 | | final StringBuilder sb = new StringBuilder(STRING_BUFFER_SIZE); |
| 439 | 0 | | sb.append("<table width='100%' cellspacing='0' cellpadding='0' " |
| 440 | | | + "summary='coverage-bar'><tr valign='middle'>"); |
| 441 | 0 | | if (notCovered < MAX_PERCENTAGE) |
| 442 | | | { |
| 443 | 0 | | sb.append("<td class='ok' width='"); |
| 444 | 0 | | sb.append(MAX_PERCENTAGE - notCovered); |
| 445 | 0 | | sb.append("%' height='10'></td>"); |
| 446 | | | } |
| 447 | 0 | | if (notCovered != 0) |
| 448 | | | { |
| 449 | 0 | | sb.append("<td class='error' width='"); |
| 450 | 0 | | sb.append(notCovered); |
| 451 | 0 | | sb.append("%' height='10'></td></tr>"); |
| 452 | | | } |
| 453 | 0 | | sb.append("</tr></table>"); |
| 454 | 0 | | return sb.toString(); |
| 455 | | | } |
| 456 | | | |
| 457 | | | |
| 458 | | | |
| 459 | | | @param |
| 460 | | | @return |
| 461 | | | |
| 462 | | | public int getViolations (Severity severity) |
| 463 | | | { |
| 464 | 0 | | return mViolations[severity.toInt()]; |
| 465 | | | } |
| 466 | | | |
| 467 | | | |
| 468 | | | |
| 469 | | | @return |
| 470 | | | |
| 471 | | | public float getCoverageAsFloat () |
| 472 | | | { |
| 473 | 0 | | final float allLinesOfCode |
| 474 | | | = getNotCoveredLinesOfCode() + mCoveredLinesOfCode; |
| 475 | | | float result; |
| 476 | 0 | | if (allLinesOfCode != 0) |
| 477 | | | { |
| 478 | 0 | | result = mCoveredLinesOfCode / allLinesOfCode; |
| 479 | | | } |
| 480 | 0 | | else if (getNotCoveredLinesOfCode() > 0) |
| 481 | | | { |
| 482 | 0 | | result = 0; |
| 483 | | | } |
| 484 | | | else |
| 485 | | | { |
| 486 | 0 | | result = 1; |
| 487 | | | } |
| 488 | 0 | | return result * MAX_PERCENTAGE_FLOAT; |
| 489 | | | } |
| 490 | | | |
| 491 | | | |
| 492 | | | |
| 493 | | | @return |
| 494 | | | |
| 495 | | | public String getCoverageAsString () |
| 496 | | | { |
| 497 | 0 | | return mCoveragePercantageFormatter.format(getCoverageAsFloat()) + "%"; |
| 498 | | | } |
| 499 | | | |
| 500 | | | @return |
| 501 | | | public int getCoverage () |
| 502 | | | { |
| 503 | 0 | | final int notCoveredLinesOfCode = getNotCoveredLinesOfCode(); |
| 504 | | | |
| 505 | | | int notCovered; |
| 506 | 0 | | if (mCoveredLinesOfCode != 0) |
| 507 | | | { |
| 508 | 0 | | notCovered = (notCoveredLinesOfCode * MAX_PERCENTAGE) |
| 509 | | | / (mCoveredLinesOfCode + notCoveredLinesOfCode); |
| 510 | 0 | | if ((notCovered == 0) && (notCoveredLinesOfCode > 0)) |
| 511 | | | { |
| 512 | 0 | | notCovered = 1; |
| 513 | | | } |
| 514 | | | } |
| 515 | 0 | | else if (notCoveredLinesOfCode > 0) |
| 516 | | | { |
| 517 | 0 | | notCovered = MAX_PERCENTAGE; |
| 518 | | | } |
| 519 | | | else |
| 520 | | | { |
| 521 | 0 | | notCovered = 0; |
| 522 | | | } |
| 523 | 0 | | return MAX_PERCENTAGE - notCovered; |
| 524 | | | } |
| 525 | | | |
| 526 | | | |
| 527 | | | @return |
| 528 | | | |
| 529 | | | public int getNotCoveredLinesOfCode () |
| 530 | | | { |
| 531 | 0 | | return mViolations[Severity.COVERAGE.toInt()]; |
| 532 | | | } |
| 533 | | | |
| 534 | | | |
| 535 | | | {@link } |
| 536 | | | {@link }{@link } |
| 537 | | | |
| 538 | | | @return |
| 539 | | | |
| 540 | | | public int getNumberOfFindings () |
| 541 | | | { |
| 542 | 100 | | int sum = 0; |
| 543 | 100 | | for (int i = Severity.INFO.toInt(); i <= Severity.ERROR.toInt(); i++) |
| 544 | | | { |
| 545 | 100 | | if (i != Severity.COVERAGE.toInt()) |
| 546 | | | { |
| 547 | 100 | | sum += mViolations[i]; |
| 548 | | | } |
| 549 | | | } |
| 550 | 100 | | return sum; |
| 551 | | | } |
| 552 | | | |
| 553 | | | {@inheritDoc} |
| 554 | | | public int compareTo (FileSummary o) |
| 555 | | | { |
| 556 | 0 | (3) | int result = 0; |
| 557 | 0 | | if (mPackage != null) |
| 558 | | | { |
| 559 | 0 | | result = mPackage.compareTo((o).mPackage); |
| 560 | | | } |
| 561 | 0 | | if (result == 0) |
| 562 | | | { |
| 563 | 0 | | if (getClassName() != null) |
| 564 | | | { |
| 565 | 0 | | result = getClassName().compareTo(o.getClassName()); |
| 566 | | | } |
| 567 | | | } |
| 568 | 0 | | return result; |
| 569 | | | } |
| 570 | | | |
| 571 | | | |
| 572 | | | private void calcPercent () |
| 573 | | | { |
| 574 | 0 | | if (!mPercentUpToDate) |
| 575 | | | { |
| 576 | 0 | | doCalcPercent(); |
| 577 | | | } |
| 578 | 0 | | } |
| 579 | | | |
| 580 | | | private void doCalcPercent () |
| 581 | | | { |
| 582 | 0 | | int remainingPercentage = MAX_PERCENTAGE; |
| 583 | | | |
| 584 | 0 | | if (mLinesOfCode != 0) |
| 585 | | | { |
| 586 | 0 | | for (int i = Severity.ERROR.toInt(); i > Severity.INFO.toInt(); |
| 587 | 0 | | i--) |
| 588 | | | { |
| 589 | | | int percent; |
| 590 | | | |
| 591 | 0 | | if (i == Severity.COVERAGE.toInt()) |
| 592 | | | { |
| 593 | 0 | | percent = calcPercentCoverage(); |
| 594 | | | } |
| 595 | | | else |
| 596 | | | { |
| 597 | 0 | | percent = calcPercentage( |
| 598 | | | mViolations[i] * Severity.fromInt(i).getPenalty(), |
| 599 | | | mLinesOfCode * Severity.PENALTY_SCALE); |
| 600 | | | } |
| 601 | | | |
| 602 | 0 | | if (mViolations[i] > 0 && percent == 0) |
| 603 | | | { |
| 604 | 0 | | percent = 1; |
| 605 | | | } |
| 606 | 0 | | if (percent > remainingPercentage) |
| 607 | | | { |
| 608 | 0 | | percent = remainingPercentage; |
| 609 | | | } |
| 610 | 0 | | mPercent[i] = percent; |
| 611 | 0 | | remainingPercentage -= percent; |
| 612 | | | } |
| 613 | | | } |
| 614 | | | else |
| 615 | | | { |
| 616 | 0 | | for (int i = Severity.ERROR.toInt(); i > Severity.INFO.toInt(); i--) |
| 617 | | | { |
| 618 | 0 | | mPercent[i] = 0; |
| 619 | | | } |
| 620 | | | } |
| 621 | 0 | | mPercent[Severity.OK.toInt()] = remainingPercentage; |
| 622 | 0 | | mPercentUpToDate = true; |
| 623 | 0 | | } |
| 624 | | | |
| 625 | | | |
| 626 | | | |
| 627 | | | |
| 628 | | | private int calcPercentCoverage () |
| 629 | | | { |
| 630 | | | final int coverageViolationPercentage; |
| 631 | 0 | | if (!mCoverageData) |
| 632 | | | { |
| 633 | 0 | | coverageViolationPercentage = 0; |
| 634 | | | } |
| 635 | | | else |
| 636 | | | { |
| 637 | 0 | | final int notCoveredLines |
| 638 | | | = getNotCoveredLinesOfCode(); |
| 639 | 0 | | coverageViolationPercentage = calcPercentage( |
| 640 | | | notCoveredLines * Severity.COVERAGE.getPenalty(), |
| 641 | | | Severity.PENALTY_SCALE |
| 642 | | | * (mCoveredLinesOfCode + notCoveredLines)); |
| 643 | | | } |
| 644 | 0 | | return coverageViolationPercentage; |
| 645 | | | } |
| 646 | | | |
| 647 | | | private static int calcPercentage (int part, int all) |
| 648 | | | { |
| 649 | | | final int result; |
| 650 | 0 | | if (all == 0) |
| 651 | | | { |
| 652 | 0 | | result = 0; |
| 653 | | | } |
| 654 | | | else |
| 655 | | | { |
| 656 | 0 | | result = part * MAX_PERCENTAGE / all; |
| 657 | | | } |
| 658 | 0 | | return result; |
| 659 | | | } |
| 660 | | | |
| 661 | | | |
| 662 | | | |
| 663 | | | |
| 664 | | | @author |
| 665 | | | |
| 666 | 0 | | static final class SortByPackage |
| 667 | | | implements Comparator<FileSummary>, Serializable |
| 668 | | | { |
| 669 | | | private static final long serialVersionUID = 2244367340241672131L; |
| 670 | | | |
| 671 | | | public int compare (FileSummary o1, FileSummary o2) |
| 672 | | | { |
| 673 | 0 | | return o1.compareTo(o2); |
| 674 | | | } |
| 675 | | | } |
| 676 | | | |
| 677 | | | |
| 678 | | | |
| 679 | | | @author |
| 680 | | | |
| 681 | 0 | | static final class SortByQuality |
| 682 | | | implements Comparator<FileSummary>, Serializable |
| 683 | | | { |
| 684 | | | private static final long serialVersionUID = 1718175789352629538L; |
| 685 | | | |
| 686 | | | public int compare (FileSummary o1, FileSummary o2) |
| 687 | | | { |
| 688 | | | int result; |
| 689 | 0 | | final float qualityA = o1.getQualityAsFloat(); |
| 690 | 0 | | final float qualityB = o2.getQualityAsFloat(); |
| 691 | 0 | | if (qualityA < qualityB) |
| 692 | | | { |
| 693 | 0 | | result = -1; |
| 694 | | | } |
| 695 | 0 | | else if (qualityA > qualityB) |
| 696 | | | { |
| 697 | 0 | | result = 1; |
| 698 | | | } |
| 699 | | | else |
| 700 | | | { |
| 701 | 0 | | result = o1.compareTo(o2); |
| 702 | | | } |
| 703 | 0 | | return result; |
| 704 | | | } |
| 705 | | | } |
| 706 | | | |
| 707 | | | |
| 708 | | | |
| 709 | | | @author |
| 710 | | | |
| 711 | 0 | | static final class SortByCoverage |
| 712 | | | implements Comparator<FileSummary>, Serializable |
| 713 | | | { |
| 714 | | | private static final long serialVersionUID = -4275903074787742250L; |
| 715 | | | |
| 716 | | | public int compare (FileSummary a, FileSummary b) |
| 717 | | | { |
| 718 | 0 | | final float coverA = a.getCoverageAsFloat(); |
| 719 | 0 | | final float coverB = b.getCoverageAsFloat(); |
| 720 | | | |
| 721 | | | final int result; |
| 722 | 0 | | if (coverA < coverB) |
| 723 | | | { |
| 724 | 0 | | result = -1; |
| 725 | | | } |
| 726 | 0 | | else if (coverA > coverB) |
| 727 | | | { |
| 728 | 0 | | result = 1; |
| 729 | | | } |
| 730 | 0 | (4) | else if (a.getNotCoveredLinesOfCode() > b.getNotCoveredLinesOfCode()) |
| 731 | | | { |
| 732 | 0 | | result = -1; |
| 733 | | | } |
| 734 | 0 | (5) | else if (a.getNotCoveredLinesOfCode() < b.getNotCoveredLinesOfCode()) |
| 735 | | | { |
| 736 | 0 | | result = 1; |
| 737 | | | } |
| 738 | | | else |
| 739 | | | { |
| 740 | 0 | | result = a.compareTo(b); |
| 741 | | | } |
| 742 | 0 | | return result; |
| 743 | | | } |
| 744 | | | } |
| 745 | | | } |