final void addRegulatedChild(int index, TemplateElement nestedElement) { final int lRegulatedChildCount = regulatedChildCount; TemplateElement[] lRegulatedChildBuffer = regulatedChildBuffer; if (lRegulatedChildBuffer == null) { lRegulatedChildBuffer = new TemplateElement[INITIAL_REGULATED_CHILD_BUFFER_CAPACITY]; regulatedChildBuffer = lRegulatedChildBuffer; } else if (lRegulatedChildCount == lRegulatedChildBuffer.length) { setRegulatedChildBufferCapacity(lRegulatedChildCount != 0 ? lRegulatedChildCount * 2 : 1); lRegulatedChildBuffer = regulatedChildBuffer; } // At this point: nestedElements == this.nestedElements, and has sufficient capacity. for (int i = lRegulatedChildCount; i > index; i--) { TemplateElement movedElement = lRegulatedChildBuffer[i - 1]; movedElement.index = i; lRegulatedChildBuffer[i] = movedElement; } nestedElement.index = index; nestedElement.parent = this; lRegulatedChildBuffer[index] = nestedElement; regulatedChildCount = lRegulatedChildCount + 1; }