| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.common.collect.testing; |
| 18 |
|
| 19 |
import com.google.common.annotations.GwtCompatible; |
| 20 |
import com.google.common.collect.testing.features.CollectionSize; |
| 21 |
import java.util.ArrayList; |
| 22 |
import java.util.Arrays; |
| 23 |
import java.util.Collection; |
| 24 |
import java.util.List; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
@GwtCompatible |
| 32 |
public final class OneSizeGenerator<T, E> implements OneSizeTestContainerGenerator<T, E> { |
| 33 |
private final TestContainerGenerator<T, E> generator; |
| 34 |
private final CollectionSize collectionSize; |
| 35 |
|
| 36 |
public OneSizeGenerator(TestContainerGenerator<T, E> generator, CollectionSize collectionSize) { |
| 37 |
this.generator = generator; |
| 38 |
this.collectionSize = collectionSize; |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public TestContainerGenerator<T, E> getInnerGenerator() { |
| 43 |
return generator; |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
public SampleElements<E> samples() { |
| 48 |
return generator.samples(); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public T create(Object... elements) { |
| 53 |
return generator.create(elements); |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public E[] createArray(int length) { |
| 58 |
return generator.createArray(length); |
| 59 |
} |
| 60 |
|
| 61 |
@Override |
| 62 |
public T createTestSubject() { |
| 63 |
Collection<E> elements = getSampleElements(getCollectionSize().getNumElements()); |
| 64 |
return generator.create(elements.toArray()); |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public Collection<E> getSampleElements(int howMany) { |
| 69 |
SampleElements<E> samples = samples(); |
| 70 |
@SuppressWarnings("unchecked") |
| 71 |
List<E> allSampleElements = |
| 72 |
Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4()); |
| 73 |
return new ArrayList<>(allSampleElements.subList(0, howMany)); |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
public CollectionSize getCollectionSize() { |
| 78 |
return collectionSize; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public Iterable<E> order(List<E> insertionOrder) { |
| 83 |
return generator.order(insertionOrder); |
| 84 |
} |
| 85 |
} |