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