ReplaceAll.java revision 2362
3863N/A/*
3863N/A * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
3863N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3863N/A *
3863N/A * This code is free software; you can redistribute it and/or modify it
3863N/A * under the terms of the GNU General Public License version 2 only, as
3863N/A * published by the Free Software Foundation.
3863N/A *
3863N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3863N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3863N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3863N/A * version 2 for more details (a copy is included in the LICENSE file that
3863N/A * accompanied this code).
3863N/A *
3863N/A * You should have received a copy of the GNU General Public License version
3863N/A * 2 along with this work; if not, write to the Free Software Foundation,
3863N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3863N/A *
3863N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3863N/A * or visit www.oracle.com if you need additional information or have any
3863N/A * questions.
3863N/A */
3863N/A
3863N/A/**
3863N/A * @test
3863N/A * @bug 4323074
3863N/A * @summary Basic test for new replaceAll algorithm
3863N/A */
3863N/A
3863N/Aimport java.util.*;
3863N/A
3863N/Apublic class ReplaceAll {
3863N/A static final int SIZE = 20;
3863N/A
3863N/A public static void main(String[] args) throws Exception {
3863N/A List a[] = {new ArrayList(), new LinkedList(), new Vector()};
3863N/A
3863N/A for (int i=0; i<a.length; i++) {
3863N/A List lst = a[i];
3863N/A for (int j=1; j<=SIZE; j++)
3863N/A lst.add(new Integer(j % 3));
3863N/A List goal = Collections.nCopies(SIZE, "*");
3863N/A
3863N/A for (int j=0; j<3; j++) {
3863N/A List before = new ArrayList(lst);
3863N/A if (!Collections.replaceAll(lst, new Integer(j), "*"))
3863N/A throw new Exception("False return value: "+i+", "+j);
3863N/A if (lst.equals(before))
3863N/A throw new Exception("Unchanged: "+i+", "+j+", "+": "+lst);
3863N/A if (lst.equals(goal) != (j==2))
3863N/A throw new Exception("Wrong change:"+i+", "+j);
3863N/A }
3863N/A if (Collections.replaceAll(lst, "love", "hate"))
3863N/A throw new Exception("True return value: "+i);
3863N/A }
3863N/A }
3863N/A}
3863N/A