예제 #1
0
  /**
   * Check and add the <code>Attribute</code> to this list at the given index. Note: does not check
   * for duplicate attributes.
   *
   * @param index index where to add <code>Attribute</code>
   * @param attribute <code>Attribute</code> to add
   */
  void add(int index, Attribute attribute) {
    if (attribute.getParent() != null) {
      throw new IllegalAddException(
          "The attribute already has an existing parent \""
              + attribute.getParent().getQualifiedName()
              + "\"");
    }

    String reason = Verifier.checkNamespaceCollision(attribute, parent);
    if (reason != null) {
      throw new IllegalAddException(parent, attribute, reason);
    }

    if (index < 0 || index > size) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }

    attribute.setParent(parent);

    ensureCapacity(size + 1);
    if (index == size) {
      elementData[size++] = attribute;
    } else {
      System.arraycopy(elementData, index, elementData, index + 1, size - index);
      elementData[index] = attribute;
      size++;
    }
    modCount++;
  }
예제 #2
0
  /**
   * Set the object at the specified location to the supplied object. Note: does not check for
   * duplicate attributes.
   *
   * @param index The location to set the value to.
   * @param attribute The attribute to set.
   * @return The object which was replaced. throws IndexOutOfBoundsException if index < 0 || index
   *     >= size()
   */
  Object set(int index, Attribute attribute) {
    if (index < 0 || index >= size)
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());

    if (attribute.getParent() != null) {
      throw new IllegalAddException(
          "The attribute already has an existing parent \""
              + attribute.getParent().getQualifiedName()
              + "\"");
    }

    String reason = Verifier.checkNamespaceCollision(attribute, parent);
    if (reason != null) {
      throw new IllegalAddException(parent, attribute, reason);
    }

    Attribute old = (Attribute) elementData[index];
    old.setParent(null);

    elementData[index] = attribute;
    attribute.setParent(parent);
    return old;
  }