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.
TimeSeries with same dataname?
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: TimeSeries with same dataname?
Have you tried that? Under what conditions give the two (different!) TimeSeries the same index?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.
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).
Re: TimeSeries with same dataname?
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.
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.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: TimeSeries with same dataname?
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.