5
5
import hudson .search .SearchIndex ;
6
6
import hudson .search .SearchItem ;
7
7
8
+ import java .io .Serializable ;
8
9
import java .util .Collection ;
10
+ import java .util .Comparator ;
9
11
import java .util .Optional ;
10
12
11
- public class NestedViewsSearchResult implements SearchItem , Comparable , ExtendedSearch {
13
+ public class NestedViewsSearchResult implements SearchItem , ExtendedSearch {
12
14
private final String searchName ;
13
15
private final String searchUrl ;
14
16
private final ProjectWrapper project ;
@@ -54,12 +56,6 @@ public String toPlainOldHref() {
54
56
return "<a href=\" " + searchUrl + "\" >" + searchName + "</a>" ;
55
57
}
56
58
57
- @ Override
58
- @ SuppressFBWarnings (value = {"EQ_COMPARETO_USE_OBJECT_EQUALS" }, justification = "intentional. We check the types when filling the allCached, and the classes have not much in common" )
59
- public int compareTo (Object o ) {
60
- return this .toString ().length () - o .toString ().length ();
61
- }
62
-
63
59
@ Override
64
60
public ProjectWrapper getProject () {
65
61
return project ;
@@ -68,4 +64,38 @@ public ProjectWrapper getProject() {
68
64
public void createDetails () {
69
65
project .createDetails ();
70
66
}
67
+
68
+ public static class LenghtComparator implements Comparator <NestedViewsSearchResult >, Serializable {
69
+
70
+ @ Override
71
+ public int compare (NestedViewsSearchResult a , NestedViewsSearchResult b ) {
72
+ return a .toString ().length () - b .toString ().length ();
73
+ }
74
+ }
75
+
76
+ public static class NameComparator implements Comparator <NestedViewsSearchResult >, Serializable {
77
+
78
+ @ Override
79
+ public int compare (NestedViewsSearchResult a , NestedViewsSearchResult b ) {
80
+ return a .toString ().compareTo (b .toString ());
81
+ }
82
+ }
83
+
84
+ public static class DateComparator implements Comparator <NestedViewsSearchResult >, Serializable {
85
+
86
+ @ Override
87
+ public int compare (NestedViewsSearchResult a , NestedViewsSearchResult b ) {
88
+ if (a .getDate () == b .getDate ()) {
89
+ return 0 ;
90
+ } else if (a .getDate () > b .getDate ()) {
91
+ return -1 ;
92
+ } else {
93
+ return 1 ;
94
+ }
95
+ }
96
+ }
97
+
98
+ private long getDate () {
99
+ return project .getDateTime ();
100
+ }
71
101
}
0 commit comments