List<ZoneOffsetTransition> transitionList = new ArrayList<ZoneOffsetTransition>(256);
List<ZoneOffsetTransitionRule> lastTransitionRuleList = new ArrayList<ZoneOffsetTransitionRule>(2);
// initialize the standard offset calculation
TZWindow firstWindow = windowList.get(0);
ZoneOffset standardOffset = firstWindow.standardOffset;
Period savings = Period.ZERO;
if (firstWindow.fixedSavingAmount != null) {
savings = firstWindow.fixedSavingAmount;
}
ZoneOffset firstWallOffset = deduplicate(standardOffset.plus(savings));
OffsetDateTime windowStart = deduplicate(OffsetDateTime.dateTime(Year.MIN_YEAR, 1, 1, 0, 0, firstWallOffset));
// build the windows and rules to interesting data
for (TZWindow window : windowList) {
// tidy the state
window.tidy(windowStart.getYear());
// calculate effective savings at the start of the window
Period effectiveSavings = window.fixedSavingAmount;
if (effectiveSavings == null) {
// apply rules from this window together with the standard offset and
// savings from the last window to find the savings amount applicable
// at start of this window
effectiveSavings = Period.ZERO;
for (TZRule rule : window.ruleList) {
ZoneOffsetTransition trans = rule.toTransition(standardOffset, savings);
if (trans.getDateTime().isAfter(windowStart)) {
// previous savings amount found, which could be the savings amount at
// the instant that the window starts (hence isAfter)
break;
}
effectiveSavings = rule.savingAmount;
}
}
// check if standard offset changed, and update it
if (standardOffset.equals(window.standardOffset) == false) {
standardOffset = deduplicate(window.standardOffset);
standardOffsetList.add(deduplicate(windowStart.withOffsetSameInstant(standardOffset)));
}
// check if the start of the window represents a transition
ZoneOffset effectiveWallOffset = deduplicate(standardOffset.plus(effectiveSavings));
if (windowStart.getOffset().equals(effectiveWallOffset) == false) {
ZoneOffsetTransition trans = new ZoneOffsetTransition(windowStart, effectiveWallOffset);
transitionList.add(trans);
}
savings = effectiveSavings;