jdk/src/java.base/share/classes/java/security/PermissionCollection.java
changeset 31469 92cc72d2a11a
parent 25859 3317bb8137f4
child 35302 e4d2275861c3
equal deleted inserted replaced
31468:6cd3ae8de51c 31469:92cc72d2a11a
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    24  */
    24  */
    25 
    25 
    26 package java.security;
    26 package java.security;
    27 
    27 
    28 import java.util.*;
    28 import java.util.*;
       
    29 import java.util.stream.Stream;
       
    30 import java.util.stream.StreamSupport;
    29 
    31 
    30 /**
    32 /**
    31  * Abstract class representing a collection of Permission objects.
    33  * Abstract class representing a collection of Permission objects.
    32  *
    34  *
    33  * <p>With a PermissionCollection, you can:
    35  * <p>With a PermissionCollection, you can:
   124 
   126 
   125     /**
   127     /**
   126      * Returns an enumeration of all the Permission objects in the collection.
   128      * Returns an enumeration of all the Permission objects in the collection.
   127      *
   129      *
   128      * @return an enumeration of all the Permissions.
   130      * @return an enumeration of all the Permissions.
       
   131      * @see #elementsAsStream()
   129      */
   132      */
   130     public abstract Enumeration<Permission> elements();
   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     }
   131 
   158 
   132     /**
   159     /**
   133      * Marks this PermissionCollection object as "readonly". After
   160      * Marks this PermissionCollection object as "readonly". After
   134      * a PermissionCollection object
   161      * a PermissionCollection object
   135      * is marked as readonly, no new Permission objects can be added to it
   162      * is marked as readonly, no new Permission objects can be added to it