使用两个比较器的最佳方法是什么?

时间:2022-04-22 15:54:54

I currently have the following structure used to get OHLC data over an interval

我目前有以下结构用于在一定时间间隔内获取OHLC数据

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?

在marketDataItem或marketDataGroup中使用比较器更好/更好/更快/更少存储?

2 个解决方案

#1


1  

Nope. I think your implementation is optimal. We've faced similar requirements and done it this way.

不。我认为您的实施是最佳的。我们遇到了类似的要求并以这种方式完成。

#2


2  

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.

它没有区别 - 它们是静态嵌套类,所以它就像它们是完全独立的类型一样。各种类别的可访问性存在差异,但效率应该相同。

#1


1  

Nope. I think your implementation is optimal. We've faced similar requirements and done it this way.

不。我认为您的实施是最佳的。我们遇到了类似的要求并以这种方式完成。

#2


2  

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.

它没有区别 - 它们是静态嵌套类,所以它就像它们是完全独立的类型一样。各种类别的可访问性存在差异,但效率应该相同。