public class CmsDateResourceComparator extends java.lang.Object implements java.util.Comparator<CmsResource>
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
:
"dateCreated"
, which means CmsResource#getDateCreated()
.
"dateLastModified"
, which means CmsResource#getDateLastModified()
.
"dateContent"
, which means CmsResource#getDateContent()
.
"dateReleased"
, which means CmsResource#getDateReleased()
.
"dateExpired"
, which means CmsResource#getDateExpired()
.
CmsResource#getDateCreated()
is used as default.
Comparator
for resources and as comparator key for the resource
at the same time. Uses lazy initializing of comparator keys for a resource.限定符和类型 | 字段和说明 |
---|---|
static java.util.List<java.lang.String> |
DATE_ATTRIBUTES_LIST
Possible keywords to read dates from the resource attributes in a List.
|
构造器和说明 |
---|
CmsDateResourceComparator(CmsObject cms,
java.util.List<java.lang.String> dateIdentifiers,
boolean asc)
Creates a new instance of this comparator key.
|
限定符和类型 | 方法和说明 |
---|---|
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.
|
public static final java.util.List<java.lang.String> DATE_ATTRIBUTES_LIST
public CmsDateResourceComparator(CmsObject cms, java.util.List<java.lang.String> dateIdentifiers, boolean asc)
cms
- the current OpenCms user contextdateIdentifiers
- the names of the dates to checkasc
- if true, the date sort order is ascending, otherwise descendingpublic static long calculateDate(CmsObject cms, CmsResource resource, java.util.List<java.lang.String> dateIdentifiers, long defaultValue)
cms
- the current OpenCms user contextresource
- the resource to create the key fordateIdentifiers
- the date identifiers to use for selecting the datedefaultValue
- the default value to use in case no value can be calculatedfor a description about how the date identifieres are used
public int compare(CmsResource res0, CmsResource res1)
compare
在接口中 java.util.Comparator<CmsResource>
Comparator.compare(java.lang.Object, java.lang.Object)
public long getDate()