I have a requirement wherein against the unlocked shares, I want to calculate locked up shares. Say if unlock shares for 1st Jan to 31st Jan are 2000 and 1st Feb to 29th Feb the unlock shares are 3000, then for the values of the locked up shares calculated will be 5000 for 1st Jan to 31st Jan and 3000 for 1st Feb to 29th Feb. I have two JSON arrays from which I am fetching these values in the form of IPOGridList. My code is as follows.
public static List<Long> getLockedUpShares(HashMap<String, String> testcase, String token,
List<IPOGridData> ipoGridList) {
List<Long> lockedUpSharesList = new ArrayList<>();
Long lockedUpShares = Long.valueOf(0);
for (int i = 0; i < ipoGridList.size(); i++) {
lockedUpShares=lockedUpShares + ipoGridList.get(i).getUnlockShares();
lockedUpSharesList.add(lockedUpShares + ipoGridList.get(i).getUnlockShares());
}
return lockedUpSharesList;
}
This is giving me values as 2000 and 5000 which are incorrect. My first value in the lockedupSharesList should be 5000 and the other should be 3000. That is the expected result. I am passing unlock shares as 2000 and 3000 as stated in the example given. Can anyone help me in creating a generic method for this lockedUpShares calculation to calculate it dynamically?