Creates a new immutable copy of the specified Collection.

@param collection the collection to copy
@return an immutable copy
181837
public static <T> Collection<T> immutableCollectionCopy(Collection<T> collection) {
      if (collection == null) return null;
      if (collection.isEmpty()) return Collections.emptySet();
      if (collection.size() == 1) return Collections.singleton(collection.iterator().next());

      Collection<? extends T> copy = ObjectDuplicator.duplicateCollection(collection);
      if (copy == null)
         copy = attemptCopyConstructor(collection, Collection.class);
      if (copy == null)
         copy = new ArrayList<>(collection);

      return new ImmutableCollectionWrapper<>(copy);
   }
176018
public static <K, V> Map<K, V> immutableMapCopy(Map<K, V> map) {
      if (map == null) return null;
      if (map.isEmpty()) return Collections.emptyMap();
      if (map.size() == 1) {
         Map.Entry<K, V> me = map.entrySet().iterator().next();
         return Collections.singletonMap(me.getKey(), me.getValue());
      }

      Map<? extends K, ? extends V> copy = ObjectDuplicator.duplicateMap(map);

      if (copy == null)
         copy = attemptCopyConstructor(map, Map.class);
      if (copy == null)
         copy = new HashMap<>(map);

      return new ImmutableMapWrapper<>(copy);
   }
333935
@Inline(value="$2.$3copyOfSorted($1)", imported=ImmutableSortedSet.class)
	public static <T> SortedSet<T> immutableCopy(SortedSet<T> set) {
		return ImmutableSortedSet.copyOfSorted(set);
	}
427115
protected function copyCollectionWith(Collection $collection, array $values)
    {
        $collection = clone $collection;

        $collection->exchangeArray($values);

        return $collection;
    }
644447
public Packer putStringCollection(final Collection<String> collection) {
		putVInt(collection.size());
		for (final String value : collection) {
			putString(value);
		}
		return this;
	}
1279738
public static <T> Source<T> from(Collection<T> collection) {
        return from(collection.iterator());
    }
534139
@SuppressWarnings("unchecked")
    @NonNull
    public static Set<String> nonNullSet(@Nullable Collection<String> collection) {
        return collection == null || collection.isEmpty()
                ? Collections.<String>emptySet()
                : new HashSet<String>(collection);
    }
70061
public static <T> Collection<T> addAll(Collection<T> collection, Object value) {
		return addAll(collection, value, TypeUtil.getTypeArgument(collection.getClass()));
	}
1035194
public function createFromCollection(Collection $collection)
    {
        $this->operator = new CollectionOperator($collection, $this->request);
        $this->prepare();

        return $this;
    }
597371
public static <E extends Enum<E>> StreamableEnumSet<E> copyOf (Collection<E> s)
    {
        if (s instanceof StreamableEnumSet<?>) {
            StreamableEnumSet<E> set = (StreamableEnumSet<E>)s;
            return copyOf(set);
        }
        if (s.isEmpty()) {
            throw new IllegalArgumentException("Collection must have at least one element.");
        }
        StreamableEnumSet<E> set = new StreamableEnumSet<E>(
            s.iterator().next().getDeclaringClass());
        set.addAll(s);
        return set;
    }
1346981
public static <R, C, V> ImmutableTable<R, C, V> copyOf(Iterable<Table.Cell<R, C, V>> cells) {
    final ImmutableTable.Builder<R, C, V> ret = ImmutableTable.builder();

    for (final Table.Cell<R, C, V> cell : cells) {
      ret.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
    }

    return ret.build();
  }
11073
public <T> List<T> cloneList(List<T> list) {
        return new ArrayList<T>(list);
    }
900428
@SuppressWarnings("unchecked")
    public static <T> PromisesArray<T> of(Collection<T> collection) {
        final ArrayList<Promise<T>> res = new ArrayList<>();
        for (T t : collection) {
            res.add(Promise.success(t));
        }
        final Promise[] promises = res.toArray(new Promise[res.size()]);
        return new PromisesArray<>((PromiseFunc<Promise<T>[]>) executor -> {
            executor.result(promises);
        });
    }
90139
public static <T> T[] toArray(final Collection<T> collection) {

        T next = getFirstNotNullValue(collection);
        if (next != null) {
            Object[] objects = collection.toArray();
            @SuppressWarnings("unchecked")
            T[] convertedObjects = (T[]) Array.newInstance(next.getClass(), objects.length);
            System.arraycopy(objects, 0, convertedObjects, 0, objects.length);
            return convertedObjects;
        } else {
            return null;
        }
    }
439767
public static <T> Collection<T> addAll(Collection<T> collection, Enumeration<T> enumeration) {
		if (null != collection && null != enumeration) {
			while (enumeration.hasMoreElements()) {
				collection.add(enumeration.nextElement());
			}
		}
		return collection;
	}
608394
public static <K, V> Map<K, V> copyOf(Map<K, V> map) {
        Preconditions.checkNotNull(map);
        return ImmutableMap.<K, V> builder().putAll(map).build();
    }
726833
@Inline(value="$2.$3copyOf($1)", imported=ImmutableList.class)
	public static <T> List<T> immutableCopy(List<? extends T> list) {
		return ImmutableList.copyOf(list);
	}