Package org.organicdesign.fp.collections
Interface UnmodSet<E>
-
- All Superinterfaces:
Collection<E>,Iterable<E>,Set<E>,Sized,Transformable<E>,UnmodCollection<E>,UnmodIterable<E>
- All Known Subinterfaces:
BaseSet<E>,ImSet<E>,ImSortedSet<E>,MutSet<E>,UnmodSortedSet<E>
- All Known Implementing Classes:
AbstractUnmodSet,PersistentHashSet,PersistentHashSet.MutHashSet,PersistentTreeSet
public interface UnmodSet<E> extends UnmodCollection<E>, Set<E>
An unmodifiable set
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.organicdesign.fp.collections.UnmodIterable
UnmodIterable.UnIterable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default booleanadd(E e)Deprecated.default booleanaddAll(@NotNull Collection<? extends E> c)Deprecated.default voidclear()Deprecated.booleancontains(Object o)Returns true if the set contains the given item.default booleancontainsAll(@NotNull Collection<?> items)The default implementation of this method has O(this.size() + that.size()) or O(n) performance.default booleanisEmpty()This is a convenience method inherited from Collection that returns true if size() == 0 (if this set contains no elements).@NotNull UnmodIterator<E>iterator()Iterates over contents with no guarantees about their ordering.default booleanremove(Object o)Deprecated.default booleanremoveAll(@NotNull Collection<?> c)Deprecated.default booleanremoveIf(Predicate<? super E> filter)Deprecated.default booleanretainAll(@NotNull Collection<?> c)Deprecated.default Object @NotNull []toArray()This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations.default <T> @NotNull T @NotNull []toArray(T @NotNull [] as)This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations.-
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface java.util.Set
equals, hashCode, size, spliterator
-
Methods inherited from interface org.organicdesign.fp.xform.Transformable
any, toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutList, toMutMap, toMutRrbt, toMutSet, toMutSortedMap, toMutSortedSet
-
-
-
-
Method Detail
-
add
@Deprecated default boolean add(E e)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Specified by:
addin interfaceUnmodCollection<E>
-
addAll
@Deprecated default boolean addAll(@NotNull @NotNull Collection<? extends E> c)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Specified by:
addAllin interfaceUnmodCollection<E>
-
clear
@Deprecated default void clear()
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Specified by:
clearin interfaceUnmodCollection<E>
-
contains
boolean contains(Object o)
Returns true if the set contains the given item. This is the defining method of a set. Sets have to override this because the default implementation in UnmodCollection is O(n) whereas a sorted set should be O(log n) or O(1).
-
containsAll
default boolean containsAll(@NotNull @NotNull Collection<?> items)The default implementation of this method has O(this.size() + that.size()) or O(n) performance. So even though contains() is impossible to implement efficiently for Lists, containsAll() has a decent implementation (brute force would be O(this.size() * that.size()) or O(n^2) ).- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>- Specified by:
containsAllin interfaceUnmodCollection<E>
-
isEmpty
default boolean isEmpty()
This is a convenience method inherited from Collection that returns true if size() == 0 (if this set contains no elements).- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Specified by:
isEmptyin interfaceUnmodCollection<E>
-
iterator
@NotNull @NotNull UnmodIterator<E> iterator()
Iterates over contents with no guarantees about their ordering. An unmodifiable iterator A one-time use, mutable, not-thread-safe way to get each value of the underling collection in turn. I experimented with various thread-safe alternatives, but the JVM is optimized around iterators so this is the lowest common denominator of collection iteration, even though iterators are inherently mutable.- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceSet<E>- Specified by:
iteratorin interfaceUnmodCollection<E>- Specified by:
iteratorin interfaceUnmodIterable<E>
-
remove
@Deprecated default boolean remove(Object o)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Specified by:
removein interfaceUnmodCollection<E>
-
removeAll
@Deprecated default boolean removeAll(@NotNull @NotNull Collection<?> c)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Specified by:
removeAllin interfaceUnmodCollection<E>
-
retainAll
@Deprecated default boolean retainAll(@NotNull @NotNull Collection<?> c)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceSet<E>- Specified by:
retainAllin interfaceUnmodCollection<E>
-
toArray
default Object @NotNull [] toArray()
This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations. If you really need an array, consider using the somewhat type-safe version of this method instead, but read the caveats first. This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations. If you really need an array, consider using the somewhat type-safe version of this method instead, but read the caveats first.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Specified by:
toArrayin interfaceUnmodCollection<E>
-
toArray
@NotNull default <T> @NotNull T @NotNull [] toArray(T @NotNull [] as)
This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations. If you need to create an array (you almost always do) then the best way to use this method is:MyThing[] things = col.toArray(new MyThing[coll.size()]);Calling this method any other way causes unnecessary work to be done - an extra memory allocation and potential garbage collection if the passed array is too small, extra effort to fill the end of the array with nulls if it is too large. This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations. If you need to create an array (you almost always do) then the best way to use this method is:MyThing[] things = col.toArray(new MyThing[coll.size()]);Calling this method any other way causes unnecessary work to be done - an extra memory allocation and potential garbage collection if the passed array is too small, extra effort to fill the end of the array with nulls if it is too large.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Specified by:
toArrayin interfaceUnmodCollection<E>
-
removeIf
@Deprecated default boolean removeIf(Predicate<? super E> filter)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removeIfin interfaceCollection<E>- Specified by:
removeIfin interfaceUnmodCollection<E>
-
-