mnit-rtmc/iris

PeriodicSample comparisons

tanmatra opened this issue · 1 comments

If stamp marks end of period, should it be minus operator here, not plus?
But I may be wrong.

public int compareTo(PeriodicSample other) {
long ms = stamp + periodMillis();
long oms = other.stamp + other.periodMillis();
return (int) (ms - oms);
}

And by the way, you can use Long.compare() method.

The purpose of this compareTo is for ordering in PeriodicSampleCache:

/** Collection of periodic samples. Every sample is guaranteed to
* have the same sampling period. */
private final ConcurrentSkipListSet<PeriodicSample> samples =
new ConcurrentSkipListSet<PeriodicSample>();

Here, periodMillis is guaranteed to be the same between all samples. In short, I don't think adding or subtracting makes any difference. If I was writing this code now, I would use a dedicated Comparator instead of natural ordering.