public class DefaultImmutableSet<T> extends java.lang.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(java.lang.Object obj) |
boolean |
exists(java.util.function.Predicate<T> predicate)
return true if predicate is fullfilled for at least one element
|
static <T> ImmutableSet<T> |
fromImmutableList(ImmutableList<T> list)
Create an immutable set from an immutable list.
|
static <T> ImmutableSet<T> |
fromSet(java.util.Set<T> set)
Create an immutable set from a mutable set
|
int |
hashCode() |
ImmutableSet<T> |
intersect(ImmutableSet<? extends T> set) |
boolean |
isEmpty() |
java.util.Iterator<T> |
iterator() |
private DefaultImmutableSet<T> |
newUnion(DefaultImmutableSet<? extends T> set) |
static <T> DefaultImmutableSet<T> |
nil()
the empty set
|
private DefaultImmutableSet<T> |
originalUnion(ImmutableSet<? extends T> set) |
ImmutableSet<T> |
remove(T element) |
int |
size() |
java.util.stream.Stream<T> |
stream() |
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.
|
java.util.Set<T> |
toSet() |
java.lang.String |
toString() |
ImmutableSet<T> |
union(ImmutableSet<? extends T> set) |
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 presentNotUniqueExceptionpublic ImmutableSet<T> union(ImmutableSet<? extends T> set)
union in interface ImmutableSet<T>private DefaultImmutableSet<T> newUnion(DefaultImmutableSet<? extends T> set)
private DefaultImmutableSet<T> originalUnion(ImmutableSet<? extends T> set)
public ImmutableSet<T> intersect(ImmutableSet<? extends T> set)
intersect in interface ImmutableSet<T>public java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>iterator in interface ImmutableSet<T>public java.util.stream.Stream<T> stream()
stream 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 boolean exists(java.util.function.Predicate<T> predicate)
exists in interface ImmutableSet<T>predicate - the predicatepublic 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(java.lang.Object obj)
equals in interface ImmutableSet<T>equals in class java.lang.Objectpublic <S> S[] toArray(S[] array)
toArray in interface ImmutableSet<T>public java.util.Set<T> toSet()
toSet in interface ImmutableSet<T>Set containing the same elements as this ImmutableSetpublic int hashCode()
hashCode in interface ImmutableSet<T>hashCode in class java.lang.Objectpublic ImmutableList<T> toImmutableList()
public static <T> ImmutableSet<T> fromImmutableList(ImmutableList<T> list)
list - a non-null immutable listpublic static <T> ImmutableSet<T> fromSet(java.util.Set<T> set)
set - a non-null mutable setpublic java.lang.String toString()
toString in class java.lang.Object