-
Notifications
You must be signed in to change notification settings - Fork 0
/
SortByPrice.java
35 lines (31 loc) · 944 Bytes
/
SortByPrice.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
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 to sort by price.
*
* @author israfeel_ashraf - K21008936
* @version 22/03/22
*/
public class SortByPrice extends SortingTypes {
/**
* A method to sort by price
* @param listToBeSorted The list which will be ordered.
* @return the sorted list.
*/
@Override
public ArrayList<AirbnbListing> sort(ArrayList<AirbnbListing> listToBeSorted) {
//Stream to sort by price.
ArrayList<AirbnbListing> sortedList = (ArrayList<AirbnbListing>) listToBeSorted
.stream()
.sorted(Comparator.comparing(AirbnbListing::getPrice))
.collect(Collectors.toList());
return sortedList;
}
}