• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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])).isSameAs(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)).isSameAs(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)).isSameAs(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)).isSameAs(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())).isSameAs(ImmutableLongArray.of());
142     assertThat(ImmutableLongArray.copyOf(LongStream.of(0, 1, 3)).asList())
143         .containsExactly(0L, 1L, 3L)
144         .inOrder();
145   }
146 
testBuilder_presize_zero()147   public void testBuilder_presize_zero() {
148     ImmutableLongArray.Builder builder = ImmutableLongArray.builder(0);
149     builder.add(5L);
150     ImmutableLongArray array = builder.build();
151     assertThat(array.asList()).containsExactly(5L);
152   }
153 
testBuilder_presize_negative()154   public void testBuilder_presize_negative() {
155     try {
156       ImmutableLongArray.builder(-1);
157       fail();
158     } catch (IllegalArgumentException expected) {
159     }
160   }
161 
162   /**
163    * If there's a bug in builder growth, we wouldn't know how to expose it. So, brute force the hell
164    * out of it for a while and see what happens.
165    */
testBuilder_bruteForce()166   public void testBuilder_bruteForce() {
167     for (int i = 0; i < reduceIterationsIfGwt(100); i++) {
168       ImmutableLongArray.Builder builder = ImmutableLongArray.builder(RANDOM.nextInt(20));
169       AtomicLong counter = new AtomicLong(0);
170       while (counter.get() < 1000) {
171         BuilderOp op = BuilderOp.randomOp();
172         op.doIt(builder, counter);
173       }
174       ImmutableLongArray iia = builder.build();
175       for (int j = 0; j < iia.length(); j++) {
176         assertThat(iia.get(j)).isEqualTo((long) j);
177       }
178     }
179   }
180 
181   private enum BuilderOp {
182     ADD_ONE {
183       @Override
doIt(ImmutableLongArray.Builder builder, AtomicLong counter)184       void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) {
185         builder.add(counter.getAndIncrement());
186       }
187     },
188     ADD_ARRAY {
189       @Override
doIt(ImmutableLongArray.Builder builder, AtomicLong counter)190       void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) {
191         long[] array = new long[RANDOM.nextInt(10)];
192         for (int i = 0; i < array.length; i++) {
193           array[i] = counter.getAndIncrement();
194         }
195         builder.addAll(array);
196       }
197     },
198     ADD_COLLECTION {
199       @Override
doIt(ImmutableLongArray.Builder builder, AtomicLong counter)200       void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) {
201         List<Long> list = new ArrayList<>();
202         long num = RANDOM.nextInt(10);
203         for (int i = 0; i < num; i++) {
204           list.add(counter.getAndIncrement());
205         }
206         builder.addAll(list);
207       }
208     },
209     ADD_ITERABLE {
210       @Override
doIt(ImmutableLongArray.Builder builder, AtomicLong counter)211       void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) {
212         List<Long> list = new ArrayList<>();
213         long num = RANDOM.nextInt(10);
214         for (int i = 0; i < num; i++) {
215           list.add(counter.getAndIncrement());
216         }
217         builder.addAll(iterable(list));
218       }
219     },
220     ADD_STREAM {
221       @Override
doIt(ImmutableLongArray.Builder builder, AtomicLong counter)222       void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) {
223         long[] array = new long[RANDOM.nextInt(10)];
224         for (int i = 0; i < array.length; i++) {
225           array[i] = counter.getAndIncrement();
226         }
227         builder.addAll(Arrays.stream(array));
228       }
229     },
230     ADD_IIA {
231       @Override
doIt(ImmutableLongArray.Builder builder, AtomicLong counter)232       void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) {
233         long[] array = new long[RANDOM.nextInt(10)];
234         for (int i = 0; i < array.length; i++) {
235           array[i] = counter.getAndIncrement();
236         }
237         builder.addAll(ImmutableLongArray.copyOf(array));
238       }
239     },
240     ADD_LARGER_ARRAY {
241       @Override
doIt(ImmutableLongArray.Builder builder, AtomicLong counter)242       void doIt(ImmutableLongArray.Builder builder, AtomicLong counter) {
243         long[] array = new long[RANDOM.nextInt(200) + 200];
244         for (int i = 0; i < array.length; i++) {
245           array[i] = counter.getAndIncrement();
246         }
247         builder.addAll(array);
248       }
249     },
250     ;
251 
252     static final BuilderOp[] values = values();
253 
randomOp()254     static BuilderOp randomOp() {
255       return values[RANDOM.nextInt(values.length)];
256     }
257 
doIt(ImmutableLongArray.Builder builder, AtomicLong counter)258     abstract void doIt(ImmutableLongArray.Builder builder, AtomicLong counter);
259   }
260 
261   private static final Random RANDOM = new Random(42);
262 
testLength()263   public void testLength() {
264     assertThat(ImmutableLongArray.of().length()).isEqualTo(0);
265     assertThat(ImmutableLongArray.of(0).length()).isEqualTo(1);
266     assertThat(ImmutableLongArray.of(0, 1, 3).length()).isEqualTo(3);
267     assertThat(ImmutableLongArray.of(0, 1, 3).subArray(1, 1).length()).isEqualTo(0);
268     assertThat(ImmutableLongArray.of(0, 1, 3).subArray(1, 2).length()).isEqualTo(1);
269   }
270 
testIsEmpty()271   public void testIsEmpty() {
272     assertThat(ImmutableLongArray.of().isEmpty()).isTrue();
273     assertThat(ImmutableLongArray.of(0).isEmpty()).isFalse();
274     assertThat(ImmutableLongArray.of(0, 1, 3).isEmpty()).isFalse();
275     assertThat(ImmutableLongArray.of(0, 1, 3).subArray(1, 1).isEmpty()).isTrue();
276     assertThat(ImmutableLongArray.of(0, 1, 3).subArray(1, 2).isEmpty()).isFalse();
277   }
278 
testGet_good()279   public void testGet_good() {
280     ImmutableLongArray iia = ImmutableLongArray.of(0, 1, 3);
281     assertThat(iia.get(0)).isEqualTo(0L);
282     assertThat(iia.get(2)).isEqualTo(3L);
283     assertThat(iia.subArray(1, 3).get(1)).isEqualTo(3L);
284   }
285 
testGet_bad()286   public void testGet_bad() {
287     ImmutableLongArray iia = ImmutableLongArray.of(0, 1, 3);
288     try {
289       iia.get(-1);
290       fail();
291     } catch (IndexOutOfBoundsException expected) {
292     }
293     try {
294       iia.get(3);
295       fail();
296     } catch (IndexOutOfBoundsException expected) {
297     }
298 
299     iia = iia.subArray(1, 2);
300     try {
301       iia.get(-1);
302       fail();
303     } catch (IndexOutOfBoundsException expected) {
304     }
305   }
306 
testIndexOf()307   public void testIndexOf() {
308     ImmutableLongArray iia = ImmutableLongArray.of(1, 1, 2, 3, 5, 8);
309     assertThat(iia.indexOf(1)).isEqualTo(0);
310     assertThat(iia.indexOf(8)).isEqualTo(5);
311     assertThat(iia.indexOf(4)).isEqualTo(-1);
312     assertThat(ImmutableLongArray.of(13).indexOf(13)).isEqualTo(0);
313     assertThat(ImmutableLongArray.of().indexOf(21)).isEqualTo(-1);
314     assertThat(iia.subArray(1, 5).indexOf(1)).isEqualTo(0);
315   }
316 
testLastIndexOf()317   public void testLastIndexOf() {
318     ImmutableLongArray iia = ImmutableLongArray.of(1, 1, 2, 3, 5, 8);
319     assertThat(iia.lastIndexOf(1)).isEqualTo(1);
320     assertThat(iia.lastIndexOf(8)).isEqualTo(5);
321     assertThat(iia.lastIndexOf(4)).isEqualTo(-1);
322     assertThat(ImmutableLongArray.of(13).lastIndexOf(13)).isEqualTo(0);
323     assertThat(ImmutableLongArray.of().lastIndexOf(21)).isEqualTo(-1);
324     assertThat(iia.subArray(1, 5).lastIndexOf(1)).isEqualTo(0);
325   }
326 
testContains()327   public void testContains() {
328     ImmutableLongArray iia = ImmutableLongArray.of(1, 1, 2, 3, 5, 8);
329     assertThat(iia.contains(1)).isTrue();
330     assertThat(iia.contains(8)).isTrue();
331     assertThat(iia.contains(4)).isFalse();
332     assertThat(ImmutableLongArray.of(13).contains(13)).isTrue();
333     assertThat(ImmutableLongArray.of().contains(21)).isFalse();
334     assertThat(iia.subArray(1, 5).contains(1)).isTrue();
335   }
336 
testForEach()337   public void testForEach() {
338     ImmutableLongArray.of().forEach(i -> fail());
339     ImmutableLongArray.of(0, 1, 3).subArray(1, 1).forEach(i -> fail());
340 
341     AtomicLong count = new AtomicLong(0);
342     ImmutableLongArray.of(0, 1, 2, 3)
343         .forEach(i -> assertThat(i).isEqualTo(count.getAndIncrement()));
344     assertEquals(4, count.get());
345   }
346 
testStream()347   public void testStream() {
348     ImmutableLongArray.of().stream().forEach(i -> fail());
349     ImmutableLongArray.of(0, 1, 3).subArray(1, 1).stream().forEach(i -> fail());
350     assertThat(ImmutableLongArray.of(0, 1, 3).stream().toArray()).isEqualTo(new long[] {0, 1, 3});
351   }
352 
testSubArray()353   public void testSubArray() {
354     ImmutableLongArray iia0 = ImmutableLongArray.of();
355     ImmutableLongArray iia1 = ImmutableLongArray.of(5);
356     ImmutableLongArray iia3 = ImmutableLongArray.of(5, 25, 125);
357 
358     assertThat(iia0.subArray(0, 0)).isSameAs(ImmutableLongArray.of());
359     assertThat(iia1.subArray(0, 0)).isSameAs(ImmutableLongArray.of());
360     assertThat(iia1.subArray(1, 1)).isSameAs(ImmutableLongArray.of());
361     assertThat(iia1.subArray(0, 1).asList()).containsExactly(5L);
362     assertThat(iia3.subArray(0, 2).asList()).containsExactly(5L, 25L).inOrder();
363     assertThat(iia3.subArray(1, 3).asList()).containsExactly(25L, 125L).inOrder();
364 
365     try {
366       iia3.subArray(-1, 1);
367       fail();
368     } catch (IndexOutOfBoundsException expected) {
369     }
370     try {
371       iia3.subArray(1, 4);
372       fail();
373     } catch (IndexOutOfBoundsException expected) {
374     }
375   }
376 
377   /*
378    * Whenever an implementation uses `instanceof` on a parameter instance, the test has to know that
379    * (so much for "black box") and try instances that both do and don't pass the check. The "don't"
380    * half of that is more awkward to arrange...
381    */
iterable(final Collection<T> collection)382   private static <T> Iterable<T> iterable(final Collection<T> collection) {
383     // return collection::iterator;
384     return new Iterable<T>() {
385       @Override
386       public Iterator<T> iterator() {
387         return collection.iterator();
388       }
389     };
390   }
391 
392   public void testEquals() {
393     new EqualsTester()
394         .addEqualityGroup(ImmutableLongArray.of())
395         .addEqualityGroup(
396             ImmutableLongArray.of(1, 2),
397             reserialize(ImmutableLongArray.of(1, 2)),
398             ImmutableLongArray.of(0, 1, 2, 3).subArray(1, 3))
399         .addEqualityGroup(ImmutableLongArray.of(1, 3))
400         .addEqualityGroup(ImmutableLongArray.of(1, 2, 3))
401         .testEquals();
402   }
403 
404   /**
405    * This is probably a weird and hacky way to test what we're really trying to test, but hey, it
406    * caught a bug.
407    */
408   public void testTrimmed() {
409     ImmutableLongArray iia = ImmutableLongArray.of(0, 1, 3);
410     assertDoesntActuallyTrim(iia);
411     assertDoesntActuallyTrim(iia.subArray(0, 3));
412     assertActuallyTrims(iia.subArray(0, 2));
413     assertActuallyTrims(iia.subArray(1, 3));
414 
415     ImmutableLongArray rightSized = ImmutableLongArray.builder(3).add(0).add(1).add(3).build();
416     assertDoesntActuallyTrim(rightSized);
417 
418     ImmutableLongArray overSized = ImmutableLongArray.builder(3).add(0).add(1).build();
419     assertActuallyTrims(overSized);
420 
421     ImmutableLongArray underSized = ImmutableLongArray.builder(2).add(0).add(1).add(3).build();
422     assertActuallyTrims(underSized);
423   }
424 
425   @GwtIncompatible // SerializableTester
426   public void testSerialization() {
427     assertThat(reserialize(ImmutableLongArray.of())).isSameAs(ImmutableLongArray.of());
428     assertThat(reserialize(ImmutableLongArray.of(0, 1).subArray(1, 1)))
429         .isSameAs(ImmutableLongArray.of());
430 
431     ImmutableLongArray iia = ImmutableLongArray.of(0, 1, 3, 6).subArray(1, 3);
432     ImmutableLongArray iia2 = reserialize(iia);
433     assertThat(iia2).isEqualTo(iia);
434     assertDoesntActuallyTrim(iia2);
435   }
436 
437   private static void assertActuallyTrims(ImmutableLongArray iia) {
438     ImmutableLongArray trimmed = iia.trimmed();
439     assertThat(trimmed).isNotSameAs(iia);
440 
441     // Yes, this is apparently how you check array equality in Truth
442     assertThat(trimmed.toArray()).isEqualTo(iia.toArray());
443   }
444 
445   private static void assertDoesntActuallyTrim(ImmutableLongArray iia) {
446     assertThat(iia.trimmed()).isSameAs(iia);
447   }
448 
449   @GwtIncompatible // suite
450   public static Test suite() {
451     List<ListTestSuiteBuilder<Long>> builders =
452         ImmutableList.of(
453             ListTestSuiteBuilder.using(new ImmutableLongArrayAsListGenerator())
454                 .named("ImmutableLongArray.asList"),
455             ListTestSuiteBuilder.using(new ImmutableLongArrayHeadSubListAsListGenerator())
456                 .named("ImmutableLongArray.asList, head subList"),
457             ListTestSuiteBuilder.using(new ImmutableLongArrayTailSubListAsListGenerator())
458                 .named("ImmutableLongArray.asList, tail subList"),
459             ListTestSuiteBuilder.using(new ImmutableLongArrayMiddleSubListAsListGenerator())
460                 .named("ImmutableLongArray.asList, middle subList"));
461 
462     TestSuite suite = new TestSuite();
463     for (ListTestSuiteBuilder<Long> builder : builders) {
464       suite.addTest(
465           builder
466               .withFeatures(
467                   CollectionSize.ZERO,
468                   CollectionSize.ONE,
469                   CollectionSize.SEVERAL,
470                   CollectionFeature.ALLOWS_NULL_QUERIES,
471                   CollectionFeature.RESTRICTS_ELEMENTS,
472                   CollectionFeature.KNOWN_ORDER,
473                   CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)
474               .createTestSuite());
475     }
476     suite.addTestSuite(ImmutableLongArrayTest.class);
477     return suite;
478   }
479 
480   @GwtIncompatible // used only from suite
481   private static ImmutableLongArray makeArray(Long[] values) {
482     return ImmutableLongArray.copyOf(Arrays.asList(values));
483   }
484 
485   // Test generators.  To let the GWT test suite generator access them, they need to be public named
486   // classes with a public default constructor (not that we run these suites under GWT yet).
487 
488   @GwtIncompatible // used only from suite
489   public static final class ImmutableLongArrayAsListGenerator extends TestLongListGenerator {
490     @Override
491     protected List<Long> create(Long[] elements) {
492       return makeArray(elements).asList();
493     }
494   }
495 
496   @GwtIncompatible // used only from suite
497   public static final class ImmutableLongArrayHeadSubListAsListGenerator
498       extends TestLongListGenerator {
499     @Override
500     protected List<Long> create(Long[] elements) {
501       Long[] suffix = {Long.MIN_VALUE, Long.MAX_VALUE};
502       Long[] all = concat(elements, suffix);
503       return makeArray(all).subArray(0, elements.length).asList();
504     }
505   }
506 
507   @GwtIncompatible // used only from suite
508   public static final class ImmutableLongArrayTailSubListAsListGenerator
509       extends TestLongListGenerator {
510     @Override
511     protected List<Long> create(Long[] elements) {
512       Long[] prefix = {86L, 99L};
513       Long[] all = concat(prefix, elements);
514       return makeArray(all).subArray(2, elements.length + 2).asList();
515     }
516   }
517 
518   @GwtIncompatible // used only from suite
519   public static final class ImmutableLongArrayMiddleSubListAsListGenerator
520       extends TestLongListGenerator {
521     @Override
522     protected List<Long> create(Long[] elements) {
523       Long[] prefix = {Long.MIN_VALUE, Long.MAX_VALUE};
524       Long[] suffix = {86L, 99L};
525       Long[] all = concat(concat(prefix, elements), suffix);
526       return makeArray(all).subArray(2, elements.length + 2).asList();
527     }
528   }
529 
530   @GwtIncompatible // used only from suite
531   private static Long[] concat(Long[] a, Long[] b) {
532     return ObjectArrays.concat(a, b, Long.class);
533   }
534 
535   @GwtIncompatible // used only from suite
536   public abstract static class TestLongListGenerator implements TestListGenerator<Long> {
537     @Override
538     public SampleElements<Long> samples() {
539       return new SampleLongs();
540     }
541 
542     @Override
543     public List<Long> create(Object... elements) {
544       Long[] array = new Long[elements.length];
545       int i = 0;
546       for (Object e : elements) {
547         array[i++] = (Long) e;
548       }
549       return create(array);
550     }
551 
552     /**
553      * Creates a new collection containing the given elements; implement this method instead of
554      * {@link #create(Object...)}.
555      */
556     protected abstract List<Long> create(Long[] elements);
557 
558     @Override
559     public Long[] createArray(int length) {
560       return new Long[length];
561     }
562 
563     /** Returns the original element list, unchanged. */
564     @Override
565     public List<Long> order(List<Long> insertionOrder) {
566       return insertionOrder;
567     }
568   }
569 
570   @GwtIncompatible // used only from suite
571   public static class SampleLongs extends SampleElements<Long> {
572     public SampleLongs() {
573       super(1L << 31, 1L << 33, 1L << 36, 1L << 40, 1L << 45);
574     }
575   }
576 }
577