TimeSeries with same dataname?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
luizihjei
Posts: 9
Joined: Thu Sep 03, 2009 9:41 am
antibot: No, of course not.

TimeSeries with same dataname?

Post by luizihjei » Sat Oct 10, 2009 4:19 am

Is there possible that there are same dataname in TimeSeries?

Such as:
TimeSeries tempSer1 = new TimeSeries("dataName", Millisecond.class);
TimeSeries tempSer2 = new TimeSeries("dataName", Millisecond.class);

How can I differ tempSer1 from tempSer2?

TimeSeriesCollection xyData = new TimeSeriesCollection();
int index1 = xyData.indexOf(tempSer1);
int index2 = xyData.indexOf(tempSer2);

sametimes, the index1 will be equal with index2.

Any help will appreciate.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: TimeSeries with same dataname?

Post by paradoxoff » Mon Oct 12, 2009 10:00 pm

luizihjei wrote: How can I differ tempSer1 from tempSer2?
TimeSeriesCollection xyData = new TimeSeriesCollection();
int index1 = xyData.indexOf(tempSer1);
int index2 = xyData.indexOf(tempSer2);

sametimes, the index1 will be equal with index2.
Have you tried that? Under what conditions give the two (different!) TimeSeries the same index?
TimeSeriesCollection.indexOf(TimeSeries series) should only return the same index of the two TimeSeries are equal, i. e. tempSer1.equals(tempSer2) return true.
But that requires that all data items are the same, and if that is the case, well, they are indeed identical, and there is no need to distinguish between them (IMHO).

luizihjei
Posts: 9
Joined: Thu Sep 03, 2009 9:41 am
antibot: No, of course not.

Re: TimeSeries with same dataname?

Post by luizihjei » Tue Oct 13, 2009 4:10 am

According the TimeSeries method of equal, the code is follows:

public boolean equals(Object object) {
if (object == this) {
return true;
}
if (!(object instanceof TimeSeries)) {
return false;
}
TimeSeries that = (TimeSeries) object;
if (!ObjectUtilities.equal(getDomainDescription(),
that.getDomainDescription())) {
return false;
}
if (!ObjectUtilities.equal(getRangeDescription(),
that.getRangeDescription())) {
return false;
}
if (!ObjectUtilities.equal(this.timePeriodClass,
that.timePeriodClass)) {
return false;
}
if (getMaximumItemAge() != that.getMaximumItemAge()) {
return false;
}
if (getMaximumItemCount() != that.getMaximumItemCount()) {
return false;
}
int count = getItemCount();
if (count != that.getItemCount()) {
return false;
}
for (int i = 0; i < count; i++) {
if (!getDataItem(i).equals(that.getDataItem(i))) {
return false;
}
}
return super.equals(object);
}

If thier itemCount are both 0, and other properties are all same.
i.e. dataname...

at that time, the two timeseries will be equal. there will be same index of them.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: TimeSeries with same dataname?

Post by david.gilbert » Tue Oct 13, 2009 6:36 am

You shouldn't put two times series with the same key (name) into one TimeSeriesCollection. I should add some code to detect this and throw an exception.

Locked