Lines Matching refs:elements
36 * iteration order. Does not permit null elements.
74 // Casting to any type is safe because the set will never hold any elements.
93 * Returns an immutable set containing the given elements, in order. Repeated
105 * Returns an immutable set containing the given elements, in order. Repeated
117 * Returns an immutable set containing the given elements, in order. Repeated
129 * Returns an immutable set containing the given elements, in order. Repeated
141 * Returns an immutable set containing the given elements, in order. Repeated
146 * @throws NullPointerException if any of {@code elements} is null
148 public static <E> ImmutableSet<E> of(E... elements) {
149 checkNotNull(elements); // for GWT
150 switch (elements.length) {
154 return of(elements[0]);
156 return create(elements);
161 * Returns an immutable set containing the given elements, in order. Repeated
164 * sized inappropriately). This method iterates over {@code elements} at most
173 * <p><b>Note:</b> Despite what the method name suggests, if {@code elements}
177 * @throws NullPointerException if any of {@code elements} is null
179 public static <E> ImmutableSet<E> copyOf(Iterable<? extends E> elements) {
180 if (elements instanceof ImmutableSet
181 && !(elements instanceof ImmutableSortedSet)) {
183 ImmutableSet<E> set = (ImmutableSet<E>) elements;
186 return copyOfInternal(Collections2.toCollection(elements));
190 * Returns an immutable set containing the given elements, in order. Repeated
194 * @throws NullPointerException if any of {@code elements} is null
196 public static <E> ImmutableSet<E> copyOf(Iterator<? extends E> elements) {
197 Collection<E> list = Lists.newArrayList(elements);
248 private static <E> ImmutableSet<E> create(E... elements) {
249 return create(Arrays.asList(elements), elements.length);
254 // count is always the (nonzero) number of elements in the iterable
259 List<E> elements = new ArrayList<E>(count);
271 elements.add(element);
280 if (elements.size() == 1) {
282 return new SingletonImmutableSet<E>(elements.get(0), hashCode);
283 } else if (tableSize > Hashing.chooseTableSize(elements.size())) {
285 return create(elements, elements.size());
288 elements.toArray(), hashCode, table, mask);
293 // the elements (two or more) in the desired order.
294 final transient Object[] elements;
296 ArrayImmutableSet(Object[] elements) {
297 this.elements = elements;
301 return elements.length;
310 * create() method above, which only permits elements of type E.
314 return (UnmodifiableIterator<E>) Iterators.forArray(elements);
319 Platform.unsafeArrayCopy(elements, 0, array, 0, size());
330 Platform.unsafeArrayCopy(elements, 0, array, 0, size);
344 for (Object target : ((ArrayImmutableSet<?>) targets).elements) {
353 return new ImmutableAsList<E>(elements, this);
425 final Object[] elements;
426 SerializedForm(Object[] elements) {
427 this.elements = elements;
430 return of(elements);
488 * Adds each element of {@code elements} to the {@code ImmutableSet},
489 * ignoring duplicate elements (only the first duplicate element is added).
491 * @param elements the elements to add
493 * @throws NullPointerException if {@code elements} is null or contains a
496 @Override public Builder<E> add(E... elements) {
497 checkNotNull(elements); // for GWT
498 contents.ensureCapacity(contents.size() + elements.length);
499 super.add(elements);
504 * Adds each element of {@code elements} to the {@code ImmutableSet},
505 * ignoring duplicate elements (only the first duplicate element is added).
507 * @param elements the {@code Iterable} to add to the {@code ImmutableSet}
509 * @throws NullPointerException if {@code elements} is null or contains a
512 @Override public Builder<E> addAll(Iterable<? extends E> elements) {
513 if (elements instanceof Collection) {
514 Collection<?> collection = (Collection<?>) elements;
517 super.addAll(elements);
522 * Adds each element of {@code elements} to the {@code ImmutableSet},
523 * ignoring duplicate elements (only the first duplicate element is added).
525 * @param elements the elements to add to the {@code ImmutableSet}
527 * @throws NullPointerException if {@code elements} is null or contains a
530 @Override public Builder<E> addAll(Iterator<? extends E> elements) {
531 super.addAll(elements);