예제 #1
0
 public Stock addStock(Stock stock) {
   try {
     if (isValidStock(stock)) {
       return stocks.put(stock.getSymbol(), stock);
     }
   } catch (IllegalArgumentException e) {
     logger.warn("Ignore from adding: " + e.getMessage());
   }
   return null;
 }
예제 #2
0
  public boolean isValidStock(Stock stock) throws IllegalArgumentException {
    Preconditions.checkArgument(stock != null, "Invalid Stock, null reference.");
    Preconditions.checkArgument(stock.getParValue() > 0, "Invalid Trade, invalid ParValue field.");
    Preconditions.checkArgument(stock.getSymbol() != null, "Invalid Trade, missing Symbol field.");
    Preconditions.checkArgument(stock.getType() != null, "Invalid Trade, missing Type field.");

    switch (stock.getType()) {
      case PREFERRED:
        Preconditions.checkArgument(
            stock.getFixedDividend() != null, "Invalid Trade, missing FixDividend field.");
      case COMMON:
        Preconditions.checkArgument(
            stock.getLastDividend() > 0, "Invalid Trade, LastDividend should be grater than 0.");
    }

    return true;
  }