Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Collections/FindSubList.java
38812 views
/*1* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 432307426* @summary Basic test for Collections.indexOfSubList/lastIndexOfSubList27*/2829import java.util.*;3031public class FindSubList {32public static void main(String[] args) throws Exception {33int N = 500;34List source = new ArrayList(3 * N);35List target[]= new List[N+1];36int index[] = new int[N+1];37for (int i=0; i<=N; i++) {38List t = new ArrayList();39String s = Integer.toString(i, 2);40for (int j=0, len = s.length(); j<len; j++)41t.add(s.charAt(j)=='1' ? "1" : "0");42target[i] = t;43if (i == N) {44index[i] = -1;45} else {46index[i] = source.size();47source.addAll(t);48source.add("*");49}50}5152List src[] = {source, new LinkedList(source), new Vector(source),53Arrays.asList(source.toArray())};54for (int j=0; j<src.length; j++) {55List s = src[j];5657for (int i=0; i<=N; i++) {58int idx = Collections.indexOfSubList(s, target[i]);59if (idx != index[i])60throw new Exception(s.getClass()+" indexOfSubList: " + i +61"is " + idx + ", should be "+index[i]);62}6364if (Collections.indexOfSubList(s,Collections.nCopies(2*s.size(),65"0")) != -1)66throw new Exception(s.getClass()+" indexOfSubList: big target");6768}6970Collections.reverse(source);71int srcSize = source.size();72for (int i=0; i<=N; i++) {73Collections.reverse(target[i]);74if (i != N)75index[i] = srcSize - index[i] - target[i].size();76}77List src2[] = {source, new LinkedList(source), new Vector(source),78Arrays.asList(source.toArray())};79for (int j=0; j<src2.length; j++) {80List s = src2[j];8182for (int i=0; i<=N; i++) {83int idx = Collections.lastIndexOfSubList(s, target[i]);84if (idx != index[i])85throw new Exception(s.getClass()+" lastIdexOfSubList: "+i +86"is " + idx + ", should be "+index[i]);87}88if (Collections.indexOfSubList(s,Collections.nCopies(2*s.size(),89"0")) != -1)90throw new Exception(s.getClass()+" lastIndexOfSubList: big tgt");91}92}93}949596