1 /* 2 * Copyright (C) 2017 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.common.primitives; 16 17 import static com.google.common.primitives.TestPlatform.reduceIterationsIfGwt; 18 import static com.google.common.testing.SerializableTester.reserialize; 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.google.common.annotations.GwtCompatible; 22 import com.google.common.annotations.GwtIncompatible; 23 import com.google.common.collect.ImmutableList; 24 import com.google.common.collect.ObjectArrays; 25 import com.google.common.collect.testing.ListTestSuiteBuilder; 26 import com.google.common.collect.testing.SampleElements; 27 import com.google.common.collect.testing.TestListGenerator; 28 import com.google.common.collect.testing.features.CollectionFeature; 29 import com.google.common.collect.testing.features.CollectionSize; 30 import com.google.common.testing.EqualsTester; 31 import java.util.ArrayList; 32 import java.util.Arrays; 33 import java.util.Collection; 34 import java.util.Collections; 35 import java.util.Iterator; 36 import java.util.List; 37 import java.util.Random; 38 import java.util.concurrent.atomic.AtomicLong; 39 import java.util.stream.LongStream; 40 import junit.framework.Test; 41 import junit.framework.TestCase; 42 import junit.framework.TestSuite; 43 44 /** @author Kevin Bourrillion */ 45 @GwtCompatible(emulated = true) 46 public class ImmutableLongArrayTest extends TestCase { 47 // Test all creation paths very lazily: by assuming asList() works 48 testOf0()49 public void testOf0() { 50 assertThat(ImmutableLongArray.of().asList()).isEmpty(); 51 } 52 testOf1()53 public void testOf1() { 54 assertThat(ImmutableLongArray.of(0).asList()).containsExactly(0L); 55 } 56 testOf2()57 public void testOf2() { 58 assertThat(ImmutableLongArray.of(0, 1).asList()).containsExactly(0L, 1L).inOrder(); 59 } 60 testOf3()61 public void testOf3() { 62 assertThat(ImmutableLongArray.of(0, 1, 3).asList()).containsExactly(0L, 1L, 3L).inOrder(); 63 } 64 testOf4()65 public void testOf4() { 66 assertThat(ImmutableLongArray.of(0, 1, 3, 6).asList()) 67 .containsExactly(0L, 1L, 3L, 6L) 68 .inOrder(); 69 } 70 testOf5()71 public void testOf5() { 72 assertThat(ImmutableLongArray.of(0, 1, 3, 6, 10).asList()) 73 .containsExactly(0L, 1L, 3L, 6L, 10L) 74 .inOrder(); 75 } 76 testOf6()77 public void testOf6() { 78 assertThat(ImmutableLongArray.of(0, 1, 3, 6, 10, 15).asList()) 79 .containsExactly(0L, 1L, 3L, 6L, 10L, 15L) 80 .inOrder(); 81 } 82 testOf7()83 public void testOf7() { 84 assertThat(ImmutableLongArray.of(0, 1, 3, 6, 10, 15, 21).asList()) 85 .containsExactly(0L, 1L, 3L, 6L, 10L, 15L, 21L) 86 .inOrder(); 87 } 88 testCopyOf_array_empty()89 public void testCopyOf_array_empty() { 90 /* 91 * We don't guarantee the same-as property, so we aren't obligated to test it. However, it's 92 * useful in testing - when two things are the same then one can't have bugs the other doesn't. 93 */ 94 assertThat(ImmutableLongArray.copyOf(new long[0])).isSameInstanceAs(ImmutableLongArray.of()); 95 } 96 testCopyOf_array_nonempty()97 public void testCopyOf_array_nonempty() { 98 long[] array = new long[] {0, 1, 3}; 99 ImmutableLongArray iia = ImmutableLongArray.copyOf(array); 100 array[2] = 2; 101 assertThat(iia.asList()).containsExactly(0L, 1L, 3L).inOrder(); 102 } 103 testCopyOf_iterable_notCollection_empty()104 public void testCopyOf_iterable_notCollection_empty() { 105 Iterable<Long> iterable = iterable(Collections.<Long>emptySet()); 106 assertThat(ImmutableLongArray.copyOf(iterable)).isSameInstanceAs(ImmutableLongArray.of()); 107 } 108 testCopyOf_iterable_notCollection_nonempty()109 public void testCopyOf_iterable_notCollection_nonempty() { 110 List<Long> list = Arrays.asList(0L, 1L, 3L); 111 ImmutableLongArray iia = ImmutableLongArray.copyOf(iterable(list)); 112 list.set(2, 2L); 113 assertThat(iia.asList()).containsExactly(0L, 1L, 3L).inOrder(); 114 } 115 testCopyOf_iterable_collection_empty()116 public void testCopyOf_iterable_collection_empty() { 117 Iterable<Long> iterable = Collections.emptySet(); 118 assertThat(ImmutableLongArray.copyOf(iterable)).isSameInstanceAs(ImmutableLongArray.of()); 119 } 120 testCopyOf_iterable_collection_nonempty()121 public void testCopyOf_iterable_collection_nonempty() { 122 List<Long> list = Arrays.asList(0L, 1L, 3L); 123 ImmutableLongArray iia = ImmutableLongArray.copyOf((Iterable<Long>) list); 124 list.set(2, 2L); 125 assertThat(iia.asList()).containsExactly(0L, 1L, 3L).inOrder(); 126 } 127 testCopyOf_collection_empty()128 public void testCopyOf_collection_empty() { 129 Collection<Long> iterable = Collections.emptySet(); 130 assertThat(ImmutableLongArray.copyOf(iterable)).isSameInstanceAs(ImmutableLongArray.of()); 131 } 132 testCopyOf_collection_nonempty()133 public void testCopyOf_collection_nonempty() { 134 List<Long> list = Arrays.asList(0L, 1L, 3L); 135 ImmutableLongArray iia = ImmutableLongArray.copyOf(list); 136 list.set(2, 2L); 137 assertThat(iia.asList()).containsExactly(0L, 1L, 3L).inOrder(); 138 } 139 testCopyOf_stream()140 public void testCopyOf_stream() { 141 assertThat(ImmutableLongArray.copyOf(LongStream.empty())) 142 .isSameInstanceAs(ImmutableLongArray.of()); 143 assertThat(ImmutableLongArray.copyOf(LongStream.of(0, 1, 3)).asList()) 144 .containsExactly(0L, 1L, 3L) 145 .inOrder(); 146 } 147 testBuilder_presize_zero()148 public void testBuilder_presize_zero() { 149 ImmutableLongArray.Builder builder = ImmutableLongArray.builder(0); 150 builder.add(5L); 151 ImmutableLongArray array = builder.build(); 152 assertThat(array.asList()).containsExactly(5L); 153 } 154 testBuilder_presize_negative()155 public void testBuilder_presize_negative() { 156 try { 157 ImmutableLongArray.builder(-1); 158 fail(); 159 } catch (IllegalArgumentException expected) { 160 } 161 } 162 163 /** 164 * If there's a bug in builder growth, we wouldn't know how to expose it. So, brute force the hell 165 * out of it for a while and see what happens. 166 */ testBuilder_bruteForce()167 public void testBuilder_bruteForce() { 168 for (int i = 0; i < reduceIterationsIfGwt(100); i++) { 169 ImmutableLongArray.Builder builder = ImmutableLongArray.builder(RANDOM.nextInt(20)); 170 AtomicLong counter = new AtomicLong(0); 171 while (counter.get() < 1000) { 172 BuilderOp op = BuilderOp.randomOp(); 173 op.doIt(builder, counter); 174 } 175 ImmutableLongArray iia = builder.build(); 176 for (int j = 0; j < iia.length(); j++) { 177 assertThat(iia.get(j)).isEqualTo((long) j); 178 } 179 } 180 } 181 182 private enum BuilderOp { 183 ADD_ONE { 184 @Override doIt(ImmutableLongArray.Builder builder, AtomicLong counter)185 void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { 186 builder.add(counter.getAndIncrement()); 187 } 188 }, 189 ADD_ARRAY { 190 @Override doIt(ImmutableLongArray.Builder builder, AtomicLong counter)191 void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { 192 long[] array = new long[RANDOM.nextInt(10)]; 193 for (int i = 0; i < array.length; i++) { 194 array[i] = counter.getAndIncrement(); 195 } 196 builder.addAll(array); 197 } 198 }, 199 ADD_COLLECTION { 200 @Override doIt(ImmutableLongArray.Builder builder, AtomicLong counter)201 void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { 202 List<Long> list = new ArrayList<>(); 203 long num = RANDOM.nextInt(10); 204 for (int i = 0; i < num; i++) { 205 list.add(counter.getAndIncrement()); 206 } 207 builder.addAll(list); 208 } 209 }, 210 ADD_ITERABLE { 211 @Override doIt(ImmutableLongArray.Builder builder, AtomicLong counter)212 void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { 213 List<Long> list = new ArrayList<>(); 214 long num = RANDOM.nextInt(10); 215 for (int i = 0; i < num; i++) { 216 list.add(counter.getAndIncrement()); 217 } 218 builder.addAll(iterable(list)); 219 } 220 }, 221 ADD_STREAM { 222 @Override doIt(ImmutableLongArray.Builder builder, AtomicLong counter)223 void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { 224 long[] array = new long[RANDOM.nextInt(10)]; 225 for (int i = 0; i < array.length; i++) { 226 array[i] = counter.getAndIncrement(); 227 } 228 builder.addAll(Arrays.stream(array)); 229 } 230 }, 231 ADD_IIA { 232 @Override doIt(ImmutableLongArray.Builder builder, AtomicLong counter)233 void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { 234 long[] array = new long[RANDOM.nextInt(10)]; 235 for (int i = 0; i < array.length; i++) { 236 array[i] = counter.getAndIncrement(); 237 } 238 builder.addAll(ImmutableLongArray.copyOf(array)); 239 } 240 }, 241 ADD_LARGER_ARRAY { 242 @Override doIt(ImmutableLongArray.Builder builder, AtomicLong counter)243 void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) { 244 long[] array = new long[RANDOM.nextInt(200) + 200]; 245 for (int i = 0; i < array.length; i++) { 246 array[i] = counter.getAndIncrement(); 247 } 248 builder.addAll(array); 249 } 250 }, 251 ; 252 253 static final BuilderOp[] values = values(); 254 randomOp()255 static BuilderOp randomOp() { 256 return values[RANDOM.nextInt(values.length)]; 257 } 258 doIt(ImmutableLongArray.Builder builder, AtomicLong counter)259 abstract void doIt(ImmutableLongArray.Builder builder, AtomicLong counter); 260 } 261 262 private static final Random RANDOM = new Random(42); 263 testLength()264 public void testLength() { 265 assertThat(ImmutableLongArray.of().length()).isEqualTo(0); 266 assertThat(ImmutableLongArray.of(0).length()).isEqualTo(1); 267 assertThat(ImmutableLongArray.of(0, 1, 3).length()).isEqualTo(3); 268 assertThat(ImmutableLongArray.of(0, 1, 3).subArray(1, 1).length()).isEqualTo(0); 269 assertThat(ImmutableLongArray.of(0, 1, 3).subArray(1, 2).length()).isEqualTo(1); 270 } 271 testIsEmpty()272 public void testIsEmpty() { 273 assertThat(ImmutableLongArray.of().isEmpty()).isTrue(); 274 assertThat(ImmutableLongArray.of(0).isEmpty()).isFalse(); 275 assertThat(ImmutableLongArray.of(0, 1, 3).isEmpty()).isFalse(); 276 assertThat(ImmutableLongArray.of(0, 1, 3).subArray(1, 1).isEmpty()).isTrue(); 277 assertThat(ImmutableLongArray.of(0, 1, 3).subArray(1, 2).isEmpty()).isFalse(); 278 } 279 testGet_good()280 public void testGet_good() { 281 ImmutableLongArray iia = ImmutableLongArray.of(0, 1, 3); 282 assertThat(iia.get(0)).isEqualTo(0L); 283 assertThat(iia.get(2)).isEqualTo(3L); 284 assertThat(iia.subArray(1, 3).get(1)).isEqualTo(3L); 285 } 286 testGet_bad()287 public void testGet_bad() { 288 ImmutableLongArray iia = ImmutableLongArray.of(0, 1, 3); 289 try { 290 iia.get(-1); 291 fail(); 292 } catch (IndexOutOfBoundsException expected) { 293 } 294 try { 295 iia.get(3); 296 fail(); 297 } catch (IndexOutOfBoundsException expected) { 298 } 299 300 iia = iia.subArray(1, 2); 301 try { 302 iia.get(-1); 303 fail(); 304 } catch (IndexOutOfBoundsException expected) { 305 } 306 } 307 testIndexOf()308 public void testIndexOf() { 309 ImmutableLongArray iia = ImmutableLongArray.of(1, 1, 2, 3, 5, 8); 310 assertThat(iia.indexOf(1)).isEqualTo(0); 311 assertThat(iia.indexOf(8)).isEqualTo(5); 312 assertThat(iia.indexOf(4)).isEqualTo(-1); 313 assertThat(ImmutableLongArray.of(13).indexOf(13)).isEqualTo(0); 314 assertThat(ImmutableLongArray.of().indexOf(21)).isEqualTo(-1); 315 assertThat(iia.subArray(1, 5).indexOf(1)).isEqualTo(0); 316 } 317 testLastIndexOf()318 public void testLastIndexOf() { 319 ImmutableLongArray iia = ImmutableLongArray.of(1, 1, 2, 3, 5, 8); 320 assertThat(iia.lastIndexOf(1)).isEqualTo(1); 321 assertThat(iia.lastIndexOf(8)).isEqualTo(5); 322 assertThat(iia.lastIndexOf(4)).isEqualTo(-1); 323 assertThat(ImmutableLongArray.of(13).lastIndexOf(13)).isEqualTo(0); 324 assertThat(ImmutableLongArray.of().lastIndexOf(21)).isEqualTo(-1); 325 assertThat(iia.subArray(1, 5).lastIndexOf(1)).isEqualTo(0); 326 } 327 testContains()328 public void testContains() { 329 ImmutableLongArray iia = ImmutableLongArray.of(1, 1, 2, 3, 5, 8); 330 assertThat(iia.contains(1)).isTrue(); 331 assertThat(iia.contains(8)).isTrue(); 332 assertThat(iia.contains(4)).isFalse(); 333 assertThat(ImmutableLongArray.of(13).contains(13)).isTrue(); 334 assertThat(ImmutableLongArray.of().contains(21)).isFalse(); 335 assertThat(iia.subArray(1, 5).contains(1)).isTrue(); 336 } 337 testForEach()338 public void testForEach() { 339 ImmutableLongArray.of().forEach(i -> fail()); 340 ImmutableLongArray.of(0, 1, 3).subArray(1, 1).forEach(i -> fail()); 341 342 AtomicLong count = new AtomicLong(0); 343 ImmutableLongArray.of(0, 1, 2, 3) 344 .forEach(i -> assertThat(i).isEqualTo(count.getAndIncrement())); 345 assertEquals(4, count.get()); 346 } 347 testStream()348 public void testStream() { 349 ImmutableLongArray.of().stream().forEach(i -> fail()); 350 ImmutableLongArray.of(0, 1, 3).subArray(1, 1).stream().forEach(i -> fail()); 351 assertThat(ImmutableLongArray.of(0, 1, 3).stream().toArray()).isEqualTo(new long[] {0, 1, 3}); 352 } 353 testSubArray()354 public void testSubArray() { 355 ImmutableLongArray iia0 = ImmutableLongArray.of(); 356 ImmutableLongArray iia1 = ImmutableLongArray.of(5); 357 ImmutableLongArray iia3 = ImmutableLongArray.of(5, 25, 125); 358 359 assertThat(iia0.subArray(0, 0)).isSameInstanceAs(ImmutableLongArray.of()); 360 assertThat(iia1.subArray(0, 0)).isSameInstanceAs(ImmutableLongArray.of()); 361 assertThat(iia1.subArray(1, 1)).isSameInstanceAs(ImmutableLongArray.of()); 362 assertThat(iia1.subArray(0, 1).asList()).containsExactly(5L); 363 assertThat(iia3.subArray(0, 2).asList()).containsExactly(5L, 25L).inOrder(); 364 assertThat(iia3.subArray(1, 3).asList()).containsExactly(25L, 125L).inOrder(); 365 366 try { 367 iia3.subArray(-1, 1); 368 fail(); 369 } catch (IndexOutOfBoundsException expected) { 370 } 371 try { 372 iia3.subArray(1, 4); 373 fail(); 374 } catch (IndexOutOfBoundsException expected) { 375 } 376 } 377 378 /* 379 * Whenever an implementation uses `instanceof` on a parameter instance, the test has to know that 380 * (so much for "black box") and try instances that both do and don't pass the check. The "don't" 381 * half of that is more awkward to arrange... 382 */ iterable(final Collection<T> collection)383 private static <T> Iterable<T> iterable(final Collection<T> collection) { 384 // return collection::iterator; 385 return new Iterable<T>() { 386 @Override 387 public Iterator<T> iterator() { 388 return collection.iterator(); 389 } 390 }; 391 } 392 393 public void testEquals() { 394 new EqualsTester() 395 .addEqualityGroup(ImmutableLongArray.of()) 396 .addEqualityGroup( 397 ImmutableLongArray.of(1, 2), 398 reserialize(ImmutableLongArray.of(1, 2)), 399 ImmutableLongArray.of(0, 1, 2, 3).subArray(1, 3)) 400 .addEqualityGroup(ImmutableLongArray.of(1, 3)) 401 .addEqualityGroup(ImmutableLongArray.of(1, 2, 3)) 402 .testEquals(); 403 } 404 405 /** 406 * This is probably a weird and hacky way to test what we're really trying to test, but hey, it 407 * caught a bug. 408 */ 409 public void testTrimmed() { 410 ImmutableLongArray iia = ImmutableLongArray.of(0, 1, 3); 411 assertDoesntActuallyTrim(iia); 412 assertDoesntActuallyTrim(iia.subArray(0, 3)); 413 assertActuallyTrims(iia.subArray(0, 2)); 414 assertActuallyTrims(iia.subArray(1, 3)); 415 416 ImmutableLongArray rightSized = ImmutableLongArray.builder(3).add(0).add(1).add(3).build(); 417 assertDoesntActuallyTrim(rightSized); 418 419 ImmutableLongArray overSized = ImmutableLongArray.builder(3).add(0).add(1).build(); 420 assertActuallyTrims(overSized); 421 422 ImmutableLongArray underSized = ImmutableLongArray.builder(2).add(0).add(1).add(3).build(); 423 assertActuallyTrims(underSized); 424 } 425 426 @GwtIncompatible // SerializableTester 427 public void testSerialization() { 428 assertThat(reserialize(ImmutableLongArray.of())).isSameInstanceAs(ImmutableLongArray.of()); 429 assertThat(reserialize(ImmutableLongArray.of(0, 1).subArray(1, 1))) 430 .isSameInstanceAs(ImmutableLongArray.of()); 431 432 ImmutableLongArray iia = ImmutableLongArray.of(0, 1, 3, 6).subArray(1, 3); 433 ImmutableLongArray iia2 = reserialize(iia); 434 assertThat(iia2).isEqualTo(iia); 435 assertDoesntActuallyTrim(iia2); 436 } 437 438 private static void assertActuallyTrims(ImmutableLongArray iia) { 439 ImmutableLongArray trimmed = iia.trimmed(); 440 assertThat(trimmed).isNotSameInstanceAs(iia); 441 442 // Yes, this is apparently how you check array equality in Truth 443 assertThat(trimmed.toArray()).isEqualTo(iia.toArray()); 444 } 445 446 private static void assertDoesntActuallyTrim(ImmutableLongArray iia) { 447 assertThat(iia.trimmed()).isSameInstanceAs(iia); 448 } 449 450 @GwtIncompatible // suite 451 public static Test suite() { 452 List<ListTestSuiteBuilder<Long>> builders = 453 ImmutableList.of( 454 ListTestSuiteBuilder.using(new ImmutableLongArrayAsListGenerator()) 455 .named("ImmutableLongArray.asList"), 456 ListTestSuiteBuilder.using(new ImmutableLongArrayHeadSubListAsListGenerator()) 457 .named("ImmutableLongArray.asList, head subList"), 458 ListTestSuiteBuilder.using(new ImmutableLongArrayTailSubListAsListGenerator()) 459 .named("ImmutableLongArray.asList, tail subList"), 460 ListTestSuiteBuilder.using(new ImmutableLongArrayMiddleSubListAsListGenerator()) 461 .named("ImmutableLongArray.asList, middle subList")); 462 463 TestSuite suite = new TestSuite(); 464 for (ListTestSuiteBuilder<Long> builder : builders) { 465 suite.addTest( 466 builder 467 .withFeatures( 468 CollectionSize.ZERO, 469 CollectionSize.ONE, 470 CollectionSize.SEVERAL, 471 CollectionFeature.ALLOWS_NULL_QUERIES, 472 CollectionFeature.RESTRICTS_ELEMENTS, 473 CollectionFeature.KNOWN_ORDER, 474 CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS) 475 .createTestSuite()); 476 } 477 suite.addTestSuite(ImmutableLongArrayTest.class); 478 return suite; 479 } 480 481 @GwtIncompatible // used only from suite 482 private static ImmutableLongArray makeArray(Long[] values) { 483 return ImmutableLongArray.copyOf(Arrays.asList(values)); 484 } 485 486 // Test generators. To let the GWT test suite generator access them, they need to be public named 487 // classes with a public default constructor (not that we run these suites under GWT yet). 488 489 @GwtIncompatible // used only from suite 490 public static final class ImmutableLongArrayAsListGenerator extends TestLongListGenerator { 491 @Override 492 protected List<Long> create(Long[] elements) { 493 return makeArray(elements).asList(); 494 } 495 } 496 497 @GwtIncompatible // used only from suite 498 public static final class ImmutableLongArrayHeadSubListAsListGenerator 499 extends TestLongListGenerator { 500 @Override 501 protected List<Long> create(Long[] elements) { 502 Long[] suffix = {Long.MIN_VALUE, Long.MAX_VALUE}; 503 Long[] all = concat(elements, suffix); 504 return makeArray(all).subArray(0, elements.length).asList(); 505 } 506 } 507 508 @GwtIncompatible // used only from suite 509 public static final class ImmutableLongArrayTailSubListAsListGenerator 510 extends TestLongListGenerator { 511 @Override 512 protected List<Long> create(Long[] elements) { 513 Long[] prefix = {86L, 99L}; 514 Long[] all = concat(prefix, elements); 515 return makeArray(all).subArray(2, elements.length + 2).asList(); 516 } 517 } 518 519 @GwtIncompatible // used only from suite 520 public static final class ImmutableLongArrayMiddleSubListAsListGenerator 521 extends TestLongListGenerator { 522 @Override 523 protected List<Long> create(Long[] elements) { 524 Long[] prefix = {Long.MIN_VALUE, Long.MAX_VALUE}; 525 Long[] suffix = {86L, 99L}; 526 Long[] all = concat(concat(prefix, elements), suffix); 527 return makeArray(all).subArray(2, elements.length + 2).asList(); 528 } 529 } 530 531 @GwtIncompatible // used only from suite 532 private static Long[] concat(Long[] a, Long[] b) { 533 return ObjectArrays.concat(a, b, Long.class); 534 } 535 536 @GwtIncompatible // used only from suite 537 public abstract static class TestLongListGenerator implements TestListGenerator<Long> { 538 @Override 539 public SampleElements<Long> samples() { 540 return new SampleLongs(); 541 } 542 543 @Override 544 public List<Long> create(Object... elements) { 545 Long[] array = new Long[elements.length]; 546 int i = 0; 547 for (Object e : elements) { 548 array[i++] = (Long) e; 549 } 550 return create(array); 551 } 552 553 /** 554 * Creates a new collection containing the given elements; implement this method instead of 555 * {@link #create(Object...)}. 556 */ 557 protected abstract List<Long> create(Long[] elements); 558 559 @Override 560 public Long[] createArray(int length) { 561 return new Long[length]; 562 } 563 564 /** Returns the original element list, unchanged. */ 565 @Override 566 public List<Long> order(List<Long> insertionOrder) { 567 return insertionOrder; 568 } 569 } 570 571 @GwtIncompatible // used only from suite 572 public static class SampleLongs extends SampleElements<Long> { 573 public SampleLongs() { 574 super(1L << 31, 1L << 33, 1L << 36, 1L << 40, 1L << 45); 575 } 576 } 577 } 578