我的教授给我分配了整理书籍和视频的作业。这是她给我的测试代码。但是我对于用于比较器链的库确实感到困惑。我就是无法正常工作。我试图导入java.util.Comparator,但是它不起作用。
public static void main(String[] args) {
ComparatorChain chain = new ComparatorChain();
Database library = new Database();
Calendar cal = Calendar.getInstance();
cal.set(1890, Calendar.AUGUST, 10);
Date date = (Date) cal.getTime();
library.addItem(new Textbook("TB15", "TextX", date, "John Doe"));
cal.set(1954, Calendar.JANUARY, 18);
date = (Date) cal.getTime() ;
library.addItem(new Textbook("TB01", "TextY", date, "John Doe"));
chain.addComparator(new SortByTitle());
chain.addComparator(new SortByAddedOn());
chain.addComparator(new SortByDirector());
Collections.sort(library.item, chain);
library.list();}`