I currently have the following structure used to get OHLC data over an interval
class MarketDataItem{
....
static class DateComparator implements Comparator<MarketDataItem>{
}
static class PriceComparator implements Comparator<MarketDataItem> {
}
}
class MarketDataGroup{
private TreeSet<MarketDataItem> sortedByDate = Sets.newTreeSet(new MarketDataItem.DateComparator());
private TreeSet<MarketDataItem> sortedByPrice = Sets.newTreeSet(new MarketDataItem.PriceComparator());
}
Is it better/nicer/faster/lessmemory to have the comparators in the marketDataItem or in the marketDataGroup?
Nope. I think your implementation is optimal. We’ve faced similar requirements and done it this way.