--- a/jdk/src/java.base/share/classes/java/security/PermissionCollection.java Tue Jun 30 17:48:06 2015 -0700
+++ b/jdk/src/java.base/share/classes/java/security/PermissionCollection.java Tue Jun 09 07:10:02 2015 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,8 @@
package java.security;
import java.util.*;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
/**
* Abstract class representing a collection of Permission objects.
@@ -126,10 +128,35 @@
* Returns an enumeration of all the Permission objects in the collection.
*
* @return an enumeration of all the Permissions.
+ * @see #elementsAsStream()
*/
public abstract Enumeration<Permission> elements();
/**
+ * Returns a stream of all the Permission objects in the collection.
+ *
+ * <p> The collection should not be modified (see {@link #add}) during the
+ * execution of the terminal stream operation. Otherwise, the result of the
+ * terminal stream operation is undefined.
+ *
+ * @implSpec
+ * The default implementation creates a stream whose source is derived from
+ * the enumeration returned from a call to {@link #elements()}.
+ *
+ * @return a stream of all the Permissions.
+ * @since 1.9
+ */
+ public Stream<Permission> elementsAsStream() {
+ int characteristics = isReadOnly()
+ ? Spliterator.NONNULL | Spliterator.IMMUTABLE
+ : Spliterator.NONNULL;
+ return StreamSupport.stream(
+ Spliterators.spliteratorUnknownSize(
+ elements().asIterator(), characteristics),
+ false);
+ }
+
+ /**
* Marks this PermissionCollection object as "readonly". After
* a PermissionCollection object
* is marked as readonly, no new Permission objects can be added to it