Package Torello.Java.ReadOnly
Interface ReadOnlySet<E>
-
- Type Parameters:
E
- the type of elements maintained by this set
- All Superinterfaces:
java.lang.Iterable<E>
,ReadOnlyCollection<E>
- All Known Subinterfaces:
ReadOnlyNavigableSet<E>
,ReadOnlySequencedSet<E>
,ReadOnlySortedSet<E>
- All Known Implementing Classes:
ReadOnlyHashSet
,ReadOnlyTreeSet
public interface ReadOnlySet<E> extends ReadOnlyCollection<E>
This interface was originally copied fromGitHub's Open-JDK
Account. Though the original file has been modified, few changes have been applied to the Javadoc Commenting. Due to fact that that is a Javainterface
file, there were few method bodies with Source-Code to begin with - meaning this is largely a copy of Method-Signatures and Java-Doc Comments.
Method and parameter names & types have not been modified whatsoever; but several methods had to be eliminated for not being Read-Only. This Source-File was copied from the original Open JDK-21 file of the same (or, rather, highly similar) Interface-Name. The original file may be viewed on theJDK-21 GitHub
public (and, coincidentally, Read-Only) Source-Release archive for Java Packagejava.util.*
The Original'.java'
Source-File's Header-Copyright Information is included here:File Copyright
. Within that Copyright Notice, it is suggested that a copy of theGNU Public License V2
also be included alongside.Immutable variant of Java Collections Framework interfacejava.util.Set<E>
. This interface contains all of the methods that the standard Java interface ReadOnlySet contains - except those which would directly or indirectly modify / mutate the internal data-structure.
Hi-Lited Source-Code:- View Here: Torello/Java/ReadOnly/ReadOnlySet.java
- Open New Browser-Tab: Torello/Java/ReadOnly/ReadOnlySet.java
File Size: 20,831 Bytes Line Count: 471 '\n' Characters Found
-
-
Method Summary
Checking this Set's Contents Modifier and Type Method boolean
contains(Object o)
boolean
containsAll(Collection<?> c)
boolean
isEmpty()
int
size()
Convert this Set to an Array Modifier and Type Method Object[]
toArray()
<T> T[]
toArray(T[] a)
Static Methods: Builder's Modifier and Type Method static <E> ReadOnlySet<E>
copyOf(Collection<? extends E> coll)
static <E> ReadOnlySet<E>
of()
static <E> ReadOnlySet<E>
of(E e1)
static <E> ReadOnlySet<E>
of(E... elements)
static <E> ReadOnlySet<E>
of(E e1, E e2)
static <E> ReadOnlySet<E>
of(E e1, E e2, E e3)
static <E> ReadOnlySet<E>
of(E e1, E e2, E e3, E e4)
static <E> ReadOnlySet<E>
of(E e1, E e2, E e3, E e4, E e5)
static <E> ReadOnlySet<E>
of(E e1, E e2, E e3, E e4, E e5, E e6)
static <E> ReadOnlySet<E>
of(E e1, E e2, E e3, E e4, E e5, E e6, E e7)
static <E> ReadOnlySet<E>
of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8)
static <E> ReadOnlySet<E>
of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9)
static <E> ReadOnlySet<E>
of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10)
Default Methods (Interface Methods with a Concrete, Default Implementation) Modifier and Type Method default Spliterator<E>
spliterator()
Methods: class java.lang.Object Modifier and Type Method boolean
equals(Object o)
int
hashCode()
Methods: interface java.lang.Iterable Modifier and Type Method RemoveUnsupportedIterator<E>
iterator()
-
Methods inherited from interface Torello.Java.ReadOnly.ReadOnlyCollection
containsAND, containsAND, containsNAND, containsNAND, containsOR, containsOR, containsXOR, containsXOR, copyIntoCollection, parallelStream, stream, toArray
-
-
-
-
Method Detail
-
size
int size()
Returns the number of elements in this set (its cardinality). If this set contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.- Specified by:
size
in interfaceReadOnlyCollection<E>
- Returns:
- the number of elements in this set (its cardinality)
-
isEmpty
boolean isEmpty()
ReturnsTRUE
if this set contains no elements.- Specified by:
isEmpty
in interfaceReadOnlyCollection<E>
- Returns:
TRUE
if this set contains no elements
-
contains
boolean contains(java.lang.Object o)
ReturnsTRUE
if this set contains the specified element. More formally, returnsTRUE
if and only if this set contains an elemente
such thatObjects.equals(o, e)
.- Specified by:
contains
in interfaceReadOnlyCollection<E>
- Parameters:
o
- element whose presence in this set is to be tested- Returns:
TRUE
if this set contains the specified element- Throws:
java.lang.ClassCastException
- if the type of the specified element is incompatible with this set (optional)java.lang.NullPointerException
- if the specified element is null and this set does not permit null elements (optional)
-
iterator
RemoveUnsupportedIterator<E> iterator()
Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).- Specified by:
iterator
in interfacejava.lang.Iterable<E>
- Specified by:
iterator
in interfaceReadOnlyCollection<E>
- Returns:
- an iterator over the elements in this set
-
toArray
java.lang.Object[] toArray()
Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
The returned array will be "safe" in that no references to it are maintained by this set. (In other words, this method must allocate a new array even if this set is backed by an array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.- Specified by:
toArray
in interfaceReadOnlyCollection<E>
- Returns:
- an array containing all the elements in this set
-
toArray
<T> T[] toArray(T[] a)
Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set.
If this set fits in the specified array with room to spare (i.e., the array has more elements than this set), the element in the array immediately following the end of the set is set tonull
. (This is useful in determining the length of this set only if the caller knows that this set does not contain any null elements.)
If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
Like thetoArray()
method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.
Supposex
is a set known to contain only strings. The following code can be used to dump the set into a newly allocated array ofString
:String[] y = x.toArray(new String[0]);
Note thattoArray(new Object[0])
is identical in function totoArray()
.- Specified by:
toArray
in interfaceReadOnlyCollection<E>
- Type Parameters:
T
- the component type of the array to contain the collection- Parameters:
a
- the array into which the elements of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Returns:
- an array containing all the elements in this set
- Throws:
java.lang.ArrayStoreException
- if the runtime type of the specified array is not a supertype of the runtime type of every element in this setjava.lang.NullPointerException
- if the specified array is null
-
containsAll
boolean containsAll(java.util.Collection<?> c)
ReturnsTRUE
if this set contains all of the elements of the specified collection. If the specified collection is also a set, this method returnsTRUE
if it is a subset of this set.- Specified by:
containsAll
in interfaceReadOnlyCollection<E>
- Parameters:
c
- collection to be checked for containment in this set- Returns:
TRUE
if this set contains all of the elements of the specified collection- Throws:
java.lang.ClassCastException
- if the types of one or more elements in the specified collection are incompatible with this set (optional)java.lang.NullPointerException
- if the specified collection contains one or more null elements and this set does not permit null elements (optional), or if the specified collection is null- See Also:
contains(Object)
-
equals
boolean equals(java.lang.Object o)
Compares the specified object with this set for equality. ReturnsTRUE
if the specified object is also a set, the two sets have the same size, and every member of the specified set is contained in this set (or equivalently, every member of this set is contained in the specified set). This definition ensures that the equals method works properly across different implementations of the set interface.- Specified by:
equals
in interfaceReadOnlyCollection<E>
- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- object to be compared for equality with this set- Returns:
TRUE
if the specified object is equal to this set- See Also:
Object.equals(Object)
,equals(Object)
,ReadOnlyList.equals(Object)
-
hashCode
int hashCode()
Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hash code of anull
element is defined to be zero. This ensures thats1.equals(s2)
implies thats1.hashCode()==s2.hashCode()
for any two setss1
ands2
, as required by the general contract ofObject.hashCode
.- Specified by:
hashCode
in interfaceReadOnlyCollection<E>
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code value for this set
- See Also:
Object.equals(Object)
,Set.equals(Object)
-
spliterator
default java.util.Spliterator<E> spliterator()
Creates aSpliterator
over the elements in this set.
TheSpliterator
reportsSpliterator.DISTINCT
. Implementations should document the reporting of additional characteristic values.- Specified by:
spliterator
in interfacejava.lang.Iterable<E>
- Specified by:
spliterator
in interfaceReadOnlyCollection<E>
- Returns:
- a
Spliterator
over the elements in this set - Code:
- Exact Method Body:
return Spliterators.spliterator(this.iterator(), this.size(), Spliterator.DISTINCT);
-
of
static <E> ReadOnlySet<E> of()
Returns an unmodifiable set containing zero elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Returns:
- an empty
Set
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of());
-
of
static <E> ReadOnlySet<E> of(E e1)
Returns an unmodifiable set containing one element. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the single element- Returns:
- a
Set
containing the specified element - Throws:
java.lang.NullPointerException
- if the element isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(e1));
-
of
static <E> ReadOnlySet<E> of(E e1, E e2)
Returns an unmodifiable set containing two elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the first elemente2
- the second element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.IllegalArgumentException
- if the elements are duplicatesjava.lang.NullPointerException
- if an element isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(e1, e2));
-
of
static <E> ReadOnlySet<E> of(E e1, E e2, E e3)
Returns an unmodifiable set containing three elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.IllegalArgumentException
- if there are any duplicate elementsjava.lang.NullPointerException
- if an element isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(e1, e2, e3));
-
of
static <E> ReadOnlySet<E> of(E e1, E e2, E e3, E e4)
Returns an unmodifiable set containing four elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.IllegalArgumentException
- if there are any duplicate elementsjava.lang.NullPointerException
- if an element isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(e1, e2, e3, e4));
-
of
static <E> ReadOnlySet<E> of(E e1, E e2, E e3, E e4, E e5)
Returns an unmodifiable set containing five elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.IllegalArgumentException
- if there are any duplicate elementsjava.lang.NullPointerException
- if an element isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(e1, e2, e3, e4, e5));
-
of
static <E> ReadOnlySet<E> of(E e1, E e2, E e3, E e4, E e5, E e6)
Returns an unmodifiable set containing six elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth elemente6
- the sixth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.IllegalArgumentException
- if there are any duplicate elementsjava.lang.NullPointerException
- if an element isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(e1, e2, e3, e4, e5, e6));
-
of
static <E> ReadOnlySet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7)
Returns an unmodifiable set containing seven elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth elemente6
- the sixth elemente7
- the seventh element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.IllegalArgumentException
- if there are any duplicate elementsjava.lang.NullPointerException
- if an element isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(e1, e2, e3, e4, e5, e6, e7));
-
of
static <E> ReadOnlySet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8)
Returns an unmodifiable set containing eight elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth elemente6
- the sixth elemente7
- the seventh elemente8
- the eighth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.IllegalArgumentException
- if there are any duplicate elementsjava.lang.NullPointerException
- if an element isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(e1, e2, e3, e4, e5, e6, e7, e8));
-
of
static <E> ReadOnlySet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9)
Returns an unmodifiable set containing nine elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth elemente6
- the sixth elemente7
- the seventh elemente8
- the eighth elemente9
- the ninth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.IllegalArgumentException
- if there are any duplicate elementsjava.lang.NullPointerException
- if an element isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(e1, e2, e3, e4, e5, e6, e7, e8, e9));
-
of
static <E> ReadOnlySet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10)
Returns an unmodifiable set containing ten elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
e1
- the first elemente2
- the second elemente3
- the third elemente4
- the fourth elemente5
- the fifth elemente6
- the sixth elemente7
- the seventh elemente8
- the eighth elemente9
- the ninth elemente10
- the tenth element- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.IllegalArgumentException
- if there are any duplicate elementsjava.lang.NullPointerException
- if an element isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10));
-
of
@SafeVarargs static <E> ReadOnlySet<E> of(E... elements)
Returns an unmodifiable set containing an arbitrary number of elements. See Unmodifiable Sets for details.- Type Parameters:
E
- theSet
's element type- Parameters:
elements
- the elements to be contained in the set- Returns:
- a
Set
containing the specified elements - Throws:
java.lang.IllegalArgumentException
- if there are any duplicate elementsjava.lang.NullPointerException
- if an element isnull
or if the array isnull
- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.of(elements));
-
copyOf
static <E> ReadOnlySet<E> copyOf(java.util.Collection<? extends E> coll)
Returns an unmodifiable Set containing the elements of the given Collection. The given Collection must not be null, and it must not contain any null elements. If the given Collection contains duplicate elements, an arbitrary element of the duplicates is preserved. If the given Collection is subsequently modified, the returned Set will not reflect such modifications.- Type Parameters:
E
- theSet
's element type- Parameters:
coll
- aCollection
from which elements are drawn, must be non-null- Returns:
- a
Set
containing the elements of the givenCollection
- Throws:
java.lang.NullPointerException
- if coll is null, or if it contains any nulls- Code:
- Exact Method Body:
return InterfaceBuilder.toReadOnlySet(Set.copyOf(coll));
-
-