Extends the native collections to have quick access to all collection methods.

This method extends the prototypes of Array, Map and Set.

@see {@link extendIterablePrototype} to extend custom iterables.
432397
function extendNativeTypes() {
    extendIterablePrototype(Array.prototype, ["concat", "forEach", "indexOf", "join", "lastIndexOf", "reverse"]);
    const originalJoin = Array.prototype.join;
    Array.prototype.join = function (...args) {
        if (args.length == 4 || args.length == 5) {
            let collection = exports.Collection.from(this);
            return collection.join.call(collection, ...args);
        }
        return originalJoin.call(this, ...args);
    };
    const originalIndexOf = Array.prototype.indexOf;
    Array.prototype.indexOf = function (...args) {
        if (args.length == 2 && __isFunction(args[1])) {
            let collection = exports.Collection.from(this);
            return collection.indexOf.call(collection, ...args);
        }
        return originalIndexOf.call(this, ...args);
    };
    const originalLastIndexOf = Array.prototype.lastIndexOf;
    Array.prototype.lastIndexOf = function (...args) {
        if (args.length == 2 && __isFunction(args[1])) {
            let collection = exports.Collection.from(this);
            return collection.lastIndexOf.call(collection, ...args);
        }
        return originalLastIndexOf.call(this, ...args);
    };
    extendIterablePrototype(Map.prototype, ["add", "forEach"]);
    extendIterablePrototype(Set.prototype, ["add", "forEach"]);
}
738831
public <A extends Appendable> A appendTo(A appendable, Iterable<? extends Entry<?, ? extends Collection<?>>> entries)
			throws IOException {
		//    checkNotNull(appendable);
		Iterator<? extends Entry<?, ? extends Collection<?>>> iterator = entries.iterator();
		if (iterator.hasNext()) {
			Entry<?, ? extends Collection<?>> entry = iterator.next();
			appendable.append(toString(entry.getKey()));
			appendable.append(keyValueSeparator);
			entryJoiner.appendTo(appendable, entry.getValue());
			while (iterator.hasNext()) {
				appendable.append(separator);
				Entry<?, ? extends Collection<?>> e = iterator.next();
				appendable.append(toString(e.getKey()));
				appendable.append(keyValueSeparator);
				entryJoiner.appendTo(appendable, e.getValue());
			}
		}
		return appendable;
	}
1030649
public static <T, P, A, R extends Collection<A>> R collectWith(
            Iterable<T> iterable,
            Function2<? super T, ? super P, ? extends A> function,
            P parameter,
            R targetCollection)
    {
        if (iterable instanceof RichIterable)
        {
            return ((RichIterable<T>) iterable).collectWith(function, parameter, targetCollection);
        }
        if (iterable instanceof ArrayList)
        {
            return ArrayListIterate.collectWith((ArrayList<T>) iterable, function, parameter, targetCollection);
        }
        if (iterable instanceof RandomAccess)
        {
            return RandomAccessListIterate.collectWith((List<T>) iterable, function, parameter, targetCollection);
        }
        if (iterable != null)
        {
            return IterableIterate.collectWith(iterable, function, parameter, targetCollection);
        }
        throw new IllegalArgumentException("Cannot perform a collectWith on null");
    }
1046627
def extend(self, collection):
        
        if type(collection) is list:
            if self._col_dict is None and self._col_list is None:
                self._col_list = collection
            else:
                self._col_list += collection
            self._sync_list_to_dict(collection)
        elif type(collection) is dict:
            if self._col_dict is None and self._col_list is None:
                self._col_dict = collection
                self._col_list = collection.values()
            else:
                for key, value in collection.items():
                    self._set_key(key, value)
        else:
            raise NotImplementedError()
951584
@Override
    public Iterator<T> iterator() {
        
        /*
         * We make a copy of the allResults list to iterate over in order to
         * avoid ConcurrentModificationExceptions caused by other methods
         * loading more results into the list while someone iterates over it.
         * This is a more severe problem than it might seem, because even
         * innocuous-seeming operations such as contains() can modify the
         * underlying result set.
         */
        final List<T> allResultsCopy = new ArrayList<T>();
        allResultsCopy.addAll(allResults);        
        final Iterator<T> iter = allResultsCopy.iterator();
        
        return new Iterator<T>() {
    
            Iterator<T> iterator = iter;
            int pos = 0;
            
            @Override
            public boolean hasNext() {
                return iterator.hasNext() || nextResultsAvailable();
            }
    
            @Override
            public T next() {
                if ( !iterator.hasNext() ) {
                    /*
                     * Our private copy of the result list may be out of date
                     * with the full one. If it is, we just need to update our
                     * private copy to get more results. If it's not, we need to
                     * fetch more results from the service.
                     */
                    if ( allResults.size() == allResultsCopy.size() ) {
                        if ( !nextResultsAvailable() ) {
                            throw new NoSuchElementException();
                        }
                        moveNextResults();
                    } 
                    
                    if ( allResults.size() > allResultsCopy.size() )
                        allResultsCopy.addAll(allResults.subList(allResultsCopy.size(), allResults.size()));
                    
                    iterator = allResultsCopy.listIterator(pos);
                }
                
                pos++;
                return iterator.next();
            }
            
            @Override
            public void remove() {
                throw new UnsupportedOperationException(UNMODIFIABLE_MESSAGE);
            }            
        };
    }
790227
@SuppressWarnings({
     "unchecked", "rawtypes"
    })
    @Override
    public void extend(final String key, final Object value) {
        final Object v = configuration.get(key);
        if (v == null) {
            final Object array = Array.newInstance(value.getClass(), 1);
            Array.set(array, 0, value);
            configuration.put(key, array);
        }
        else {
            final Class<?> clazz = v.getClass();
            if (clazz.isArray()) {
                final int length = Array.getLength(v);
                final Object array = Array.newInstance(clazz.getComponentType(), length + 1);
                System.arraycopy(v, 0, array, 0, length);
                Array.set(array, length, value);
                configuration.put(key, array);
            }
            else if (v instanceof Collection) {
                ((Collection) v).add(value);
            }
            else {
                final String message = String.format("Cannot extend %s by %s.", key, value);
                throw new IllegalArgumentException(message);
            }
        }
    }
1181260
@SuppressWarnings("all")
    public static <C extends Class<?>> Map<String, C> buildClassNameMap(Iterable<C> set) {
        Map<String, C> classNameMap = new HashMap<String, C>();
        for (C javaClass : set) {
            classNameMap.put(javaClass.getName(), javaClass);
        }
        return classNameMap;
    }
779562
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
    private static Iterable<String> extend(final Response res,
        final Iterable<? extends CharSequence> headers) throws IOException {
        Response resp = res;
        for (final CharSequence hdr: headers) {
            resp = new RsWithHeader(resp, hdr);
        }
        return resp.head();
    }
210266
def extend(self, iterable):
        
        with self.lock:
            for item in iterable:
                self.append(item)
583245
def extend(self, *args, **kwargs):
        """"""
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))

        iterable = args[0] if args else None
        if iterable:
            if isinstance(iterable, Mapping) or hasattr(iterable, 'items'):
                for key, value in iterable.items():
                    self.append(key, value)
            elif hasattr(iterable, 'keys'):
                for key in iterable.keys():
                    self.append(key, iterable[key])
            else:
                for key, value in iterable:
                    self.append(key, value)

        for key, value in kwargs.items():
            self.append(key, value)
990176
int addAll(Collection<? extends T> collection) {
        int positionOfInsert = mObjects.size();
        mObjects.addAll(collection);
        return positionOfInsert;
    }
947513
public static <T> boolean addAll(Collection<T> target, Iterable<? extends T> iterable) {
        if (iterable instanceof Collection) {
            return target.addAll((Collection<? extends T>) iterable);
        }
        return Iterators.addAll(target, iterable.iterator());
    }
1334133
public static <T> void addAll(Collection<T> collection, Iterable<? extends T> items) {
    for (T item : items) {
      collection.add(item);
    }
  }
1219462
public static <T, P, A> Collection<A> collectWith(
            Iterable<T> iterable,
            Function2<? super T, ? super P, ? extends A> function,
            P parameter)
    {
        if (iterable instanceof MutableCollection)
        {
            return ((MutableCollection<T>) iterable).collectWith(function, parameter);
        }
        if (iterable instanceof ArrayList)
        {
            return ArrayListIterate.collectWith((ArrayList<T>) iterable, function, parameter);
        }
        if (iterable instanceof List<?>)
        {
            return ListIterate.collectWith((List<T>) iterable, function, parameter);
        }
        if (iterable instanceof Collection)
        {
            return IterableIterate.collectWith(
                    iterable,
                    function,
                    parameter,
                    DefaultSpeciesNewStrategy.INSTANCE.<A>speciesNew(
                            (Collection<T>) iterable,
                            ((Collection<T>) iterable).size()));
        }
        if (iterable != null)
        {
            return IterableIterate.collectWith(iterable, function, parameter);
        }
        throw new IllegalArgumentException("Cannot perform a collectWith on null");
    }
188213
@SuppressWarnings("unchecked")
        public <Coll extends CollectionFuncSup<T>> Coll add(T t) {
                Collection<T> coll = (Collection<T>) iterable;
                coll.add(t);
                return (Coll) this;
        }
170321
private void initExtendedTypes()
  {    
    m_extendedTypes = new ExtendedType[m_initialSize];
    for (int i = 0; i < DTM.NTYPES; i++) {
        m_extendedTypes[i] = m_defaultExtendedTypes[i];
        m_table[i] = new HashEntry(m_defaultExtendedTypes[i], i, i, null);
    }
    
    m_nextType = DTM.NTYPES;
  }
204442
@Override
    public boolean addAll(int location, Collection<? extends E> collection) {
        // int totalNeededSize = size() + collection.size();
        // int overhead = totalNeededSize - maxSize;
        // if(overhead > 0) {
        // removeRange(0, overhead);
        // }
        // return super.addAll(location, collection);
        if(location == size()){
            return super.addAll(location, collection);
        }
        throw new UnsupportedOperationException();
    }