/** * Clear the current list and set it to the contents of the <code>Collection</code>. object. * * @param collection The collection to use. */ void clearAndSet(Collection collection) { Attribute[] old = elementData; int oldSize = size; elementData = null; size = 0; if ((collection != null) && (collection.size() != 0)) { ensureCapacity(collection.size()); try { addAll(0, collection); } catch (RuntimeException exception) { elementData = old; size = oldSize; throw exception; } } if (old != null) { for (int i = 0; i < oldSize; i++) { Attribute attribute = old[i]; attribute.setParent(null); } } modCount++; }
/** * 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++; }
/** Removes the given attribute from the list. */ void removeAttribute(Attribute attr) { int pos = attribs.indexOf(attr); if (-1 == pos) { throw new PublicException(BpmRuntimeError.SDT_NO_SUCH_ATTRIBUTE.raise(attr)); } else { attribs.remove(pos); attr.setParent(null); } }
/** Clear the current list. */ public void clear() { if (elementData != null) { for (int i = 0; i < size; i++) { Attribute attribute = elementData[i]; attribute.setParent(null); } elementData = null; size = 0; } modCount++; }
/** * Remove the object at the specified offset. * * @param index The offset of the object. * @return The Object which was removed. */ public Object remove(int index) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size()); Attribute old = elementData[index]; old.setParent(null); int numMoved = size - index - 1; if (numMoved > 0) System.arraycopy(elementData, index + 1, elementData, index, numMoved); elementData[--size] = null; // Let gc do its work modCount++; return old; }
/** * Adds the given attribute to the list, possibly replacing an existing attribute matching the new * attribute's name and namespace URI. */ public void addAttribute(Attribute attr) { if (null != attr.getParent()) { throw new PublicException(BpmRuntimeError.SDT_ATTRIBUTE_MUST_BE_DETACHED.raise()); } if (attribs.isEmpty()) { this.attribs = newArrayList(); } for (int i = 0; i < attribs.size(); ++i) { Attribute attrib = attribs.get(i); if (areEqual(attrib.getLocalName(), attr.getLocalName()) && areEqual(attrib.getNamespaceURI(), attr.getNamespaceURI())) { attrib.setParent(null); attribs.set(i, attr); attr.setParent(this); return; } } attribs.add(attr); attr.setParent(this); }
/** * 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; }