I have an object of the following format
Map<String, List<ObjectDTO>> mapOfIndicators = new HashMap<>();
ObjectDTO is
public class ObjectDTO {
private static final long serialVersionUID = 1L;
private String iName;
private String dName;
private String countryName;
private int year;
//Since the value can be empty, using String instead of Double
private String newIndex;
}
I am trying to compute the average of the newIndex value, which basically I cannot do as getNewIndex is String, and there can be empty string(values). I cannot convert to the null values to 0 as there will be 0 values in newIndex.
Is there an easier way to calculate the average?
Eg.
mapOfIndicators = new HashMap<>();
List<IndicatorTableDTO> _tempValue = new ArrayList();
IndicatorTableDTO _iTDTO = new IndicatorTableDTO("iName", "dName", "countryName1", 2012, "1.00");
_tempValue.add(_iTDTO);
_iTDTO = new IndicatorTableDTO("iName", "dName", "countryName2", 2012, "");
_tempValue.add(_iTDTO);
_iTDTO = new IndicatorTableDTO("iName", "dName", "countryName3", 2012, "0.02");
_tempValue.add(_iTDTO);
_iTDTO = new IndicatorTableDTO("iName", "dName", "countryName4", 2012, "-0.25");
_tempValue.add(_iTDTO);
_iTDTO = new IndicatorTableDTO("iName", "dName", "countryName5", 2012, "0.10");
_tempValue.add(_iTDTO);
mapOfIndicators.put("Test1", _tempValue);
_iTDTO = new IndicatorTableDTO("iName", "dName", "countryName1", 2012, "0.10");
_tempValue.add(_iTDTO);
_iTDTO = new IndicatorTableDTO("iName", "dName", "countryName2", 2012, "", "", "");
_tempValue.add(_iTDTO);
_iTDTO = new IndicatorTableDTO("iName", "dName", "countryName3", 2012, "", "", "");
_tempValue.add(_iTDTO);
_iTDTO = new IndicatorTableDTO("iName", "dName", "countryName4", 2012, "0.25", "", "");
_tempValue.add(_iTDTO);
_iTDTO = new IndicatorTableDTO("iName", "dName", "countryName5", 2012, "1.10", "", "");
_tempValue.add(_iTDTO);
mapOfIndicators.put("Test2", _tempValue);
Update 01: We can skip empty string/null values; the average would be per countryName, so I want to find the average of the newIndex for same contryName and eventually be able to get a Map as the final result.