test/tools/javac/util/list/TList.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 554
9d9f26857129
parent 0
959103a6100f
permissions
-rw-r--r--

merge

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

mercurial