Created
February 28, 2023 12:50
-
-
Save androidneha/e1483ff01c7da80a17e7912c32a4f954 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> fetchItemToDisplay(List<List<String>> items, int sortParameter, int sortOrder, int itemsPerPage, int pageNumber) { | |
List<String> output = new ArrayList<>(); | |
Collections.sort(items, (a, b) -> { | |
if (sortOrder == 0) { | |
return sortParameter != 0 ? | |
Integer.parseInt(a.get(sortParameter)) - Integer.parseInt(b.get(sortParameter)) : | |
a.get(sortParameter).compareTo(b.get(sortParameter)); | |
} else { | |
return sortParameter != 0 ? | |
Integer.parseInt(b.get(sortParameter)) - Integer.parseInt(a.get(sortParameter)) : | |
b.get(sortParameter).compareTo(a.get(sortParameter)); | |
} | |
}); | |
int sum = itemsPerPage * pageNumber; | |
if (sum >= items.size()) { | |
return output; | |
} | |
for (int i = sum; i <items.size() && i < sum + itemsPerPage; i++) { | |
List<String> temp = items.get(i); | |
output.add(temp.get(0)); | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment