jdk/test/jdk/lambda/shapegen/TTShape.java
changeset 29748 9ad0fcf27b36
parent 29659 f40752db7773
parent 29747 0ab8f74c7f13
child 29749 68def6418e33
child 29815 a50c9d80a80f
child 29899 a660cade22ce
equal deleted inserted replaced
29659:f40752db7773 29748:9ad0fcf27b36
     1 /*
       
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     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
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 package shapegen;
       
    25 
       
    26 import java.util.ArrayList;
       
    27 import java.util.HashSet;
       
    28 import java.util.List;
       
    29 import java.util.Set;
       
    30 
       
    31 /**
       
    32  *
       
    33  * @author Robert Field
       
    34  */
       
    35 public class TTShape {
       
    36 
       
    37     private final TTNode root;
       
    38     private final TTNode[] nodes;
       
    39 
       
    40     TTShape(TTNode root) {
       
    41         this.root = root;
       
    42         Set<TTNode> subs = new HashSet<>();
       
    43         root.collectAllSubtypes(subs);
       
    44         nodes = subs.toArray(new TTNode[subs.size()]);
       
    45     }
       
    46 
       
    47     private List<ClassCase> toCases(boolean includeClasses) {
       
    48         List<ClassCase> ccs = new ArrayList<>();
       
    49         root.start(includeClasses);
       
    50         int i;
       
    51         outer:
       
    52         while (true) {
       
    53             if (root.isValid()) {
       
    54                 ClassCase cc = root.genCase();
       
    55                 //System.out.println(cc);
       
    56                 ccs.add(cc);
       
    57             }
       
    58 
       
    59             i = 0;
       
    60             do {
       
    61                 if (i >= nodes.length) {
       
    62                     break outer;
       
    63                 }
       
    64             } while(!nodes[i++].next());
       
    65         }
       
    66         return ccs;
       
    67     }
       
    68 
       
    69    public static List<ClassCase> allCases(boolean includeClasses) {
       
    70         List<ClassCase> ccs = new ArrayList<>();
       
    71         for (TTShape shape : SHAPES) {
       
    72             ccs.addAll(shape.toCases(includeClasses));
       
    73         }
       
    74         return ccs;
       
    75     }
       
    76 
       
    77     public static TTShape parse(String s) {
       
    78         return new TTShape(new TTParser(s).parse());
       
    79     }
       
    80 
       
    81     public static final TTShape[] SHAPES = new TTShape[] {
       
    82         parse("a"),
       
    83         parse("a(b)"),
       
    84         parse("A(bb)"),
       
    85         parse("A(B(d)c(d))"),
       
    86         parse("A(b(c))"),
       
    87         parse("A(B(cd)d)"),
       
    88         parse("A(B(c)c)"),
       
    89         parse("A(B(Ce)d(e))"),
       
    90         parse("A(B(C)d(e))"),
       
    91         parse("A(Bc(d))"),
       
    92         parse("A(B(d)dc)"),
       
    93         parse("A(B(dc)dc)"),
       
    94         parse("A(B(c(d))d)"),
       
    95         parse("A(B(C(d))d)"),
       
    96         parse("A(B(C(e)d(e))e)"),
       
    97         parse("A(B(c(d))c)"),
       
    98         parse("A(B(dc(d))c)"),
       
    99         parse("A(B(C(d))d)"),
       
   100     };
       
   101 
       
   102 }