Skip to content

Commit

Permalink
Update Portfolio class with exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed May 24, 2026
1 parent bd8d34a commit 3bb7de3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/Model/Portfolio.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ public Portfolio() {
}

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);
}

Expand All @@ -24,6 +30,9 @@ public List<Share> getShares() {
}

public List<Share> getShares(String symbol) {
if (symbol == null || symbol.isBlank()) {
throw new IllegalArgumentException("Symbol cannot be null or blank");
}
List<Share> result = new ArrayList<>();
for (Share share : shares) {
if (share.getStock().getSymbol().equals(symbol)) {
Expand All @@ -34,6 +43,9 @@ public List<Share> getShares(String symbol) {
}

public boolean contains(Share share) {
if (share == null) {
throw new IllegalArgumentException("Share cannot be null");
}
return shares.contains(share);
}

Expand Down

0 comments on commit 3bb7de3

Please sign in to comment.