Map<String, StockState> symbolToCurrentStockState,
Annotation annotation, Integer month, Integer year) {
if (!symbolToCurrentStockState.keySet().contains(
annotation.getConcept())) {
if (annotation instanceof StockExpensesAnnotation) {
StockExpensesAnnotation stockExpensesAnnotation = (StockExpensesAnnotation) annotation;
StockState stockState = new StockState(
stockExpensesAnnotation.getConcept(),
-stockExpensesAnnotation.getAmount(),
stockExpensesAnnotation.getNumberOfStocks(),
month, year);
symbolToCurrentStockState.put(annotation.getConcept(),
stockState);
} else {
throw new AssetManagerRuntimeException("the first transaction should be buy stocks");
// TODO: error, the first transaction should be buy stocks
}
} else {
StockState stockState = symbolToCurrentStockState.get(annotation
.getConcept());
if (annotation instanceof StockExpensesAnnotation) {
StockExpensesAnnotation stockExpensesAnnotation = (StockExpensesAnnotation) annotation;
stockState = new StockState(stockState.getSymbol(),
stockState.getBalance()
- stockExpensesAnnotation.getAmount(),
stockState.getNumberOfPurchasedStocks()
+ stockExpensesAnnotation.getNumberOfStocks(), month, year);
} else if (annotation instanceof StockIncomeAnnotation) {
StockIncomeAnnotation stockIncomeAnnotation = (StockIncomeAnnotation) annotation;
stockState = new StockState(stockState.getSymbol(),
stockState.getBalance()
+ stockIncomeAnnotation.getAmount(),