public void sample(T item) {
        Preconditions.checkNotNull(item);
        if (reservoir.size() < numSamples) {
            // reservoir not yet full, just append
            reservoir.add(item);
        } else {
            // find a sample to replace
            int randomIndex = random.nextInt(numItemsSeen + 1);
            if (randomIndex < numSamples) {
                reservoir.set(randomIndex, item);
            }
        }
        numItemsSeen++;
    }
Sample an item and store in the reservoir if needed.

@param item The item to sample - may not be null.
ache/src/main/java/achecrawler/util/Sampler.java