Skip to content

Commit

Permalink
feat(Exchange): Set gainers/losers to percent change instead of chang…
Browse files Browse the repository at this point in the history
…e value.
  • Loading branch information
PawelSapula committed May 25, 2026
1 parent 851c6c9 commit 4fa891f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/edu/ntnu/idi/idatt/model/Exchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ public List<Stock> findStocks(String searchTerm) {
*
* <p>
* Returns the stocks that have done it the best
* in the latest week.
* (percent change) in the latest week.
* </p>
*
* @param limit - Amount of stocks to be returned.
* @return A list of stocks sorted in declining order.
*/
public List<Stock> getGainers(int limit) {
return stockMap.values().stream()
.filter(stock -> stock.getLatestPriceChange().compareTo(BigDecimal.ZERO) > 0)
.sorted(Comparator.comparing(Stock::getLatestPriceChange).reversed())
.filter(stock -> stock.getLatestPriceChangePercent().compareTo(BigDecimal.ZERO) > 0)
.sorted(Comparator.comparing(Stock::getLatestPriceChangePercent).reversed())
.limit(limit)
.toList();
}
Expand All @@ -133,16 +133,16 @@ public List<Stock> getGainers(int limit) {
*
* <p>
* Returns the stocks that have done it the worst
* in value in the latest week.
* in percent change in the latest week.
* </p>
*
* @param limit - Amount of stocks to be returned.
* @return A list of stocks sorted in inclining order.
* @return A list of stocks sorted in ascending order.
*/
public List<Stock> getLosers(int limit) {
return stockMap.values().stream()
.filter(stock -> stock.getLatestPriceChange().compareTo(BigDecimal.ZERO) < 0)
.sorted(Comparator.comparing(Stock::getLatestPriceChange))
.filter(stock -> stock.getLatestPriceChangePercent().compareTo(BigDecimal.ZERO) < 0)
.sorted(Comparator.comparing(Stock::getLatestPriceChangePercent))
.limit(limit)
.toList();
}
Expand Down

0 comments on commit 4fa891f

Please sign in to comment.