01: package org.libresource.kernel.comparator;
02:
03: import java.util.Comparator;
04:
05: import org.libresource.LibresourceResourceValue;
06: import org.libresource.kernel.comparator.util.TreeNode;
07:
08: //Ajout d'une suite de comparateurs
09: public class CreationDateComparator implements Comparator {
10: private Comparator comparator;
11:
12: public CreationDateComparator() {
13: this (null);
14: }
15:
16: public CreationDateComparator(Comparator comparator) {
17: this .comparator = comparator;
18: }
19:
20: public int compare(Object lsvalue1, Object lsvalue2) {
21: LibresourceResourceValue lsv1 = null;
22: LibresourceResourceValue lsv2 = null;
23: if (lsvalue1 instanceof TreeNode) {
24: lsv1 = ((TreeNode) lsvalue1).getValue();
25: lsv2 = ((TreeNode) lsvalue2).getValue();
26: } else {
27: lsv1 = (LibresourceResourceValue) lsvalue1;
28: lsv2 = (LibresourceResourceValue) lsvalue2;
29: }
30: int result = lsv1.getCreationDate().compareTo(
31: lsv2.getCreationDate());
32: if (comparator != null && result == 0)
33: return comparator.compare(lsvalue1, lsvalue2);
34: return result;
35: }
36:
37: @Override
38: public String toString() {
39: return "CreationDateComparator(" + comparator + ")";
40: }
41: }
|