| java.lang.Object | |
| ↳ | com.facebook.common.internal.Sets |
Static utility methods pertaining to Set instances.
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| static <E> CopyOnWriteArraySet<E> |
newCopyOnWriteArraySet()
Creates an empty
CopyOnWriteArraySet instance. | ||||||||||
| static <E> HashSet<E> |
newHashSet(Iterator<? extends E> elements)
Creates a mutable
HashSet instance containing the given
elements in unspecified order. | ||||||||||
| static <E> HashSet<E> |
newHashSet(E... elements)
Creates a mutable
HashSet instance containing the given
elements in unspecified order. | ||||||||||
| static <E> HashSet<E> |
newHashSet()
Creates a mutable, empty
HashSet instance. | ||||||||||
| static <E> HashSet<E> |
newHashSet(Iterable<? extends E> elements)
Creates a mutable
HashSet instance containing the given
elements in unspecified order. | ||||||||||
| static <E> HashSet<E> |
newHashSetWithCapacity(int capacity)
Creates a
HashSet instance, with a high enough "initial capacity"
that it should hold expectedSize elements without growth. | ||||||||||
| static <E> Set<E> |
newIdentityHashSet()
Creates an empty
Set that uses identity to determine equality. | ||||||||||
| static <E> LinkedHashSet<E> |
newLinkedHashSet()
Creates a mutable, empty
LinkedHashSet instance. | ||||||||||
| static <E> Set<E> |
newSetFromMap(Map<E, Boolean> map)
Returns a set backed by the specified map.
| ||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
Creates an empty CopyOnWriteArraySet instance.
Note: if you need an immutable empty Set, use
emptySet() instead.
CopyOnWriteArraySetCreates a mutable HashSet instance containing the given
elements in unspecified order.
| elements | the elements that the set should contain |
|---|
HashSet containing those elements (minus duplicates)
Creates a mutable HashSet instance containing the given
elements in unspecified order.
| elements | the elements that the set should contain |
|---|
HashSet containing those elements (minus duplicates)
Creates a mutable, empty HashSet instance.
HashSet
Creates a mutable HashSet instance containing the given
elements in unspecified order.
| elements | the elements that the set should contain |
|---|
HashSet containing those elements (minus duplicates)
Creates a HashSet instance, with a high enough "initial capacity"
that it should hold expectedSize elements without growth.
This behavior cannot be broadly guaranteed, but it is observed to be true
for OpenJDK 1.6. It also can't be guaranteed that the method isn't
inadvertently oversizing the returned set.
| capacity | the number of elements you expect to add to the returned set |
|---|
HashSet with enough capacity to hold expectedSize elements without resizing| IllegalArgumentException | if expectedSize is negative
|
|---|
Creates an empty Set that uses identity to determine equality. It
compares object references, instead of calling equals, to
determine whether a provided object matches an element in the set. For
example, contains returns false when passed an object that
equals a set member, but isn't the same instance. This behavior is similar
to the way IdentityHashMap handles key lookups.
Creates a mutable, empty LinkedHashSet instance.
LinkedHashSet
Returns a set backed by the specified map. The resulting set displays the same ordering, concurrency, and performance characteristics as the backing map. In essence, this factory method provides a Set implementation corresponding to any Map implementation. There is no need to use this method on a Map implementation that already has a corresponding Set implementation (such as java.util.HashMap or java.util.TreeMap).
Each method invocation on the set returned by this method results in
exactly one method invocation on the backing map or its keySet
view, with one exception. The addAll method is implemented as a
sequence of put invocations on the backing map.
The specified map must be empty at the time this method is invoked, and should not be accessed directly after this method returns. These conditions are ensured if the map is created empty, passed directly to this method, and no reference to the map is retained, as illustrated in the following code fragment:
Set<Object> identityHashSet = Sets.newSetFromMap(
new IdentityHashMap<Object, Boolean>());
This method has the same behavior as the JDK 6 method
Collections.newSetFromMap(). The returned set is serializable if
the backing map is.
| map | the backing map |
|---|
| IllegalArgumentException | if map is not empty
|
|---|