Suppose there is a class stock
class Stock
{
String id;
String name;
}
I want to create two comparators that compare by id and name, respectively.
Are there naming conventions or best practices for comparators in Java?
Are following names okay?
StockByIdComparatorandStockByNameComparatorSortStockByIdandSortStockByName
I know that redundant names are avoided in certain areas. One would choose
List<Stock> stocks over List<Stock> stockList. Also types should not be encoded in variable names (maybe since the rise of IDEs?). But there is also the important dimension of clearness.
So what is a good aproach for naming comparators?