I have created an object to store a lot of data.
There are a total of 15 different types of this objects, for which I need to store data with the following time frame:
8.00 9.00 10.00 11.00 12.00 //ect ect
an example of this would be: in between 8.00 – 9.00 the data of this type would be 15 and between 9.00 and 10.00 it would be 5.
Now when I want to calculate the average of these numbers I want to get the average of each time period so for example I wish to find the average of the data between 8.00 and 9.00
My question is not how to get the data, but instead how I would store the data in my object.
So far my object looks like this:
public class CallQueue {
private String type;
private int data;
public CallQueue(String type, int data){
this.type = type;
this.data = data;
}
public void setType(String type){
this.type = type;
}
public String getType(){
return type;
}
public void setData(int data){
this.data = data;
}
public int getData(){
return data;
}
}
My question to you is: What is the best way to store an Integer with a timestamp ? I’d prefer to avoid Hashmap or Hashtable since they are harder to loop through! Can I avoid this in some way and if, so how?
Update – More information
My goal is to use the following method (this is in my statistic class)
public void calculateAverage(double time){
if (time != 20.00) {
double data =0;
int times = 0;
for (CallQueue cq : getData()) {
data += cq.getData();
times++;
}
averageData.add(data/times);
calculateAverage(time + 1);
}
}
as you can see I want to add the average of the data between 8 – 19.00 (with interval of 1 hour) all of these will be added to an arrayList (averageData)!
So the for each loop needs to get all the data from each object at the given time
My question to you is: What is the best way to store an Integer with a timestamp ?
I would say.
Create a class with two members
That is the way I could think of. If there exists anything better. Not sure.