boolean (final int index, final Collection<? extends Attribute> collection) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size()); } if (collection == null) { throw new NullPointerException( "Can not add a null Collection to AttributeList"); } final int addcnt = collection.size(); if (addcnt == 0) { return false; } if (addcnt == 1) { // quick check for single-add. add(index, collection.iterator().next()); return true; } ensureCapacity(size() + addcnt); final int tmpmodcount = modCount; boolean ok = false; int count = 0; try { for (Attribute att : collection) { add(index + count, att); count++; } ok = true; } finally { if (!ok) { while (--count >= 0) { remove(index + count); } modCount = tmpmodcount; } } return true; }