Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.primitives.Ints;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.annotation.Nullable;
/**
* A high-performance, immutable {@code Set} with reliable, user-specified
* iteration order. Does not permit null elements.
*
*
Unlike {@link Collections#unmodifiableSet}, which is a view of a
* separate collection that can still change, an instance of this class contains
* its own private data and will never change. This class is convenient
* for {@code public static final} sets ("constant sets") and also lets you
* easily make a "defensive copy" of a set provided to your class by a caller.
*
*
Warning: Like most sets, an {@code ImmutableSet} will not function
* correctly if an element is modified after being placed in the set. For this
* reason, and to avoid general confusion, it is strongly recommended to place
* only immutable objects into this collection.
*
*
This class has been observed to perform significantly better than {@link
* HashSet} for objects with very fast {@link Object#hashCode} implementations
* (as a well-behaved immutable object should). While this class's factory
* methods create hash-based instances, the {@link ImmutableSortedSet} subclass
* performs binary searches instead.
*
*
Note: Although this class is not final, it cannot be subclassed
* outside its package as it has no public or protected constructors. Thus,
* instances of this type are guaranteed to be immutable.
*
*
See the Guava User Guide article on
* immutable collections.
*
* @see ImmutableList
* @see ImmutableMap
* @author Kevin Bourrillion
* @author Nick Kralevich
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings("serial") // we're overriding default serialization
public abstract class ImmutableSet extends ImmutableCollection
implements Set {
/**
* Returns the empty immutable set. This set behaves and performs comparably
* to {@link Collections#emptySet}, and is preferable mainly for consistency
* and maintainability of your code.
*/
// Casting to any type is safe because the set will never hold any elements.
@SuppressWarnings({"unchecked"})
public static ImmutableSet of() {
return (ImmutableSet) EmptyImmutableSet.INSTANCE;
}
/**
* Returns an immutable set containing a single element. This set behaves and
* performs comparably to {@link Collections#singleton}, but will not accept
* a null element. It is preferable mainly for consistency and
* maintainability of your code.
*/
public static ImmutableSet of(E element) {
return new SingletonImmutableSet(element);
}
/**
* Returns an immutable set containing the given elements, in order. Repeated
* occurrences of an element (according to {@link Object#equals}) after the
* first are ignored.
*
* @throws NullPointerException if any element is null
*/
public static ImmutableSet of(E e1, E e2) {
return construct(e1, e2);
}
/**
* Returns an immutable set containing the given elements, in order. Repeated
* occurrences of an element (according to {@link Object#equals}) after the
* first are ignored.
*
* @throws NullPointerException if any element is null
*/
public static ImmutableSet of(E e1, E e2, E e3) {
return construct(e1, e2, e3);
}
/**
* Returns an immutable set containing the given elements, in order. Repeated
* occurrences of an element (according to {@link Object#equals}) after the
* first are ignored.
*
* @throws NullPointerException if any element is null
*/
public static ImmutableSet of(E e1, E e2, E e3, E e4) {
return construct(e1, e2, e3, e4);
}
/**
* Returns an immutable set containing the given elements, in order. Repeated
* occurrences of an element (according to {@link Object#equals}) after the
* first are ignored.
*
* @throws NullPointerException if any element is null
*/
public static ImmutableSet of(E e1, E e2, E e3, E e4, E e5) {
return construct(e1, e2, e3, e4, e5);
}
/**
* Returns an immutable set containing the given elements, in order. Repeated
* occurrences of an element (according to {@link Object#equals}) after the
* first are ignored.
*
* @throws NullPointerException if any element is null
* @since 3.0 (source-compatible since 2.0)
*/
public static ImmutableSet of(E e1, E e2, E e3, E e4, E e5, E e6,
E... others) {
final int paramCount = 6;
Object[] elements = new Object[paramCount + others.length];
elements[0] = e1;
elements[1] = e2;
elements[2] = e3;
elements[3] = e4;
elements[4] = e5;
elements[5] = e6;
for (int i = paramCount; i < elements.length; i++) {
elements[i] = others[i - paramCount];
}
return construct(elements);
}
/** {@code elements} has to be internally created array. */
private static ImmutableSet construct(Object... elements) {
int tableSize = chooseTableSize(elements.length);
Object[] table = new Object[tableSize];
int mask = tableSize - 1;
ArrayList