< prev index next >

src/java.base/share/classes/java/lang/module/Configuration.java

Print this page
rev 51700 : [mq]: 8210347-Combine-subsequent-calls-to-Set-contains-and-Set-add


 584      * in DFS order.
 585      *
 586      * @implNote For now, the assumption is that the number of elements will
 587      * be very low and so this method does not use a specialized spliterator.
 588      */
 589     Stream<Configuration> configurations() {
 590         List<Configuration> allConfigurations = this.allConfigurations;
 591         if (allConfigurations == null) {
 592             allConfigurations = new ArrayList<>();
 593             Set<Configuration> visited = new HashSet<>();
 594             Deque<Configuration> stack = new ArrayDeque<>();
 595             visited.add(this);
 596             stack.push(this);
 597             while (!stack.isEmpty()) {
 598                 Configuration layer = stack.pop();
 599                 allConfigurations.add(layer);
 600 
 601                 // push in reverse order
 602                 for (int i = layer.parents.size() - 1; i >= 0; i--) {
 603                     Configuration parent = layer.parents.get(i);
 604                     if (!visited.contains(parent)) {
 605                         visited.add(parent);
 606                         stack.push(parent);
 607                     }
 608                 }
 609             }
 610             this.allConfigurations = allConfigurations; // no need to do defensive copy
 611         }
 612         return allConfigurations.stream();
 613     }
 614 
 615     private volatile List<Configuration> allConfigurations;
 616 
 617 
 618     /**
 619      * Returns a string describing this configuration.
 620      *
 621      * @return A possibly empty string describing this configuration
 622      */
 623     @Override
 624     public String toString() {
 625         return modules().stream()


 584      * in DFS order.
 585      *
 586      * @implNote For now, the assumption is that the number of elements will
 587      * be very low and so this method does not use a specialized spliterator.
 588      */
 589     Stream<Configuration> configurations() {
 590         List<Configuration> allConfigurations = this.allConfigurations;
 591         if (allConfigurations == null) {
 592             allConfigurations = new ArrayList<>();
 593             Set<Configuration> visited = new HashSet<>();
 594             Deque<Configuration> stack = new ArrayDeque<>();
 595             visited.add(this);
 596             stack.push(this);
 597             while (!stack.isEmpty()) {
 598                 Configuration layer = stack.pop();
 599                 allConfigurations.add(layer);
 600 
 601                 // push in reverse order
 602                 for (int i = layer.parents.size() - 1; i >= 0; i--) {
 603                     Configuration parent = layer.parents.get(i);
 604                     if (visited.add(parent)) {

 605                         stack.push(parent);
 606                     }
 607                 }
 608             }
 609             this.allConfigurations = allConfigurations; // no need to do defensive copy
 610         }
 611         return allConfigurations.stream();
 612     }
 613 
 614     private volatile List<Configuration> allConfigurations;
 615 
 616 
 617     /**
 618      * Returns a string describing this configuration.
 619      *
 620      * @return A possibly empty string describing this configuration
 621      */
 622     @Override
 623     public String toString() {
 624         return modules().stream()
< prev index next >