// Path: src/main/java/org/dynaform/xml/form/Form.java
// public interface Form {
//   
//   String HL_CHILD = "/";
//   String HL_DESCENDANT_OR_SELF = "//";
//   String LL_CHILD = "!";
//   String LL_DESCENDANT_OR_SELF = "!!";
//   String INDEX_START = "[";
//   String INDEX_END = "]";
//   String OPERATOR_SEQUENCE = "sequence";
//   String OPERATOR_CHOICE = "choice";
//   String OPERATOR_ALL = "all";
//   
//   // Identity and parent
//   String getDescendantOrSelfSelector();         // "//element"
//   String getFullSelector();                     // "/aa/bb/cc!selector[0]"
//   String getHighLevelFullSelectorForChildren(); // "/aa/bb/cc"
// 
//   String getHighLevelId();  // cc
//   String getLowLevelId();   // selector[0]
//   
//   Form getParent();
//   void _setParent(Form parent);
//   
//   // Sequence
//   String nextCounterValue();
//   
//   // Visitors
// 	void accept(FormVisitor visitor);
// 	<T> T apply(FormFunction<T> function);
// 
// }
// 
// Path: src/main/java/org/dynaform/xml/form/FormFunction.java
// public interface FormFunction<T> {
// 	
// 	<E> T element(FormElement<E> element);
// 	
// 	<F extends Form> T section(FormSection<F> section);
// 	
// 	<F extends Form> T repeat(FormRepeat<F> sequence);
// 	
// 	T sequence(FormSequence composite);
// 	
// 	T choice(FormChoice choice);
// 	
// 	T all(FormAll all);
// 
// }
// 
// Path: src/main/java/org/dynaform/xml/form/FormVisitor.java
// public interface FormVisitor {
// 
// 	<E> void element(FormElement<E> element);
// 	
// 	<F extends Form> void section(FormSection<F> section);
// 	
// 	<F extends Form> void repeat(FormRepeat<F> sequence);
// 	
// 	void sequence(FormSequence composite);
// 	
// 	void choice(FormChoice choice);
// 	
// 	void all(FormAll all);
// 	
// }


import org.dynaform.xml.form.Form;
import org.dynaform.xml.form.FormChoice;
import org.dynaform.xml.form.FormFunction;
import org.dynaform.xml.form.FormVisitor;
import org.dynaform.xml.form.ToggleFormVisitor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

    return children.get(selectedIndex);
  }

  public int getSelectedIndex() {
    return selectedIndex;
  }

  public void setSelectedIndex(int index) {
    if (index < 0 || index >= children.size())
      throw new IndexOutOfBoundsException();

    if (index == selectedIndex)
      return; // no change
    
    // Disable last selected child element
    getSelectedChild().accept(ToggleFormVisitor.DISABLER);
    
    selectedIndex = index;
    
    // Enable new selected child element
    getSelectedChild().accept(ToggleFormVisitor.ENABLER);
    
    // Invoke listeners
    onSetSelectedIndex(index);
  }
  
  public void accept(FormVisitor visitor) {
    visitor.choice(this);
  }


// Path: src/main/java/org/dynaform/xml/form/Form.java
// public interface Form {
//   
//   String HL_CHILD = "/";
//   String HL_DESCENDANT_OR_SELF = "//";
//   String LL_CHILD = "!";
//   String LL_DESCENDANT_OR_SELF = "!!";
//   String INDEX_START = "[";
//   String INDEX_END = "]";
//   String OPERATOR_SEQUENCE = "sequence";
//   String OPERATOR_CHOICE = "choice";
//   String OPERATOR_ALL = "all";
//   
//   // Identity and parent
//   String getDescendantOrSelfSelector();         // "//element"
//   String getFullSelector();                     // "/aa/bb/cc!selector[0]"
//   String getHighLevelFullSelectorForChildren(); // "/aa/bb/cc"
// 
//   String getHighLevelId();  // cc
//   String getLowLevelId();   // selector[0]
//   
//   Form getParent();
//   void _setParent(Form parent);
//   
//   // Sequence
//   String nextCounterValue();
//   
//   // Visitors
// 	void accept(FormVisitor visitor);
// 	<T> T apply(FormFunction<T> function);
// 
// }
// 
// Path: src/main/java/org/dynaform/xml/form/FormFunction.java
// public interface FormFunction<T> {
// 	
// 	<E> T element(FormElement<E> element);
// 	
// 	<F extends Form> T section(FormSection<F> section);
// 	
// 	<F extends Form> T repeat(FormRepeat<F> sequence);
// 	
// 	T sequence(FormSequence composite);
// 	
// 	T choice(FormChoice choice);
// 	
// 	T all(FormAll all);
// 
// }
// 
// Path: src/main/java/org/dynaform/xml/form/FormVisitor.java
// public interface FormVisitor {
// 
// 	<E> void element(FormElement<E> element);
// 	
// 	<F extends Form> void section(FormSection<F> section);
// 	
// 	<F extends Form> void repeat(FormRepeat<F> sequence);
// 	
// 	void sequence(FormSequence composite);
// 	
// 	void choice(FormChoice choice);
// 	
// 	void all(FormAll all);
// 	
// }


// Path: src/main/java/org/dynaform/xml/form/impl/FormChoiceImpl.java
import org.dynaform.xml.form.Form;
import org.dynaform.xml.form.FormChoice;
import org.dynaform.xml.form.FormFunction;
import org.dynaform.xml.form.FormVisitor;
import org.dynaform.xml.form.ToggleFormVisitor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

    return children.get(selectedIndex);
  }

  public int getSelectedIndex() {
    return selectedIndex;
  }

  public void setSelectedIndex(int index) {
    if (index < 0 || index >= children.size())
      throw new IndexOutOfBoundsException();

    if (index == selectedIndex)
      return; // no change
    
    // Disable last selected child element
    getSelectedChild().accept(ToggleFormVisitor.DISABLER);
    
    selectedIndex = index;
    
    // Enable new selected child element
    getSelectedChild().accept(ToggleFormVisitor.ENABLER);
    
    // Invoke listeners
    onSetSelectedIndex(index);
  }
  
  public void accept(FormVisitor visitor) {
    visitor.choice(this);
  }


  public <T> T apply(FormFunction<T> function) {
