/** * Adds the given XMLObject to this list. * * @param index index at which to add the given XMLObject * @param element element to be stored at the given index * * @throws IllegalArgumentException thrown if the given XMLObject already has a parent that is different from the * XMLObject given at list construction time */ public void add(int index, ElementType element) throws IllegalArgumentException { if (element == null || elements.contains(element)) { return; } setParent(element); parent.getIDIndex().registerIDMappings(element.getIDIndex()); modCount++; elements.add(index, element); }
/** * Adds the given XMLObject to this list. * * @param index index at which to add the given XMLObject * @param element element to be stored at the given index * * @throws IllegalArgumentException thrown if the given XMLObject already has a parent that is different from the * XMLObject given at list construction time */ public void add(int index, ElementType element) throws IllegalArgumentException { if (element == null || elements.contains(element)) { return; } setParent(element); parent.getIDIndex().registerIDMappings(element.getIDIndex()); modCount++; elements.add(index, element); }
/** * Replaces the XMLObject at the specified index with the given element. * * @param index index of the XMLObject to be replaced * @param element element to be stored at the given index * * @return the replaced XMLObject * * @throws IllegalArgumentException thrown if the given XMLObject already has a parent that is different from the * XMLObject given at list construction time */ public ElementType set(int index, ElementType element) throws IllegalArgumentException { if (element == null) { return null; } setParent(element); ElementType removedElement = elements.set(index, element); if (removedElement != null) { removedElement.setParent(null); parent.getIDIndex().deregisterIDMappings(removedElement.getIDIndex()); } // Note: to avoid ordering problems, this needs to be called after // the deregistration, in case the added element has a same ID string // value as the removed one, else you will lose it. parent.getIDIndex().registerIDMappings(element.getIDIndex()); modCount++; return removedElement; }
/** * Replaces the XMLObject at the specified index with the given element. * * @param index index of the XMLObject to be replaced * @param element element to be stored at the given index * * @return the replaced XMLObject * * @throws IllegalArgumentException thrown if the given XMLObject already has a parent that is different from the * XMLObject given at list construction time */ public ElementType set(int index, ElementType element) throws IllegalArgumentException { if (element == null) { return null; } setParent(element); ElementType removedElement = elements.set(index, element); if (removedElement != null) { removedElement.setParent(null); parent.getIDIndex().deregisterIDMappings(removedElement.getIDIndex()); } // Note: to avoid ordering problems, this needs to be called after // the deregistration, in case the added element has a same ID string // value as the removed one, else you will lose it. parent.getIDIndex().registerIDMappings(element.getIDIndex()); modCount++; return removedElement; }