langtools/test/tools/javac/util/list/TList.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 5520 86e4b9a9da40
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 5520
diff changeset
     2
 * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
 * @test
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
 * @bug 6267067 6351336 6389198
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @summary unit test for javac List
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 5520
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.util
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
public class TList {
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
    public static void main(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
        new TList().run();
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
    String[][] data = {
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
        { },
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
        { "1" },
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
        { "1", "2" },
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
        { "1", "2" }, // different but equal
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
        { "1", "2", "3", "4", "X", "X", "X", "8", "9", "10" } // contains duplicates
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    Map<java.util.List<String>,List<String>> examples;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    void run() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
        examples = new LinkedHashMap<java.util.List<String>,List<String>>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
        for (String[] values: data)
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
            examples.put(Arrays.asList(values), createList(values));
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        // 6351336: com.sun.tools.javac.util.List shouldn't extend java.util.AbstractList
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
        test_AbstractList();
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        // general unit tests for java.util.List methods, including...
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        // 6389198: com.sun.tools.javac.util.List.equals() violates java.util.List.equals() contract
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        test_add_E();
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
        test_add_int_E();
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        test_addAll_Collection();
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        test_addAll_int_Collection();
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        test_clear();
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        test_contains_Object();
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        test_contains_All();
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        test_equals_Object();
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        test_get_int();
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        test_hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        test_indexOf_Object();
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        test_isEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        test_iterator();
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        test_lastIndexOf_Object();
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        test_listIterator();
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        test_listIterator_int();
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        test_remove_int();
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        test_remove_Object();
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        test_removeAll_Collection();
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        test_retainAll_Collection();
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        test_set_int_E();
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        test_size();
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        test_subList_int_int();
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        test_toArray();
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        test_toArray_TArray();
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        // tests for additional methods
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        test_prependList_List();
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        test_reverse();
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    // 6351336
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    void test_AbstractList() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        System.err.println("test AbstractList");
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        if (AbstractList.class.isAssignableFrom(List.class))
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    void test_add_E() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        System.err.println("test add(E)");
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        for (List<String> l: examples.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                l.add("test");
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            } catch (UnsupportedOperationException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    void test_add_int_E() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        System.err.println("test add(int,E)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        for (List<String> l: examples.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
                l.add(0, "test");
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
            } catch (UnsupportedOperationException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    void test_addAll_Collection() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        System.err.println("test addAll(Collection)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        for (List<String> l: examples.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
            int l_size = l.size();
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
            for (java.util.List<String> arg: examples.keySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                    boolean modified = l.addAll(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
                    if (modified)
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
                        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
                } catch (UnsupportedOperationException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                if (l.size() != l_size)
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    void test_addAll_int_Collection() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        System.err.println("test addAll(int,Collection)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        for (List<String> l: examples.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            int l_size = l.size();
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            for (java.util.List<String> arg: examples.keySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
                    boolean modified = l.addAll(0, arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                    if (modified)
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
                        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
                } catch (UnsupportedOperationException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                if (l.size() != l_size)
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    void test_clear() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        System.err.println("test clear()");
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        for (List<String> l: examples.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
            int l_size = l.size();
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                l.clear();
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                if (l_size > 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
            } catch (UnsupportedOperationException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
            if (l.size() != l_size)
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    void test_contains_Object() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        System.err.println("test contains(Object)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
            boolean expect = ref.contains("1");
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
            boolean found = l.contains("1");
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            if (expect != found)
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    void test_contains_All() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        System.err.println("test containsAll()");
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
            for (java.util.List<String> arg: examples.keySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                boolean expect = ref.containsAll(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
                boolean found = l.containsAll(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
                if (expect != found)
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    // 6389198
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    void test_equals_Object() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        System.err.println("test equals(Object)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
            for (java.util.List<String> arg: examples.keySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
                boolean expect = ref.equals(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
                boolean found = l.equals(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
                if (expect != found) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
                    System.err.println("ref: " + ref);
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
                    System.err.println("l: " + l);
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
                    System.err.println("arg: " + arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
                    System.err.println("expect: " + expect + ", found: " + found);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    void test_get_int() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        System.err.println("test get(int)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            for (int i = -1; i <= ref.size(); i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
                boolean expectException = i < 0 || i >= ref.size();
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                String expectValue = (expectException ? null : ref.get(i));
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                    String foundValue = l.get(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
                    if (expectException || !equal(expectValue, foundValue))
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
                } catch (IndexOutOfBoundsException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
                    if (!expectException)
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
                        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    void test_hashCode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        System.err.println("test hashCode()");
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            long expect = ref.hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            long found = l.hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            if (expect != found) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
                System.err.println("ref: " + ref);
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                System.err.println("l: " + l);
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                System.err.println("expect: " + expect);
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
                System.err.println("found: " + found);
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    void test_indexOf_Object() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        System.err.println("test indexOf(Object)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
            for (int i = -1; i < ref.size(); i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
                String arg = (i == -1 ? "NOT IN LIST" : ref.get(i));
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
                int expect = ref.indexOf(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                int found = l.indexOf(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                if (expect != found)
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    void test_isEmpty() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        System.err.println("test isEmpty()");
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
            boolean expect = ref.isEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
            boolean found = l.isEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
            if (expect != found)
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    void test_iterator() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        System.err.println("test iterator()");
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
            if (!equal(l.iterator(), ref.iterator()))
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    void test_lastIndexOf_Object() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        System.err.println("test lastIndexOf(Object)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
            for (int i = -1; i < ref.size(); i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
                String arg = (i == -1 ? "NOT IN LIST" : ref.get(i));
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
                int expect = ref.lastIndexOf(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
                int found = l.lastIndexOf(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
                if (expect != found)
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    void test_listIterator() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        System.err.println("test listIterator()");
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
            if (!equal(l.listIterator(), ref.listIterator()))
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
    void test_listIterator_int() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        System.err.println("test listIterator(int)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
            for (int i = 0; i < ref.size(); i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
                if (!equal(l.listIterator(i), ref.listIterator(i)))
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    void test_remove_int() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        System.err.println("test remove(int)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
        for (List<String> l: examples.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                l.remove(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            } catch (UnsupportedOperationException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    void test_remove_Object() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        System.err.println("test remove(Object)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        for (List<String> l: examples.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            boolean hasX = l.contains("X");
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                l.remove("X");
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                if (hasX)
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            } catch (UnsupportedOperationException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
    void test_removeAll_Collection() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        System.err.println("test removeAll(Collection)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        for (List<String> l: examples.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
            int l_size = l.size();
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
            for (java.util.List<String> arg: examples.keySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
                    boolean modified = l.removeAll(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
                    if (modified)
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
                        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                } catch (UnsupportedOperationException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                if (l.size() != l_size)
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    void test_retainAll_Collection() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        System.err.println("test retainAll(Collection)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        for (List<String> l: examples.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
            int l_size = l.size();
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
            for (java.util.List<String> arg: examples.keySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
                    boolean modified = l.retainAll(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
                    if (modified)
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
                        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
                } catch (UnsupportedOperationException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
                if (l.size() != l_size)
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
    void test_set_int_E() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        System.err.println("test set(int,E)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        for (List<String> l: examples.values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
                l.set(0, "X");
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            } catch (UnsupportedOperationException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
    void test_size() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        System.err.println("test size()");
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
            int  expect = ref.size();
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            int found = l.size();
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
            if (expect != found)
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    void test_subList_int_int() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
        System.err.println("test subList(int,int)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
            for (int lwb = 0; lwb < ref.size(); lwb++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
                for (int upb = lwb; upb <= ref.size(); upb++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
                    if (!equal(l.subList(lwb, upb), ref.subList(lwb,upb)))
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
    void test_toArray() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        System.err.println("test toArray()");
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            if (!equal(l.toArray(), ref.toArray()))
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
    void test_toArray_TArray() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
        System.err.println("test toArray(E[])");
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
            if (!equal(l.toArray(new String[0]), ref.toArray(new String[0])))
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
    void test_prependList_List() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        System.err.println("test prependList(List<E>)");
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
            for (Map.Entry<java.util.List<String>, List<String>> arg_e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
                java.util.List<String> arg_ref = arg_e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
                List<String> arg = arg_e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
                java.util.List<String> expect = join(arg, ref);
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
                List<String> found = l.prependList(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
                // verify results, and that original and arg lists are unchanged
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
                if (!equal(expect, found)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
                    System.err.println("ref: " + ref);
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
                    System.err.println("l: " + l);
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
                    System.err.println("arg: " + arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
                    System.err.println("expect: " + expect);
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
                    System.err.println("found: " + found);
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
                if (!equal(l, ref))
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
                if (!equal(arg, arg_ref))
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
                    throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
    void test_reverse() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
        System.err.println("test reverse()");
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
        for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
            java.util.List<String> ref = e.getKey();
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
            List<String> l = e.getValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
            java.util.List<String> expect = reverse(ref);
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
            List<String> found = l.reverse();
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
            if (l.size() < 2 && found != l)  // reverse of empty or singleton list is itself
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
            if (!equal(l, ref)) // orginal should be unchanged
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
            if (!equal(expect, found))
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
    static <T> com.sun.tools.javac.util.List<T> createList(List<T> d) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        com.sun.tools.javac.util.List<T> l = com.sun.tools.javac.util.List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        for (ListIterator<T> iter = d.listIterator(d.size()); iter.hasPrevious(); )
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
            l = l.prepend(iter.previous());
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        return l;
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
    static <T> com.sun.tools.javac.util.List<T> createList(T... d) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        com.sun.tools.javac.util.List<T> l = com.sun.tools.javac.util.List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        for (int i = d.length - 1; i >= 0; i--)
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
            l = l.prepend(d[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
        return l;
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
    static <T> boolean equal(T t1, T t2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
        return (t1 == null ? t2 == null : t1.equals(t2));
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
    static <T> boolean equal(Iterator<T> iter1, Iterator<T> iter2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        if (iter1 == null || iter2 == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
            return (iter1 == iter2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
        while (iter1.hasNext() && iter2.hasNext()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
            if (!equal(iter1.next(), iter2.next()))
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
        return (!iter1.hasNext() && !iter2.hasNext());
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
    static <T> boolean equal(ListIterator<T> iter1, ListIterator<T> iter2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
        if (iter1 == null || iter2 == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
            return (iter1 == iter2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        if (iter1.previousIndex() != iter2.previousIndex())
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        while (iter1.hasPrevious() && iter2.hasPrevious()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
            iter1.previous();
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
            iter2.previous();
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
        return equal((Iterator<T>) iter1, (Iterator<T>) iter2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
    static <T> boolean equal(T[] a1, T[] a2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
        if (a1 == null || a2 == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
            return (a1 == a2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
        if (a1.length != a2.length)
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
        for (int i = 0; i < a1.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            if (!equal(a1[i], a2[i]))
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
    static <T> java.util.List<T> join(java.util.List<T>... lists) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
        java.util.List<T> r = new ArrayList<T>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
        for (java.util.List<T> l: lists)
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
            r.addAll(l);
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
    static <T> java.util.List<T> reverse(java.util.List<T> l) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        java.util.List<T> r = new ArrayList<T>(l.size());
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
        for (T t: l)
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
            r.add(0, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
        return r;
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
}