test_class.file: ml/streaminer/src/test/java/org/streaminer/stream/sampler/ChainSamplerTest.java
test_class.identifier: ChainSamplerTest
test_case.body: @Test
      public void testSample() {
          System.out.println("sample");
          
          ChainSampler sampler = new ChainSampler(10, 125);
          
          for (int j=0; j<1000; j++) {
              sampler.sample(j);
          }
      }
test_case.class_method_signature: ChainSamplerTest.testSample()
test_case.full_signature: @Test public void testSample()
test_case.identifier: testSample
test_case.invocations: println sample
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testSample()
focal_class.declarator: LOG = LoggerFactory.getLogger(ChainSampler.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOG = LoggerFactory.getLogger(ChainSampler.class);
focal_class.type: Logger
focal_class.var_name: LOG
focal_class.declarator: k
focal_class.modifier: private
focal_class.original_string: private int k;
focal_class.type: int
focal_class.var_name: k
focal_class.declarator: n
focal_class.modifier: private
focal_class.original_string: private int n;
focal_class.type: int
focal_class.var_name: n
focal_class.declarator: count = 0
focal_class.modifier: private
focal_class.original_string: private long count = 0;
focal_class.type: long
focal_class.var_name: count
focal_class.declarator: fillSample = 0
focal_class.modifier: private
focal_class.original_string: private int fillSample = 0;
focal_class.type: int
focal_class.var_name: fillSample
focal_class.declarator: items
focal_class.modifier: private
focal_class.original_string: private Serializable[] items;
focal_class.type: Serializable[]
focal_class.var_name: items
focal_class.declarator: replacements
focal_class.modifier: private
focal_class.original_string: private Map<Integer, Integer> replacements;
focal_class.type: Map<Integer, Integer>
focal_class.var_name: replacements
focal_class.declarator: rand = new Random()
focal_class.modifier: private
focal_class.original_string: private Random rand = new Random();
focal_class.type: Random
focal_class.var_name: rand
focal_class.file: ml/streaminer/src/main/java/org/streaminer/stream/sampler/ChainSampler.java
focal_class.identifier: ChainSampler
focal_class.interfaces: implements ISampleList<Serializable>
focal_class.class_method_signature: ChainSampler.ChainSampler(int k, int n)
focal_class.full_signature: public  ChainSampler(int k, int n)
focal_class.identifier: ChainSampler
focal_class.modifiers: public
focal_class.parameters: (int k, int n)
focal_class.signature:  ChainSampler(int k, int n)
focal_class.class_method_signature: ChainSampler.sample(Serializable item)
focal_class.full_signature: public void sample(Serializable item)
focal_class.identifier: sample
focal_class.modifiers: public
focal_class.parameters: (Serializable item)
focal_class.return: void
focal_class.signature: void sample(Serializable item)
focal_class.class_method_signature: ChainSampler.sample(Serializable... t)
focal_class.full_signature: public void sample(Serializable... t)
focal_class.identifier: sample
focal_class.modifiers: public
focal_class.parameters: (Serializable... t)
focal_class.return: void
focal_class.signature: void sample(Serializable... t)
focal_class.class_method_signature: ChainSampler.getSamples()
focal_class.full_signature: public Collection<Serializable> getSamples()
focal_class.identifier: getSamples
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Collection<Serializable>
focal_class.signature: Collection<Serializable> getSamples()
focal_class.class_method_signature: ChainSampler.getSize()
focal_class.full_signature: public int getSize()
focal_class.identifier: getSize
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getSize()
focal_method.body: 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++;
      }
focal_method.class_method_signature: ChainSampler.sample(Serializable item)
focal_method.full_signature: public void sample(Serializable item)
focal_method.identifier: sample
focal_method.invocations: containsKey get nextInt info format remove put min nextDouble nextInt put info format
focal_method.modifiers: public
focal_method.parameters: (Serializable item)
focal_method.return: void
focal_method.signature: void sample(Serializable item)