-
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
Showing
2 changed files
with
38 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,38 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Portfolio { | ||
|
|
||
| private final List<Share> shares; | ||
|
|
||
| public Portfolio() { | ||
| this.shares = new ArrayList<>(); | ||
| } | ||
|
|
||
| public boolean addShare(Share share) { | ||
| return shares.add(share); | ||
| } | ||
|
|
||
| public boolean removeShare(Share share) { | ||
| return shares.remove(share); | ||
| } | ||
|
|
||
| public List<Share> getShares() { | ||
| return new ArrayList<>(shares); | ||
| } | ||
|
|
||
| public List<Share> getShares(String symbol) { | ||
| List<Share> result = new ArrayList<>(); | ||
| for (Share share : shares) { | ||
| if (share.getStock().getSymbol().equals(symbol)) { | ||
| result.add(share); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public boolean contains(Share share) { | ||
| return shares.contains(share); | ||
| } | ||
|
|
||
| } |
Binary file not shown.