Skip to content

Commit

Permalink
Adding null and blank checks to Stock
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed Mar 6, 2026
1 parent 4e90cef commit eea0cf2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/millions/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ public Stock(String symbol, String company, List<BigDecimal> prices) {
this.symbol = symbol;
this.company = company;
this.prices = new ArrayList<>(prices);

if (symbol == null || symbol.isBlank()) {
throw new IllegalArgumentException("Symbol cannot be null or blank");
}

if (company == null || company.isBlank()) {
throw new IllegalArgumentException("Company cannot be null or blank");
}
}

public Stock(String symbol, String company, BigDecimal initialPrice) {
this.symbol = symbol;
this.company = company;
this.prices = new ArrayList<>(List.of(initialPrice));
this(symbol, company, new ArrayList<>(List.of(initialPrice)));
}

public String getSymbol() {
Expand Down

0 comments on commit eea0cf2

Please sign in to comment.