-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
EspenTinius
committed
May 19, 2026
1 parent
30a4bac
commit 5d450cf
Showing
7 changed files
with
1,152 additions
and
265 deletions.
There are no files selected for viewing
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
94 changes: 94 additions & 0 deletions
94
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/stats/HoldingData.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.math.RoundingMode; | ||
|
|
||
| /** | ||
| * Immutable data carrier for a single holding shown in {@link StatsView}. | ||
| * | ||
| * <p>Each instance represents an aggregated position in a single stock: | ||
| * the total number of shares owned, the weighted average purchase price, | ||
| * and the current market price. Derived values (value, cost, P&L) are | ||
| * computed on demand.</p> | ||
| * */ | ||
| public final class HoldingData { | ||
|
|
||
| /** The stock ticker symbol. */ | ||
| private final String ticker; | ||
|
|
||
| /** Total number of shares owned of this ticker. */ | ||
| private final BigDecimal shares; | ||
|
|
||
| /** Weighted average purchase price per share. */ | ||
| private final BigDecimal avgPrice; | ||
|
|
||
| /** Current market price per share. */ | ||
| private final BigDecimal currentPrice; | ||
|
|
||
| /** | ||
| * Creates a new holding data row. | ||
| * | ||
| * @param ticker the stock ticker symbol. | ||
| * @param shares total number of shares owned. | ||
| * @param avgPrice weighted average purchase price per share. | ||
| * @param currentPrice current market price per share. | ||
| * | ||
| * @throws IllegalArgumentException if any argument is null. | ||
| * */ | ||
| public HoldingData(final String ticker, | ||
| final BigDecimal shares, | ||
| final BigDecimal avgPrice, | ||
| final BigDecimal currentPrice) throws IllegalArgumentException { | ||
| if (ticker == null || shares == null || avgPrice == null || currentPrice == null) { | ||
| throw new IllegalArgumentException("Invalid holding data!"); | ||
| } | ||
| this.ticker = ticker; | ||
| this.shares = shares; | ||
| this.avgPrice = avgPrice; | ||
| this.currentPrice = currentPrice; | ||
| } | ||
|
|
||
| /** @return the ticker symbol. */ | ||
| public String getTicker() { | ||
| return ticker; | ||
| } | ||
|
|
||
| /** @return total shares owned. */ | ||
| public BigDecimal getShares() { | ||
| return shares; | ||
| } | ||
|
|
||
| /** @return weighted average purchase price. */ | ||
| public BigDecimal getAvgPrice() { | ||
| return avgPrice; | ||
| } | ||
|
|
||
| /** @return current market price. */ | ||
| public BigDecimal getCurrentPrice() { | ||
| return currentPrice; | ||
| } | ||
|
|
||
| /** @return current market value of this position (shares * currentPrice). */ | ||
| public BigDecimal getValue() { | ||
| return shares.multiply(currentPrice); | ||
| } | ||
|
|
||
| /** @return total cost paid for this position (shares * avgPrice). */ | ||
| public BigDecimal getCost() { | ||
| return shares.multiply(avgPrice); | ||
| } | ||
|
|
||
| /** @return absolute profit and loss (value - cost). */ | ||
| public BigDecimal getPnl() { | ||
| return getValue().subtract(getCost()); | ||
| } | ||
|
|
||
| /** @return profit and loss as a percentage of cost. */ | ||
| public double getPnlPct() { | ||
| BigDecimal cost = getCost(); | ||
| if (cost.signum() == 0) { | ||
| return 0.0; | ||
| } | ||
| return getPnl().divide(cost, 6, RoundingMode.HALF_UP).doubleValue() * 100.0; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/stats/StatsActions.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats; | ||
|
|
||
| /** | ||
| * Enum representing all interactable actions in {@link StatsView}. | ||
| * | ||
| * <p>The stats widget is mostly an informational dashboard, so it currently | ||
| * has no top-level buttons of its own. {@code SELECT_HOLDING} is reserved | ||
| * for future use when individual holdings rows become clickable.</p> | ||
| * */ | ||
| public enum StatsActions { | ||
| /** Reserved for future holding-row click handling. */ | ||
| SELECT_HOLDING; | ||
| } |
Oops, something went wrong.