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