Skip to content

Commit

Permalink
Added Checkstyle to Portfolio
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed May 24, 2026
1 parent b08e846 commit 2774464
Showing 1 changed file with 67 additions and 34 deletions.
101 changes: 67 additions & 34 deletions src/main/java/Model/Portfolio.java
Original file line number Diff line number Diff line change
@@ -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<Share> shares;
private final List<Share> 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<Share> getShares() {
return new ArrayList<>(shares);
}
public List<Share> getShares() {
return new ArrayList<>(shares);
}

public List<Share> 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<Share> 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);
}

}

0 comments on commit 2774464

Please sign in to comment.