class ChainSampler implements ISampleList<Serializable> {

    public void sample(Serializable item) {
        int i = (int) (count%n);
        
        if (replacements.containsKey(i)) {
            int replace = replacements.get(i);
            // replace the old item
            items[replace] = item;
            
            int next = rand.nextInt(n);
            
            LOG.info(String.format("Item=%s; i=%d; b=%d; next=%d", item, i, replace, next));
            
            replacements.remove(i);
            replacements.put(next, replace);
        }
        
        // this will build the initial sample
        else if (fillSample < k) {
            double prob = ((double)Math.min(i, n))/((double)n);
            
            if (rand.nextDouble() < prob) {
                int bucket = fillSample++;
                int next = rand.nextInt(n);
                
                items[bucket] = item;
                replacements.put(next, bucket);
                
                LOG.info(String.format("[init] Item=%s; i=%d; b=%d; next=%d", item, i, bucket, next));
            }
        }
        count++;
    }

    public  ChainSampler(int k, int n);

}