What is the best way of using two comparators?
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?
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.
Nope. I think your implementation is optimal. We've faced similar requirements and done it this way.
精彩评论