Exemple #1
0
 /**
  * Check if category exist in output data if no add new element if yes adds next amount to
  * category
  *
  * @param c Coast to add
  * @return BigDecimal
  */
 public BigDecimal calculateValue(Cost c) {
   BigDecimal value = null;
   String key = null;
   key = c.getCategory();
   if (outputData.containsKey(key)) {
     value = outputData.get(key).add(c.getValue());
   } else {
     value = c.getValue();
   }
   return value;
 }
Exemple #2
0
 /**
  * Group data by category and sum cost
  *
  * @return Grouped categories LinkedHashMap
  */
 public LinkedHashMap<String, BigDecimal> sumByCategory() {
   ListIterator<Cost> listIterator = inputData.listIterator();
   BigDecimal value = null;
   String key = null;
   while (listIterator.hasNext()) {
     Cost c = listIterator.next();
     key = c.getCategory();
     value = calculateValue(c);
     outputData.put(key, value);
   }
   return outputData;
 }