My Book app gathers a collection of Book
objects using lookups against different Merchant
objects:
List<Book> books = new ArrayList<Book>();
for (Merchant merchant : merchants)
{
books.addAll(getBooksForMerchant(merchantName);
}
It has to sort the List on the basis of a dropdown box:
<select class="sortByDropdown" name="sort">
<option value="lowPrice">Price: Low to High</option>
<option value="highPrice">Price: High to Low</option>
<option value="reviewRank">Avg. Customer Review</option>
</select>
Given that a Book
has a price
property and a reviewRank
property, how would I sort the ArrayList of Books in Java before displaying it to the user in the order they requested?