private static long calculateFromChangelog( DefaultIssue issue, Collection<IssueChangeDto> debtChangelog, long periodDate) { List<FieldDiffs> debtDiffs = from(debtChangelog) .transform(ToFieldDiffs.INSTANCE) .filter(HasDebtChange.INSTANCE) .toSortedList(CHANGE_ORDERING); FieldDiffs currentChange = issue.currentChange(); if (currentChange != null && HasDebtChange.INSTANCE.apply(currentChange)) { debtDiffs = Lists.newArrayList(debtDiffs); debtDiffs.add(currentChange); } long newDebt = issue.effortInMinutes(); for (Iterator<FieldDiffs> it = debtDiffs.iterator(); it.hasNext(); ) { FieldDiffs diffs = it.next(); Date date = diffs.creationDate(); // TODO use longs if (isBeforeOrEqual(date, new Date(periodDate))) { // return new value from the change that is just before the period date return subtract(newDebt, debtDiff(diffs).newValueLong()); } if (!it.hasNext()) { // return old value from the change that is just after the period date when there's no more // element in changelog return subtract(newDebt, debtDiff(diffs).oldValueLong()); } } // no changelog return 0L; }
@Override public Date apply(@Nonnull FieldDiffs dto) { return dto.creationDate(); }