127 /**
128 * Returns an enumeration of all the Permission objects in the collection.
129 *
130 * @return an enumeration of all the Permissions.
131 * @see #elementsAsStream()
132 */
133 public abstract Enumeration<Permission> elements();
134
135 /**
136 * Returns a stream of all the Permission objects in the collection.
137 *
138 * <p> The collection should not be modified (see {@link #add}) during the
139 * execution of the terminal stream operation. Otherwise, the result of the
140 * terminal stream operation is undefined.
141 *
142 * @implSpec
143 * The default implementation creates a stream whose source is derived from
144 * the enumeration returned from a call to {@link #elements()}.
145 *
146 * @return a stream of all the Permissions.
147 * @since 1.9
148 */
149 public Stream<Permission> elementsAsStream() {
150 int characteristics = isReadOnly()
151 ? Spliterator.NONNULL | Spliterator.IMMUTABLE
152 : Spliterator.NONNULL;
153 return StreamSupport.stream(
154 Spliterators.spliteratorUnknownSize(
155 elements().asIterator(), characteristics),
156 false);
157 }
158
159 /**
160 * Marks this PermissionCollection object as "readonly". After
161 * a PermissionCollection object
162 * is marked as readonly, no new Permission objects can be added to it
163 * using {@code add}.
164 */
165 public void setReadOnly() {
166 readOnly = true;
167 }
|
127 /**
128 * Returns an enumeration of all the Permission objects in the collection.
129 *
130 * @return an enumeration of all the Permissions.
131 * @see #elementsAsStream()
132 */
133 public abstract Enumeration<Permission> elements();
134
135 /**
136 * Returns a stream of all the Permission objects in the collection.
137 *
138 * <p> The collection should not be modified (see {@link #add}) during the
139 * execution of the terminal stream operation. Otherwise, the result of the
140 * terminal stream operation is undefined.
141 *
142 * @implSpec
143 * The default implementation creates a stream whose source is derived from
144 * the enumeration returned from a call to {@link #elements()}.
145 *
146 * @return a stream of all the Permissions.
147 * @since 9
148 */
149 public Stream<Permission> elementsAsStream() {
150 int characteristics = isReadOnly()
151 ? Spliterator.NONNULL | Spliterator.IMMUTABLE
152 : Spliterator.NONNULL;
153 return StreamSupport.stream(
154 Spliterators.spliteratorUnknownSize(
155 elements().asIterator(), characteristics),
156 false);
157 }
158
159 /**
160 * Marks this PermissionCollection object as "readonly". After
161 * a PermissionCollection object
162 * is marked as readonly, no new Permission objects can be added to it
163 * using {@code add}.
164 */
165 public void setReadOnly() {
166 readOnly = true;
167 }
|