コード例 #1
0
  /**
   * Clones the object Makes a deep copy of the Valivalues form references are set to null;
   *
   * @return
   */
  public Object clone() throws CloneNotSupportedException {
    Question copy = null;
    copy = (Question) super.clone();
    // make the copy a little deeper
    if (getValidValues() != null) {
      List validValuesCopy = new ArrayList();
      ListIterator it = getValidValues().listIterator();
      while (it.hasNext()) {
        FormValidValue validValue = (FormValidValue) it.next();
        FormValidValue clonedValidValue = (FormValidValue) validValue.clone();
        clonedValidValue.setQuestion(copy);
        validValuesCopy.add(clonedValidValue);
      }
      copy.setValidValues(validValuesCopy);
      copy.setForm(null);
      copy.setModule(null);
    }

    if (getInstructions() != null) {
      List instructionsCopy = new ArrayList();
      ListIterator it = getInstructions().listIterator();
      while (it.hasNext()) {
        Instruction instr = (Instruction) it.next();
        Instruction instrClone = (Instruction) instr.clone();
        instructionsCopy.add(instrClone);
      }
      copy.setInstructions(instructionsCopy);
    }

    return copy;
  }