From 2774464c535986ca66ad726f95311b5d6d581b17 Mon Sep 17 00:00:00 2001 From: Elisabeth Berg Date: Sun, 24 May 2026 23:56:59 +0200 Subject: [PATCH] Added Checkstyle to Portfolio --- src/main/java/Model/Portfolio.java | 101 +++++++++++++++++++---------- 1 file changed, 67 insertions(+), 34 deletions(-) diff --git a/src/main/java/Model/Portfolio.java b/src/main/java/Model/Portfolio.java index ba050e7..902b8b9 100644 --- a/src/main/java/Model/Portfolio.java +++ b/src/main/java/Model/Portfolio.java @@ -1,54 +1,87 @@ package Model; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +/** + * Portfolio class of the player. + */ public class Portfolio { - private final List shares; + private final List shares; - public Portfolio() { - this.shares = new ArrayList<>(); - } + public Portfolio() { + this.shares = new ArrayList<>(); + } - public boolean addShare(Share share) { - if (share == null) { - throw new IllegalArgumentException("Share cannot be null"); - } - return shares.add(share); + /** + * Method to add share. + * + * @param share the share being added + * @return returns the added share + */ + public boolean addShare(Share share) { + if (share == null) { + throw new IllegalArgumentException("Share cannot be null"); } + return shares.add(share); + } - public boolean removeShare(Share share) { - if (share == null) { - throw new IllegalArgumentException("Share cannot be null"); - } - return shares.remove(share); + /** + * Method to remove share. + * + * @param share the share being removed + * @return returns the removed share + */ + public boolean removeShare(Share share) { + if (share == null) { + throw new IllegalArgumentException("Share cannot be null"); } + return shares.remove(share); + } - public List getShares() { - return new ArrayList<>(shares); - } + public List getShares() { + return new ArrayList<>(shares); + } - public List getShares(String symbol) { - if (symbol == null || symbol.isBlank()) { - throw new IllegalArgumentException("Symbol cannot be null or blank"); - } - return shares.stream() - .filter(share -> share.getStock().getSymbol().equals(symbol)) - .toList(); + /** + * Method to get all shares. + * + * @param symbol the symbol for each stock + * @return the shares of stocks + */ + public List getShares(String symbol) { + if (symbol == null || symbol.isBlank()) { + throw new IllegalArgumentException("Symbol cannot be null or blank"); } + return shares.stream() + .filter(share -> share.getStock().getSymbol().equals(symbol)) + .toList(); + } - public boolean contains(Share share) { - if (share == null) { - throw new IllegalArgumentException("Share cannot be null"); - } - return shares.contains(share); + /** + * Method to check if contains share. + * + * @param share the share + * @return the share if not null + */ + public boolean contains(Share share) { + if (share == null) { + throw new IllegalArgumentException("Share cannot be null"); } + return shares.contains(share); + } - public BigDecimal getNetWorth() { - return shares.stream() - .map(share -> new SaleCalculator(share).calculateTotal()) - .reduce(BigDecimal.ZERO, BigDecimal::add); - } + /** + * Method to get the new worth. + * + * @return returns the net worth + */ + public BigDecimal getNetWorth() { + return shares.stream() + .map(share -> new SaleCalculator(share).calculateTotal()) + .reduce(BigDecimal.ZERO, BigDecimal::add); + } }