/** * Creates a new instance of this comparator key. * * <p> * * @param cms the current OpenCms user context * @param resource the resource to create the key for * @param dateIdentifiers the date identifiers to use for selecting the date * @return a new instance of this comparator key */ private static CmsDateResourceComparator create( CmsObject cms, CmsResource resource, List<String> dateIdentifiers) { CmsDateResourceComparator result = new CmsDateResourceComparator(); result.m_date = calculateDate(cms, resource, dateIdentifiers, resource.getDateCreated()); return result; }
/** @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ 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; } } return 0; }