/** * Creates a new immutable set that consists of the elements in the given collection. If the given collection is already an instance created by * {@link ImmutableSet}, the instance is re-used. * * @param collection the given collection * @return a new immutable set that consists of the elements in the given collection */ @SuppressWarnings("unchecked") public static <T> Set<T> copyOf(Collection<? extends T> collection) { Preconditions.checkNotNull(collection); if (collection instanceof AbstractImmutableSet<?>) { return (Set<T>) collection; } if (collection.isEmpty()) { return Collections.emptySet(); } if (collection instanceof Set) { return from((Set<T>) collection); } return ImmutableSet.<T> builder().addAll(collection).build(); }
/** * Creates a new immutable set that consists of the elements in the given collection. If the given collection is already an instance created by * {@link ImmutableSet}, the instance is re-used. * * @param collection the given collection * @return a new immutable set that consists of the elements in the given collection */ @SuppressWarnings("unchecked") public static <T> Set<T> copyOf(Collection<? extends T> collection) { Preconditions.checkNotNull(collection); if (collection instanceof AbstractImmutableSet<?>) { return (Set<T>) collection; } if (collection.isEmpty()) { return Collections.emptySet(); } if (collection instanceof Set) { return from((Set<T>) collection); } return ImmutableSet.<T> builder().addAll(collection).build(); }
/** * Creates a new immutable set that consists of the elements in the given collection. If the given collection is already an instance created by * {@link ImmutableSet}, the instance is re-used. * * @param collection the given collection * @return a new immutable set that consists of the elements in the given collection */ @SuppressWarnings("unchecked") public static <T> Set<T> copyOf(Collection<? extends T> collection) { Preconditions.checkNotNull(collection); if (collection instanceof AbstractImmutableSet<?>) { return (Set<T>) collection; } if (collection.isEmpty()) { return Collections.emptySet(); } if (collection instanceof Set) { return from((Set<T>) collection); } return ImmutableSet.<T> builder().addAll(collection).build(); }
/** * Creates a new immutable set that consists of the elements in the given collection. If the given collection is already an instance created by * {@link ImmutableSet}, the instance is re-used. * * @param collection the given collection * @return a new immutable set that consists of the elements in the given collection */ @SuppressWarnings("unchecked") public static <T> Set<T> copyOf(Collection<? extends T> collection) { Preconditions.checkNotNull(collection); if (collection instanceof AbstractImmutableSet<?>) { return (Set<T>) collection; } if (collection.isEmpty()) { return Collections.emptySet(); } if (collection instanceof Set) { return from((Set<T>) collection); } return ImmutableSet.<T> builder().addAll(collection).build(); }
/** * Creates a new immutable set that consists of the elements in the given collection. If the given collection is already an instance created by * {@link ImmutableSet}, the instance is re-used. * * @param collection the given collection * @return a new immutable set that consists of the elements in the given collection */ @SuppressWarnings("unchecked") public static <T> Set<T> copyOf(Collection<? extends T> collection) { Preconditions.checkNotNull(collection); if (collection instanceof AbstractImmutableSet<?>) { return (Set<T>) collection; } if (collection.isEmpty()) { return Collections.emptySet(); } if (collection instanceof Set) { return from((Set<T>) collection); } return ImmutableSet.<T> builder().addAll(collection).build(); }
/** * Creates a new immutable set that consists of the elements in the given collection. If the given collection is already an instance created by * {@link ImmutableSet}, the instance is re-used. * * @param collection the given collection * @return a new immutable set that consists of the elements in the given collection */ @SuppressWarnings("unchecked") public static <T> Set<T> copyOf(Collection<? extends T> collection) { Preconditions.checkNotNull(collection); if (collection instanceof AbstractImmutableSet<?>) { return (Set<T>) collection; } if (collection.isEmpty()) { return Collections.emptySet(); } if (collection instanceof Set) { return from((Set<T>) collection); } return ImmutableSet.<T> builder().addAll(collection).build(); }