List<AdvanceMeasurement> result) {
Iterator<AdvanceMeasurement> iterator1 = list1.iterator();
Iterator<AdvanceMeasurement> iterator2 = list2.iterator();
AdvanceMeasurement next1;
if (iterator1.hasNext()) {
next1 = iterator1.next();
} else {
next1 = null;
}
AdvanceMeasurement next2;
if (iterator2.hasNext()) {
next2 = iterator2.next();
} else {
next2 = null;
}
BigDecimal previous1 = BigDecimal.ZERO;
BigDecimal previous2 = BigDecimal.ZERO;
BigDecimal previousResult = BigDecimal.ZERO;
LocalDate date;
BigDecimal add;
Date communicationDate;
BigDecimal totalHours = null;
if (advanceAssignment.getAdvanceType().getPercentage()) {
totalHours = new BigDecimal(advanceAssignment.getOrderElement()
.getWorkHours());
}
while ((next1 != null) && (next2 != null)) {
if (next1.getDate().compareTo(next2.getDate()) < 0) {
date = next1.getDate();
add = next1.getValue().subtract(previous1);
communicationDate = next1.getCommunicationDate();
previous1 = next1.getValue();
if (advanceAssignment.getAdvanceType().getPercentage()) {
BigDecimal orderElementHours = new BigDecimal(next1
.getAdvanceAssignment().getOrderElement()
.getWorkHours());
add = addMeasure(add, totalHours, orderElementHours);
}
if (iterator1.hasNext()) {
next1 = iterator1.next();
} else {
next1 = null;
}
} else if (next1.getDate().compareTo(next2.getDate()) > 0) {
date = next2.getDate();
add = next2.getValue().subtract(previous2);
communicationDate = next2.getCommunicationDate();
previous2 = next2.getValue();
if (advanceAssignment.getAdvanceType().getPercentage()) {
BigDecimal orderElementHours = new BigDecimal(next2
.getAdvanceAssignment().getOrderElement()
.getWorkHours());
add = addMeasure(add, totalHours, orderElementHours);
}
if (iterator2.hasNext()) {
next2 = iterator2.next();
} else {
next2 = null;
}
} else {
date = next1.getDate();
BigDecimal add1 = next1.getValue().subtract(previous1);
BigDecimal add2 = next2.getValue().subtract(previous2);
add = add1.add(add2);
communicationDate = getGreatestDate(next1
.getCommunicationDate(), next2.getCommunicationDate());
previous1 = next1.getValue();
previous2 = next2.getValue();
if (advanceAssignment.getAdvanceType().getPercentage()) {
BigDecimal orderElementHours1 = new BigDecimal(next1
.getAdvanceAssignment().getOrderElement()
.getWorkHours());
add1 = addMeasure(add1, totalHours, orderElementHours1);
BigDecimal orderElementHours2 = new BigDecimal(next2
.getAdvanceAssignment().getOrderElement()
.getWorkHours());
add2 = addMeasure(add2, totalHours, orderElementHours2);
add = add1.add(add2);
}
if (iterator1.hasNext()) {
next1 = iterator1.next();
} else {
next1 = null;
}
if (iterator2.hasNext()) {
next2 = iterator2.next();
} else {
next2 = null;
}
}
AdvanceMeasurement advanceMeasurement = AdvanceMeasurement.create();
advanceMeasurement.setAdvanceAssignment(advanceAssignment);
advanceMeasurement.setDate(date);
previousResult = previousResult.add(add);
checkAndSetValue(advanceMeasurement, previousResult);
advanceMeasurement.setCommunicationDate(communicationDate);
result.add(advanceMeasurement);
}
while (next1 != null) {
date = next1.getDate();
add = next1.getValue().subtract(previous1);
communicationDate = next1.getCommunicationDate();
previous1 = next1.getValue();
if (advanceAssignment.getAdvanceType().getPercentage()) {
BigDecimal orderElementHours = new BigDecimal(next1
.getAdvanceAssignment().getOrderElement()
.getWorkHours());
add = addMeasure(add, totalHours, orderElementHours);
}
if (iterator1.hasNext()) {
next1 = iterator1.next();
} else {
next1 = null;
}
AdvanceMeasurement advanceMeasurement = AdvanceMeasurement.create();
advanceMeasurement.setAdvanceAssignment(advanceAssignment);
advanceMeasurement.setDate(date);
checkAndSetValue(advanceMeasurement, previousResult.add(add));
previousResult = advanceMeasurement.getValue();
advanceMeasurement.setCommunicationDate(communicationDate);
result.add(advanceMeasurement);
}
while (next2 != null) {
date = next2.getDate();
add = next2.getValue().subtract(previous2);
communicationDate = next2.getCommunicationDate();
previous2 = next2.getValue();
if (advanceAssignment.getAdvanceType().getPercentage()) {
BigDecimal orderElementHours = new BigDecimal(next2
.getAdvanceAssignment().getOrderElement()
.getWorkHours());
add = addMeasure(add, totalHours, orderElementHours);
}
if (iterator2.hasNext()) {
next2 = iterator2.next();
} else {
next2 = null;
}
AdvanceMeasurement advanceMeasurement = AdvanceMeasurement.create();
advanceMeasurement.setAdvanceAssignment(advanceAssignment);
advanceMeasurement.setDate(date);
checkAndSetValue(advanceMeasurement, previousResult.add(add));
previousResult = advanceMeasurement.getValue();
advanceMeasurement.setCommunicationDate(communicationDate);
result.add(advanceMeasurement);
}
}