1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.whatsnew.utils.sort;
35
36 import fr.paris.lutece.plugins.whatsnew.business.ElementOrderEnum;
37 import fr.paris.lutece.plugins.whatsnew.business.IWhatsNew;
38
39 import java.io.Serializable;
40
41 import java.util.Comparator;
42
43
44
45
46
47
48
49 public class WhatsNewComparator implements Comparator<IWhatsNew>, Serializable
50 {
51 private static final long serialVersionUID = 1035663950193810359L;
52 private int _nOrder;
53 private boolean _bIsAscSort;
54
55
56
57
58
59
60 public WhatsNewComparator( int nOrder, boolean bIsAscSort )
61 {
62 _nOrder = nOrder;
63 _bIsAscSort = bIsAscSort;
64 }
65
66
67
68
69
70
71
72
73
74
75
76
77 public int compare( IWhatsNew w1, IWhatsNew w2 )
78 {
79 int nStatus = 0;
80
81 if ( ( w1 != null ) && ( w2 != null ) )
82 {
83 if ( _nOrder == ElementOrderEnum.DATE.getId( ) )
84 {
85 if ( ( w1.getDateUpdate( ) != null ) && ( w2.getDateUpdate( ) != null ) )
86 {
87 nStatus = w1.getDateUpdate( ).compareTo( w2.getDateUpdate( ) );
88 }
89 else if ( ( w1.getDateUpdate( ) == null ) && ( w2.getDateUpdate( ) != null ) )
90 {
91 nStatus = -1;
92 }
93 else if ( ( w1.getDateUpdate( ) != null ) && ( w2.getDateUpdate( ) == null ) )
94 {
95 nStatus = 1;
96 }
97 }
98 else if ( _nOrder == ElementOrderEnum.ALPHA.getId( ) )
99 {
100 if ( ( w1.getTitle( ) != null ) && ( w2.getTitle( ) != null ) )
101 {
102 nStatus = w1.getTitle( ).toUpperCase( ).compareTo( w2.getTitle( ).toUpperCase( ) );
103 }
104 else if ( ( w1.getTitle( ) == null ) && ( w2.getTitle( ) != null ) )
105 {
106 nStatus = -1;
107 }
108 else if ( ( w1.getTitle( ) != null ) && ( w2.getTitle( ) == null ) )
109 {
110 nStatus = 1;
111 }
112 }
113
114 if ( ( nStatus != 0 ) && !_bIsAscSort )
115 {
116 nStatus = nStatus * ( -1 );
117 }
118 }
119
120 return nStatus;
121 }
122 }