ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collections/FindSubList.java
Revision: 1.4
Committed: Sun Oct 22 02:59:18 2017 UTC (6 years, 6 months ago) by jsr166
Branch: MAIN
Changes since 1.3: +14 -6 lines
Log Message:
fix errorprone [MixedArrayDimensions] warnings

File Contents

# User Rev Content
1 jsr166 1.1 /*
2 jsr166 1.2 * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
3 jsr166 1.1 * 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 jsr166 1.2 * 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 jsr166 1.1 */
23    
24 jsr166 1.3 /*
25 jsr166 1.1 * @test
26     * @bug 4323074
27     * @summary Basic test for Collections.indexOfSubList/lastIndexOfSubList
28     */
29    
30     import java.util.*;
31    
32     public class FindSubList {
33     public static void main(String[] args) throws Exception {
34     int N = 500;
35     List source = new ArrayList(3 * N);
36 jsr166 1.4 List[] target = new List[N+1];
37     int[] index = new int[N+1];
38 jsr166 1.1 for (int i=0; i<=N; i++) {
39     List t = new ArrayList();
40     String s = Integer.toString(i, 2);
41     for (int j=0, len = s.length(); j<len; j++)
42     t.add(s.charAt(j)=='1' ? "1" : "0");
43     target[i] = t;
44     if (i == N) {
45     index[i] = -1;
46     } else {
47     index[i] = source.size();
48     source.addAll(t);
49     source.add("*");
50     }
51     }
52    
53 jsr166 1.4 List[] src = {
54     source,
55     new LinkedList(source),
56     new Vector(source),
57     Arrays.asList(source.toArray())
58     };
59 jsr166 1.1 for (int j=0; j<src.length; j++) {
60     List s = src[j];
61    
62     for (int i=0; i<=N; i++) {
63     int idx = Collections.indexOfSubList(s, target[i]);
64     if (idx != index[i])
65     throw new Exception(s.getClass()+" indexOfSubList: " + i +
66     "is " + idx + ", should be "+index[i]);
67     }
68    
69     if (Collections.indexOfSubList(s,Collections.nCopies(2*s.size(),
70     "0")) != -1)
71     throw new Exception(s.getClass()+" indexOfSubList: big target");
72    
73     }
74    
75     Collections.reverse(source);
76     int srcSize = source.size();
77     for (int i=0; i<=N; i++) {
78     Collections.reverse(target[i]);
79     if (i != N)
80     index[i] = srcSize - index[i] - target[i].size();
81     }
82 jsr166 1.4 List[] src2 = {
83     source,
84     new LinkedList(source),
85     new Vector(source),
86     Arrays.asList(source.toArray())
87     };
88 jsr166 1.1 for (int j=0; j<src2.length; j++) {
89     List s = src2[j];
90    
91     for (int i=0; i<=N; i++) {
92     int idx = Collections.lastIndexOfSubList(s, target[i]);
93     if (idx != index[i])
94     throw new Exception(s.getClass()+" lastIdexOfSubList: "+i +
95     "is " + idx + ", should be "+index[i]);
96     }
97     if (Collections.indexOfSubList(s,Collections.nCopies(2*s.size(),
98     "0")) != -1)
99     throw new Exception(s.getClass()+" lastIndexOfSubList: big tgt");
100     }
101     }
102     }