-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sorting_output.java
41 lines (31 loc) · 993 Bytes
/
Sorting_output.java
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
35
36
37
38
39
40
41
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class Sorting_output {
public static void sort_by_date( ArrayList<Publications>Search_result)
{
Collections.sort(Search_result, new Comparator<Publications>(){
@Override
public int compare(Publications o1, Publications o2) {
int year1=Integer.parseInt(o1.ret_year());
int year2=Integer.parseInt(o2.ret_year());
return year2-year1;
}
});
}
public static void sort_by_relevance( ArrayList<Publications>Search_result)
{
Collections.sort(Search_result, new Comparator<Publications>(){
@Override
public int compare(Publications o1, Publications o2) {
if(o1.ret_matched_words()!=o2.ret_matched_words())
{
return o2.ret_matched_words()- o1.ret_matched_words();
}
else{
return o2.ret_matched_characters()- o1.ret_matched_characters();
}
}
});
}
}