Reputation: 948
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?
Upvotes: 4
Views: 181
Reputation: 19225
Nope. I think your implementation is optimal. We've faced similar requirements and done it this way.
Upvotes: 1
Reputation: 1500815
It makes no difference - they're static nested classes, so it's as if they were completely independent types. There are differences to accessibility from various classes, but the efficiency should be the same.
Upvotes: 2