-
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.
the code for the portfoli class
- Loading branch information
EspenTinius
committed
Feb 13, 2026
1 parent
c41e279
commit e694c85
Showing
1 changed file
with
41 additions
and
0 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| public class Portfolio { | ||
|
|
||
| private final List<Share> shares = new ArrayList<>(); | ||
|
|
||
| public Portfolio() { | ||
| // Intentionally empty | ||
| } | ||
|
|
||
| public boolean addShare(Share share) { | ||
| Objects.requireNonNull(share, "share cannot be null"); | ||
| return shares.add(share); | ||
| } | ||
|
|
||
| public boolean removeShare(Share share) { | ||
| Objects.requireNonNull(share, "share cannot be null"); | ||
| return shares.remove(share); | ||
| } | ||
|
|
||
|
|
||
| public List<Share> getShares() { | ||
| return List.copyOf(shares); | ||
| } | ||
|
|
||
| public List<Share> getShares(String symbol) { | ||
| Objects.requireNonNull(symbol, "symbol cannot be null"); | ||
| return shares.stream() | ||
| .filter(s -> symbol.equalsIgnoreCase(s.getStock().getSymbol())) | ||
| .toList(); | ||
| } | ||
|
|
||
| public boolean contains(Share share) { | ||
| Objects.requireNonNull(share, "share cannot be null"); | ||
| return shares.contains(share); | ||
| } | ||
| } |