public class DefaultImmutableSet<T> extends Object implements ImmutableSet<T>
Modifier and Type | Class and Description |
---|---|
private static class |
DefaultImmutableSet.NILSet<T>
represents the empty set for elements of type
|
Modifier and Type | Field and Description |
---|---|
private ImmutableList<T> |
elementList
list containing the elements
|
private static long |
serialVersionUID |
static int |
UNION_OPTIMIZATION_SIZE
Constant defining the set size at which an optimized union operation will be executed.
|
Modifier | Constructor and Description |
---|---|
protected |
DefaultImmutableSet() |
private |
DefaultImmutableSet(ImmutableList<T> elementList)
creates new set containg all elements from the elementList
PRECONDITION: elementList has no duplicates
|
protected |
DefaultImmutableSet(T element)
creates new set with one element
|
Modifier and Type | Method and Description |
---|---|
ImmutableSet<T> |
add(T element)
adds an element
|
ImmutableSet<T> |
addUnique(T element)
adds an element, barfs if the element is already present
|
private void |
complainAboutSize() |
boolean |
contains(T obj) |
boolean |
equals(Object obj) |
static <T> ImmutableSet<T> |
fromImmutableList(ImmutableList<T> list)
Create an immutable set from an immutable list.
|
int |
hashCode() |
ImmutableSet<T> |
intersect(ImmutableSet<T> set) |
boolean |
isEmpty() |
Iterator<T> |
iterator() |
private DefaultImmutableSet<T> |
newUnion(DefaultImmutableSet<T> set) |
static <T> DefaultImmutableSet<T> |
nil()
the empty set
|
private DefaultImmutableSet<T> |
originalUnion(ImmutableSet<T> set) |
ImmutableSet<T> |
remove(T element) |
int |
size() |
boolean |
subset(ImmutableSet<T> s) |
<S> S[] |
toArray(S[] array)
Convert the set to a Java array (O(n))
|
ImmutableList<T> |
toImmutableList()
Get the underlying immutable list.
|
String |
toString() |
ImmutableSet<T> |
union(ImmutableSet<T> set) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
private static final long serialVersionUID
public static final int UNION_OPTIMIZATION_SIZE
private final ImmutableList<T> elementList
protected DefaultImmutableSet()
protected DefaultImmutableSet(T element)
element
- of type private DefaultImmutableSet(ImmutableList<T> elementList)
elementList
- IListpublic static final <T> DefaultImmutableSet<T> nil()
private void complainAboutSize()
public ImmutableSet<T> add(T element)
add
in interface ImmutableSet<T>
element
- of type public ImmutableSet<T> addUnique(T element) throws NotUniqueException
addUnique
in interface ImmutableSet<T>
element
- of type org.key_project.utils.collection.NotUniqueException
- if the element is already presentNotUniqueException
public ImmutableSet<T> union(ImmutableSet<T> set)
union
in interface ImmutableSet<T>
private DefaultImmutableSet<T> newUnion(DefaultImmutableSet<T> set)
private DefaultImmutableSet<T> originalUnion(ImmutableSet<T> set)
public ImmutableSet<T> intersect(ImmutableSet<T> set)
intersect
in interface ImmutableSet<T>
public boolean contains(T obj)
contains
in interface ImmutableSet<T>
public boolean subset(ImmutableSet<T> s)
subset
in interface ImmutableSet<T>
public int size()
size
in interface ImmutableSet<T>
public boolean isEmpty()
isEmpty
in interface ImmutableSet<T>
public ImmutableSet<T> remove(T element)
remove
in interface ImmutableSet<T>
public boolean equals(Object obj)
equals
in interface ImmutableSet<T>
equals
in class Object
public <S> S[] toArray(S[] array)
toArray
in interface ImmutableSet<T>
public int hashCode()
hashCode
in interface ImmutableSet<T>
hashCode
in class Object
public ImmutableList<T> toImmutableList()
public static <T> ImmutableSet<T> fromImmutableList(ImmutableList<T> list)
list
- a non-null immutable list