T - type of items in the collection being sampledpublic class UniformSampler<T> extends Object implements CollectionSampler<T>
CollectionSampler that performs uniform sampling.
Each sampled set is sampled without replacement (i.e. an item will only
appear once), however there is no guarantee that subsequent calls to
sample(int) will return unique sets of samples.| Constructor and Description |
|---|
UniformSampler() |
| Modifier and Type | Method and Description |
|---|---|
List<T> |
sample(int nItems)
Samples
nItems items from the collection set by
CollectionSampler.setCollection(Collection), returning a new collection with the
given samples. |
void |
setCollection(Collection<? extends T> collection)
Set the items to sample from.
|
public UniformSampler()
public void setCollection(Collection<? extends T> collection)
CollectionSamplersetCollection in interface CollectionSampler<T>collection - the items to sample frompublic List<T> sample(int nItems)
CollectionSamplernItems items from the collection set by
CollectionSampler.setCollection(Collection), returning a new collection with the
given samples. Implementations can decide what to do if
nItems is bigger than the number of items in the collection.sample in interface CollectionSampler<T>nItems - the number of items to samplenull if a sample cannot be made
for any reason.