}
lightPolicies = new ArrayList<LightPolicySet>();
boolean notOne = false;
BlankPolicy blankPolicy = iterator.next();
LightPolicySet lightPolicy = new LightPolicySet(blankPolicy.getRealId().getSeries().getSeries(),
blankPolicy.getPolicyType().getTitle(),
blankPolicy.getIssueToAgentDate(),
blankPolicy.getInventoryPolicyState().toString());
if (blankPolicy.getWriteOffReason() != null) {
lightPolicy.setReason(blankPolicy.getWriteOffReason().toString());
}
long lastValue = blankPolicy.getRealId().getNumber();
Date lastDate = blankPolicy.getInventoryDate();
while (iterator.hasNext()) {
blankPolicy = iterator.next();
final long currentValue = blankPolicy.getRealId().getNumber();
final Date currentDate = blankPolicy.getInventoryDate();
if (EMPTY_STRING.equals(lightPolicy.getNumber())) {
lightPolicy.setNumber(Long.toString(lastValue));
notOne = false;
}
/* Check if prev policy vs current, if they have diff number or diff PolicyType
or diff PolicySerie or diff Invent Date or diff State*/
if ((lastValue + 1) != currentValue ||
!lastDate.equals(currentDate) ||
!blankPolicy.getPolicyType().getTitle().equals(lightPolicy.getType()) ||
!blankPolicy.getRealId().getSeries().getSeries().equals(lightPolicy.getSerie()) ||
!blankPolicy.getInventoryPolicyState().toString().equals(lightPolicy.getState()) ||
(blankPolicy.getWriteOffReason() != null && !blankPolicy.getWriteOffReason().toString().equals(lightPolicy.getReason()))) {
if (notOne) {
lightPolicy.setNumber(lightPolicy.getNumber() + NUMBERS_SEPARATOR + lastValue);
}
/*IF write-off , then set reason */
if (WRITE_OFF.equals(lightPolicy.getState())) {
lightPolicy.setReason(MessageBundle.getMessage(lightPolicy.getReason()));
lightPolicy.setState(MessageBundle.getMessage(lightPolicy.getState()) + REASON_SEPARATOR_LEFT + lightPolicy.getReason() + REASON_SEPARATOR_RIGHT);
} else {
lightPolicy.setState(MessageBundle.getMessage(lightPolicy.getState()));
}
lightPolicies.add(lightPolicy);
lightPolicy = new LightPolicySet(blankPolicy.getRealId().getSeries().getSeries(),
blankPolicy.getPolicyType().getTitle(),
blankPolicy.getIssueToAgentDate(),
blankPolicy.getInventoryPolicyState().toString());
if (blankPolicy.getWriteOffReason() != null) {
lightPolicy.setReason(blankPolicy.getWriteOffReason().toString());
}
lastDate = currentDate;
} else {
notOne = true;
}