com.yammer.metrics.stats
Class UniformSample

java.lang.Object
  extended by com.yammer.metrics.stats.UniformSample
All Implemented Interfaces:
Sample

public class UniformSample
extends Object
implements Sample

A random sample of a stream of longs. Uses Vitter's Algorithm R to produce a statistically representative sample.

See Also:
Random Sampling with a Reservoir

Constructor Summary
UniformSample(int reservoirSize)
          Creates a new UniformSample.
 
Method Summary
 void clear()
          Clears all recorded values.
 void dump(File output)
          Writes the values of the sample to the given file.
 int size()
          Returns the number of values recorded.
 void update(long value)
          Adds a new recorded value to the sample.
 List<Long> values()
          Returns a copy of the sample's values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UniformSample

public UniformSample(int reservoirSize)
Creates a new UniformSample.

Parameters:
reservoirSize - the number of samples to keep in the sampling reservoir
Method Detail

clear

public void clear()
Description copied from interface: Sample
Clears all recorded values.

Specified by:
clear in interface Sample

size

public int size()
Description copied from interface: Sample
Returns the number of values recorded.

Specified by:
size in interface Sample
Returns:
the number of values recorded

update

public void update(long value)
Description copied from interface: Sample
Adds a new recorded value to the sample.

Specified by:
update in interface Sample
Parameters:
value - a new recorded value

values

public List<Long> values()
Description copied from interface: Sample
Returns a copy of the sample's values.

Specified by:
values in interface Sample
Returns:
a copy of the sample's values

dump

public void dump(File output)
          throws IOException
Description copied from interface: Sample
Writes the values of the sample to the given file.

Specified by:
dump in interface Sample
Parameters:
output - the file to which the values will be written
Throws:
IOException - if there is an error writing the values


Copyright © 2011. All Rights Reserved.