I have an array of items that I need to merge together so that there
is only
one entry in the array per username (1st field) and the rest of the
numbers
are merged into the single entry.
I end up with this: but I want to have this:
============================= ==============================
usera 5 0 0 0 0 0 0 0 0 0 0 0 usera 5 2 0 0 0 0 0 0 0 0 0 0
userb 5 0 0 0 0 0 0 0 0 0 0 0 userb 5 1 3 0 0 0 0 0 0 0 0 0
userc 5 0 0 0 0 0 0 0 0 0 0 0 userc 5 4 3 0 0 0 0 0 0 0 0 0
usera 0 2 0 0 0 0 0 0 0 0 0 0
userb 0 1 0 0 0 0 0 0 0 0 0 0
userc 0 4 0 0 0 0 0 0 0 0 0 0
usera 0 0 0 0 0 0 0 0 0 0 0 0
userb 0 0 3 0 0 0 0 0 0 0 0 0
userc 0 0 3 0 0 0 0 0 0 0 0 0
Here are the details. Maybe I should be building the array
differently.
I have an array of "JobHist" objects. The JobHist class has a name
followed by 12 integers.
public JobHistory(String name,
int jan, int feb, int mar, int apr, int may,
int jun,
int jul, int aug, int sep, int oct, int nov,
int dec) {
.....
}
In my code I am doing something like:
for (int n = 1; n < 12; n++) {
// the month number is i
// gets some sql data from a db that returns some names and a
number
while (rs.next()) }
String username = rs.getString("username");
int jobcount = rs.getInt("jobcount");
switch (n) {
case 1: values.add(new
JobHistory(username,jobcount,0,0,0,0,0,0,0,0,0,0,0)); break;
case 2: values.add(new JobHistory(username,
0,jobcount,0,0,0,0,0,0,0,0,0,0)); break;
case 3: values.add(new JobHistory(username,
0,0,jobcount,0,0,0,0,0,0,0,0,0)); break;
case 4: values.add(new JobHistory(username,
0,0,0,jobcount,0,0,0,0,0,0,0,0)); break;
case 5: values.add(new JobHistory(username,
0,0,0,0,jobcount,0,0,0,0,0,0,0)); break;
case 6: values.add(new JobHistory(username,
0,0,0,0,0,jobcount,0,0,0,0,0,0)); break;
case 7: values.add(new JobHistory(username,
0,0,0,0,0,0,jobcount,0,0,0,0,0)); break;
case 8: values.add(new JobHistory(username,
0,0,0,0,0,0,0,jobcount,0,0,0,0)); break;
case 9: values.add(new JobHistory(username,
0,0,0,0,0,0,0,0,jobcount,0,0,0)); break;
case 10: values.add(new JobHistory(username,
0,0,0,0,0,0,0,0,0,jobcount,0,0)); break;
case 11: values.add(new JobHistory(username,
0,0,0,0,0,0,0,0,0,0,jobcount,0)); break;
case 12: values.add(new JobHistory(username,
0,0,0,0,0,0,0,0,0,0,0,jobcount)); break;