gt:         for (GlueElement child : children) {
context: /*
   * Copyright (c) 2012, 2014, Oracle and/or its affiliates.
   * All rights reserved. Use is subject to license terms.
   *
   * This file is available and licensed under the following license:
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   *  - Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *  - Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the distribution.
   *  - Neither the name of Oracle Corporation nor the names of its
   *    contributors may be used to endorse or promote products derived
   *    from this software without specific prior written permission.
   *
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   */
  package com.oracle.javafx.scenebuilder.kit.fxom.glue;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.Objects;
  
  /**
   *
   *
   */
  public class GlueElement extends GlueNode {
  
      private final static int INDENT_STEP = 3;
  
      private GlueDocument document;
      private String tagName;
      private final List<GlueElement> children = new ArrayList<>();
  
      private final Map<String, String> attributes = new HashMap<>();
      private final List<GlueAuxiliary> front = new ArrayList<>();
      private final List<GlueAuxiliary> tail = new ArrayList<>();
      private final List<GlueAuxiliary> content = new ArrayList<>();
      private int indentDepth;
      private boolean synthetic;
  
      private GlueElement parent;
  
      public GlueElement(GlueDocument document, String tagName) {
          this(document, tagName, 0, true /* preset */);
      }
  
      public GlueElement(GlueDocument document, String tagName, int indentDepth, boolean preset) {
          assert document != null;
          assert tagName != null;
  
          this.document = document;
          this.tagName = tagName;
          this.indentDepth = indentDepth;
          if (preset) {
              front.add(new GlueCharacters(document, GlueCharacters.Type.TEXT, "\n")); //NOI18N
              tail.add(new GlueCharacters(document, GlueCharacters.Type.TEXT, "\n")); //NOI18N
          }
      }
  
      public GlueElement(GlueDocument document, String tagName, GlueElement template) {
          this(document, tagName, template.indentDepth, false);
  
          final int templateIndent = template.guessIndent();
          if (templateIndent != -1) {
              front.add(makeIndentCharacters(templateIndent));
              tail.add(makeIndentCharacters(templateIndent));
          }
      }
  
      public GlueElement getParent() {
          return parent;
      }
  
      public GlueDocument getDocument() {
          return document;
      }
  
      public String getTagName() {
          return tagName;
      }
  
      public void setTagName(String tagName) {
          assert tagName != null;
          assert tagName.isEmpty() == false;
          this.tagName = tagName;
      }
  
      public List<GlueElement> getChildren() {
          return Collections.unmodifiableList(children);
      }
  
      public void addToParent(GlueElement newParent) {
          addToParent(-1, newParent);
      }
  
      public void addToParent(int index, GlueElement newParent) {
          assert newParent != null;
          assert newParent != parent;
          assert newParent.getDocument() == document;
          assert -1 <= index;
          assert index <= newParent.children.size();
  
          if (parent != null) {
              this.removeFromParent();
          } else if (this == document.getRootElement()) {
              document.setRootElement(null);
          }
  
          if (index == -1) {
              index = newParent.children.size();
          }
          newParent.children.add(index, this);
          this.parent = newParent;
      }
  
      public void addBefore(GlueElement nextSibling) {
          assert nextSibling != null;
          assert nextSibling.getDocument() == document;
          assert nextSibling.getParent() != null;
  
          final GlueElement siblingParent = nextSibling.getParent();
          final int nextSiblingIndex = siblingParent.getChildren().indexOf(nextSibling);
          assert nextSiblingIndex != -1;
  
          addToParent(nextSiblingIndex, siblingParent);
      }
  
  
      public void removeFromParent() {
          assert parent != null;
          assert parent.children.contains(this);
  
          parent.children.remove(this);
          parent = null;
      }
  
      public Map<String, String> getAttributes() {
          return attributes;
      }
  
      public List<GlueAuxiliary> getFront() {
          return front;
      }
  
      public List<GlueAuxiliary> getTail() {
          return tail;
      }
  
      public List<GlueAuxiliary> getContent() {
          return content;
      }
  
      public int getDepth() {
          int result = 0;
          GlueElement ancestor = parent;
  
          while (ancestor != null) {
              result++;
              ancestor = ancestor.getParent();
          }
  
          return result;
      }
  
      public void updateIndent(int depth) {
          if (indentDepth != depth) {
              final int indentDelta = (depth - indentDepth) * INDENT_STEP;
              if (front.isEmpty()) {
                  front.add(makeIndentCharacters(depth * INDENT_STEP));
              } else {
                  for (GlueAuxiliary auxiliary : front) {
                      if (auxiliary instanceof GlueCharacters) {
                          final GlueCharacters characters = (GlueCharacters) auxiliary;
                          characters.adjustIndentBy(indentDelta);
                      }
                  }
              }
  
              if (tail.isEmpty()) {
                  tail.add(makeIndentCharacters(depth * INDENT_STEP));
              } else {
                  for (GlueAuxiliary auxiliary : tail) {
                      if (auxiliary instanceof GlueCharacters) {
                          final GlueCharacters characters = (GlueCharacters) auxiliary;
                          characters.adjustIndentBy(indentDelta);
                      }
                  }
              }
              indentDepth = depth;
          }
  
          final int nextDepth = synthetic ? depth : depth+1;
  