org.opencms.file.collectors
Class CmsDateResourceComparator

java.lang.Object
  extended by org.opencms.file.collectors.CmsDateResourceComparator
All Implemented Interfaces:
java.util.Comparator<CmsResource>

public class CmsDateResourceComparator
extends java.lang.Object
implements java.util.Comparator<CmsResource>

Comparator for sorting resource objects based on dates.

The comparator can be configured to use any date based on resource attributes or properties. The user must in the constructor CmsDateResourceComparator(CmsObject, List, boolean) provide a list of one or more date identifiers that should be checked, in the order they should be checked. This list of dates identifiers must be Strings which tell the comparator which dates to use. The first valid date identifier that is found for a resource is used as date for comparing this resource to other resources.

The following date identifiers can be used to access the corresponding value of a CmsResource:

Serves as Comparator for resources and as comparator key for the resource at the same time. Uses lazy initializing of comparator keys for a resource.

Since:
6.0.0

Field Summary
static java.util.List<java.lang.String> DATE_ATTRIBUTES_LIST
          Possible keywords to read dates from the resource attributes in a List.
 
Constructor Summary
CmsDateResourceComparator(CmsObject cms, java.util.List<java.lang.String> dateIdentifiers, boolean asc)
          Creates a new instance of this comparator key.
 
Method Summary
static long calculateDate(CmsObject cms, CmsResource resource, java.util.List<java.lang.String> dateIdentifiers, long defaultValue)
          Calculates the date to use for comparison of this resource based on the given date identifiers.
 int compare(CmsResource res0, CmsResource res1)
           
 long getDate()
          Returns the date of this resource comparator key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

DATE_ATTRIBUTES_LIST

public static final java.util.List<java.lang.String> DATE_ATTRIBUTES_LIST
Possible keywords to read dates from the resource attributes in a List.

Constructor Detail

CmsDateResourceComparator

public CmsDateResourceComparator(CmsObject cms,
                                 java.util.List<java.lang.String> dateIdentifiers,
                                 boolean asc)
Creates a new instance of this comparator key.

Parameters:
cms - the current OpenCms user context
dateIdentifiers - the names of the dates to check
asc - if true, the date sort order is ascending, otherwise descending
Method Detail

calculateDate

public static long calculateDate(CmsObject cms,
                                 CmsResource resource,
                                 java.util.List<java.lang.String> dateIdentifiers,
                                 long defaultValue)
Calculates the date to use for comparison of this resource based on the given date identifiers.

Parameters:
cms - the current OpenCms user context
resource - the resource to create the key for
dateIdentifiers - the date identifiers to use for selecting the date
defaultValue - the default value to use in case no value can be calculated
Returns:
the calculated date
See Also:
for a description about how the date identifieres are used

compare

public int compare(CmsResource res0,
                   CmsResource res1)
Specified by:
compare in interface java.util.Comparator<CmsResource>
See Also:
Comparator.compare(java.lang.Object, java.lang.Object)

getDate

public long getDate()
Returns the date of this resource comparator key.

Returns:
the date of this resource comparator key