Skip to content

Commit

Permalink
Complete missing unweighted methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gstamatelat committed Jun 27, 2018
1 parent 4c25148 commit 08e7a7e
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package gr.james.sampling;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.*;

/**
* This class provides a skeletal implementation of the {@link RandomSampling} interface to minimize the effort required
Expand Down Expand Up @@ -53,7 +50,7 @@ abstract class AbstractUnweightedRandomSampling<T> implements RandomSampling<T>
* @throws StreamOverflowException if the number of items feeded exceeds {@link Long#MAX_VALUE}
*/
@Override
public final RandomSampling<T> feed(T item) {
public RandomSampling<T> feed(T item) {
// Checks
if (item == null) {
throw new NullPointerException("Item was null");
Expand Down Expand Up @@ -86,6 +83,34 @@ public final RandomSampling<T> feed(T item) {
return this;
}

/**
* {@inheritDoc}
*
* @param items {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public RandomSampling<T> feed(Iterator<T> items) {
RandomSampling.super.feed(items);
return this;
}

/**
* {@inheritDoc}
*
* @param items {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public RandomSampling<T> feed(Iterable<T> items) {
RandomSampling.super.feed(items);
return this;
}

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -114,7 +139,7 @@ public final long streamSize() {
* @return {@inheritDoc}
*/
@Override
public Collection<T> sample() {
public final Collection<T> sample() {
final List<T> r = new ArrayList<>(sample);
assert r.size() == Math.min(sampleSize(), streamSize());
return r;
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/gr/james/sampling/VitterXSampling.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gr.james.sampling;

import java.util.Iterator;
import java.util.Random;

/**
Expand Down Expand Up @@ -54,4 +55,46 @@ long skipLength(long streamSize, int sampleSize, Random random) {

return gamma;
}

/**
* {@inheritDoc}
*
* @param item {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public VitterXSampling<T> feed(T item) {
super.feed(item);
return this;
}

/**
* {@inheritDoc}
*
* @param items {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public VitterXSampling<T> feed(Iterator<T> items) {
super.feed(items);
return this;
}

/**
* {@inheritDoc}
*
* @param items {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public VitterXSampling<T> feed(Iterable<T> items) {
super.feed(items);
return this;
}
}
43 changes: 43 additions & 0 deletions src/main/java/gr/james/sampling/VitterZSampling.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gr.james.sampling;

import java.util.Iterator;
import java.util.Random;

/**
Expand Down Expand Up @@ -81,4 +82,46 @@ long skipLength(long streamSize, int sampleSize, Random random) {
}
}
}

/**
* {@inheritDoc}
*
* @param item {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public VitterZSampling<T> feed(T item) {
super.feed(item);
return this;
}

/**
* {@inheritDoc}
*
* @param items {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public VitterZSampling<T> feed(Iterator<T> items) {
super.feed(items);
return this;
}

/**
* {@inheritDoc}
*
* @param items {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public VitterZSampling<T> feed(Iterable<T> items) {
super.feed(items);
return this;
}
}
43 changes: 43 additions & 0 deletions src/main/java/gr/james/sampling/WatermanSampling.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gr.james.sampling;

import java.util.Iterator;
import java.util.Random;

/**
Expand Down Expand Up @@ -48,4 +49,46 @@ long skipLength(long streamSize, int sampleSize, Random random) {
}
return skipCount;
}

/**
* {@inheritDoc}
*
* @param item {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public WatermanSampling<T> feed(T item) {
super.feed(item);
return this;
}

/**
* {@inheritDoc}
*
* @param items {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public WatermanSampling<T> feed(Iterator<T> items) {
super.feed(items);
return this;
}

/**
* {@inheritDoc}
*
* @param items {@inheritDoc}
* @return {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws StreamOverflowException {@inheritDoc}
*/
@Override
public WatermanSampling<T> feed(Iterable<T> items) {
super.feed(items);
return this;
}
}

0 comments on commit 08e7a7e

Please sign in to comment.