src/main/java/de/uapcore/lightpit/entities/VersionStatistics.java

changeset 150
822b7e3d064d
parent 80
27a25f32048e
equal deleted inserted replaced
149:30b840ed8c0e 150:822b7e3d064d
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2018 Mike Becker. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29 package de.uapcore.lightpit.entities;
30
31 public class VersionStatistics {
32
33 private final Version version;
34 private int[][] issueCount;
35
36 private int[] rowTotals = null;
37 private int[] columnTotals = null;
38 private int total = -1;
39
40 public VersionStatistics(Version version) {
41 this.version = version;
42 issueCount = new int[IssueCategory.values().length][IssueStatus.values().length];
43 }
44
45 public Version getVersion() {
46 return version;
47 }
48
49 public void setIssueCount(IssueCategory category, IssueStatus status, int count) {
50 issueCount[category.ordinal()][status.ordinal()] = count;
51 total = -1;
52 rowTotals = columnTotals = null;
53 }
54
55 public int[][] getIssueCount() {
56 return issueCount;
57 }
58
59 public int[] getRowTotals() {
60 if (rowTotals != null) return rowTotals;
61 final int cn = IssueCategory.values().length;
62 final int sn = IssueStatus.values().length;
63 final var totals = new int[cn];
64 for (int i = 0 ; i < cn ; i++) {
65 totals[i] = 0;
66 for (int j = 0 ; j < sn ; j++) {
67 totals[i] += issueCount[i][j];
68 }
69 }
70 return rowTotals = totals;
71 }
72
73 public int[] getColumnTotals() {
74 if (columnTotals != null) return columnTotals;
75 final int cn = IssueCategory.values().length;
76 final int sn = IssueStatus.values().length;
77 final var totals = new int[sn];
78 for (int i = 0 ; i < sn ; i++) {
79 totals[i] = 0;
80 for (int j = 0 ; j < cn ; j++) {
81 totals[i] += issueCount[j][i];
82 }
83 }
84 return columnTotals = totals;
85 }
86
87 public int getTotal() {
88 if (this.total >= 0) {
89 return this.total;
90 }
91 int total = 0;
92 final int cn = IssueCategory.values().length;
93 final int sn = IssueStatus.values().length;
94 for (int i = 0 ; i < sn ; i++) {
95 for (int j = 0 ; j < cn ; j++) {
96 total += issueCount[j][i];
97 }
98 }
99 return this.total = total;
100 }
101 }

mercurial