public int addAllAbsent ( Collection < ? extends E > c ) { Object [ ] cs = c . toArray ( ) ; if ( cs . length == 0 ) return 0 ; Object [ ] uniq = new Object [ cs . length ] ; final ReentrantLock lock = this . lock ; lock . lock ( ) ; try { Object [ ] elements = getArray ( ) ; int len = elements . length ; int added = 0 ; for ( int i = 0 ; i < cs . length ; ++ i ) { // scan for duplicates Object e = cs [ i ] ; if ( indexOf ( e , elements , 0 , len ) < 0 && indexOf ( e , uniq , 0 , added ) < 0 ) uniq [ added ++ ] = e ; } if ( added > 0 ) { Object [ ] newElements = Arrays . copyOf ( elements , len + added ) ; System . arraycopy ( uniq , 0 , newElements , len , added ) ; setArray ( newElements ) ; } return added ; } finally { lock . unlock ( ) ; } }
Appends all of the elements in the specified collection that are not already contained in this list to the end of this list in the order that they are returned by the specified collection s iterator .