public final class Sets extends Object
com.google.common.collect.Sets.| Modifier and Type | Class and Description |
|---|---|
private static class |
Sets.SetFromMap<E> |
| Modifier and Type | Field and Description |
|---|---|
private static int |
THIRD
Capacity ratio.
|
| Modifier | Constructor and Description |
|---|---|
private |
Sets()
Hidden for pure static factory.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) static int |
capacity(int expectedSize)
Returns a capacity that is sufficient to keep the map from being resized as long as it grows no larger than
expectedSize and the load factor is >= its default (0.75).
|
static void |
checkArgument(boolean expression,
Object errorMessage)
Ensures the truth of an expression involving one or more parameters to the calling method.
|
static <E> Set<E> |
newHashSet()
Creates a new hash set.
|
static <E> Set<E> |
newHashSet(E... elements)
Creates a mutable
HashSet instance containing the given elements in unspecified order. |
static <E> Set<E> |
newHashSetWithExpectedSize(int expectedSize)
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> Set<E> |
newSetFromMap(Map<E,Boolean> map)
Returns a set backed by the specified map.
|
static <E> SortedSet<E> |
newTreeSet()
Creates a new tree set.
|
private static final int THIRD
static int capacity(int expectedSize)
expectedSize - must not be negativepublic static <E> Set<E> newHashSet()
E - type of elementsnull, always new instancepublic static <E> Set<E> newHashSet(E... elements)
HashSet instance containing the given elements in unspecified order.E - type of elementselements - the elements that the set should containHashSet containing those elements (minus duplicates)public static <E> Set<E> newHashSetWithExpectedSize(int expectedSize)
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.
E - type of elementsexpectedSize - the number of elements you expect to add to the returned setHashSet with enough capacity to hold expectedSize elements without resizing
//CHECKSTYLE:OFFIllegalArgumentException - if expectedSize is negative
//CHECKSTYLE:ONpublic static <E> SortedSet<E> newTreeSet()
E - type of elementsnull, always new instancepublic static <E> Set<E> newIdentityHashSet()
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.
E - a E object.Set object.public static <E> Set<E> newSetFromMap(Map<E,Boolean> 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 HashMap or 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.E - a E object.map - the backing mapIllegalArgumentException - if map is not emptypublic static void checkArgument(boolean expression,
Object errorMessage)
expression - a boolean expressionerrorMessage - the exception message to use if the check fails; will be converted to a string using
String.valueOf(Object)IllegalArgumentException - if expression is falseCopyright © 2014 Sven Strittmatter. All Rights Reserved.