public boolean addAll()

in sources/java-incremental-compilation/jvm-inc-builder/src/com/intellij/tools/build/bazel/org/jdom/ContentList.java [1030:1104]


    public boolean addAll(final int index,
                          final Collection<? extends F> collection) {
      if (collection == null) {
        throw new NullPointerException("Cannot add a null collection");
      }

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

      final int adj = resync(index);
      if (adj == size && index > size()) {
        throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
      }

      final int addcnt = collection.size();
      if (addcnt == 0) {
        return false;
      }

      ContentList.this.ensureCapacity(ContentList.this.size() + addcnt);

      final int tmpmodcount = getModCount();
      final int tmpdmc = getDataModCount();
      boolean ok = false;

      int count = 0;

      try {
        for (Content c : collection) {
          if (c == null) {
            throw new NullPointerException(
              "Cannot add null content");
          }
          if (filter.matches(c)) {
            ContentList.this.add(adj + count, c);
            // we can optimise the laziness now by doing a partial
            // reset on
            // the backing list... invalidate everything *after* the
            // added
            // content
            if (backingpos.length <= size) {
              backingpos = Arrays.copyOf(backingpos, backingpos.length + addcnt);
            }
            backingpos[index + count] = adj + count;
            backingsize = index + count + 1;
            xdata = getDataModCount();

            count++;
          }
          else {
            throw new IllegalAddException("Filter won't allow the " +
                                          c.getClass().getName() +
                                          " '" + c + "' to be added to the list");
          }
        }
        ok = true;
      }
      finally {
        if (!ok) {
          // something failed... remove all added content
          while (--count >= 0) {
            ContentList.this.remove(adj + count);
          }
          // restore the mod-counts.
          setModCount(tmpmodcount, tmpdmc);
          // reset the cache... will need to redo some work on another
          // call maybe....
          backingsize = index;
          xdata = tmpmodcount;
        }
      }

      return true;
    }