-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSortByReviews.java
34 lines (31 loc) · 1.06 KB
/
SortByReviews.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
import java.util.ArrayList;
import java.util.Comparator;
import java.util.stream.Collectors;
/**
* Group SWIM:
* 1: Israfeel Ashraf K21008936
* 2: Shakeeb Jumaan K21087021
* 3: Michael Seiranian K20127931
* 4: William Atta K21097986
*
* A class which sorts by the number of reviews.
*
* @author israfeel_ashraf - K21008936
* @version 22/03/22
*/
public class SortByReviews extends SortingTypes {
/**
* A method to return a sorted list based on the number of reviews.
* @param listToBeSorted The list which will be ordered.
* @return The sorted list based on the number of reviews.
*/
@Override
public ArrayList<AirbnbListing> sort(ArrayList<AirbnbListing> listToBeSorted) {
//Create a stream which sorts the input list by the number of reviews.
ArrayList<AirbnbListing> sortedList = (ArrayList<AirbnbListing>) listToBeSorted
.stream()
.sorted(Comparator.comparing(AirbnbListing::getNumberOfReviews))
.collect(Collectors.toList());
return sortedList;
}
}