我想知道是否还有其他一些技术可以在这里懒惰地使用?定义一个新的 Comparator 似乎很难。下面是 CmsDateResourceComparator 比较方法的代码:
public int compare(CmsResource res0, CmsResource res1) {
if (res0 == res1) {
return 0;
}
CmsDateResourceComparator key0 = m_keys.get(res0.getStructureId());
CmsDateResourceComparator key1 = m_keys.get(res1.getStructureId());
if (key0 == null) {
// initialize key if null
key0 = CmsDateResourceComparator.create(m_cms, res0, m_dateIdentifiers);
m_keys.put(res0.getStructureId(), key0);
}
if (key1 == null) {
// initialize key if null
key1 = CmsDateResourceComparator.create(m_cms, res1, m_dateIdentifiers);
m_keys.put(res1.getStructureId(), key1);
}
if (m_asc) {
// sort in ascending order
if (key0.m_date > key1.m_date) {
return 1;
}
if (key0.m_date < key1.m_date) {
return -1;
}
} else {
// sort in descending order
if (key0.m_date > key1.m_date) {
return -1;
}
if (key0.m_date < key1.m_date) {
return 1;
}
}