Skip to content

Commit

Permalink
code portfolio class
Browse files Browse the repository at this point in the history
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.
41 changes: 41 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Portfolio.java
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);
}
}

0 comments on commit e694c85

Please sign in to comment.