/** Creates a {@link FileLineIterable} over a given file, using the given encoding. */ public FileLineIterable(File file, Charset encoding, boolean skipFirstLine) throws IOException { this(FileLineIterator.getFileInputStream(file), encoding, skipFirstLine); }
@Override protected Integer computeNext() { if (count < to) { return count++; } else { return endOfData(); } }
public static <T> Iterable<T> maybeWrapIterable(Iterable<T> delegate, double samplingRate) { return samplingRate >= 1.0 ? delegate : new SamplingIterable<T>(delegate, samplingRate); }
@Test public void testSmallInput() { Iterator<Integer> t = new SamplingIterator<Integer>(new CountingIterator(1), 0.9999); assertTrue(t.hasNext()); assertEquals(0, t.next().intValue()); assertFalse(t.hasNext()); }
@Test public void testEmptyCase() { assertFalse(new SamplingIterator<Integer>(new CountingIterator(0), 0.9999).hasNext()); assertFalse(new SamplingIterator<Integer>(new CountingIterator(0), 1).hasNext()); }
@Test(expected = IllegalArgumentException.class) public void testBadRate1() { new SamplingIterator<Integer>(new CountingIterator(1), 0.0); }
@Test public void testEmptyCase() { assertFalse(new CountingIterator(0).hasNext()); }
@Override protected Iterator<Integer> createSampler(int n, Iterator<Integer> source) { return new FixedSizeSamplingIterator<Integer>(n, source); }
@Override protected Iterator<Integer> createSampler(int n, Iterator<Integer> source) { return new StableFixedSizeSamplingIterator<Integer>(n, source); }
@Test public void testExactSizeMatch() { Iterator<Integer> t = new SamplingIterator<Integer>(new CountingIterator(10), 1); for (int i = 0; i < 10; i++) { assertTrue(t.hasNext()); assertEquals(i, t.next().intValue()); } assertFalse(t.hasNext()); }
@Test(expected = IllegalArgumentException.class) public void testBadRate2() { new SamplingIterator<Integer>(new CountingIterator(1), 1.1); }
/** Creates a {@link FileLineIterable} over a given file, using the given encoding. */ public FileLineIterable(File file, Charset encoding, boolean skipFirstLine) throws IOException { this(FileLineIterator.getFileInputStream(file), encoding, skipFirstLine); }
@Override protected Integer computeNext() { if (count < to) { return count++; } else { return endOfData(); } }
public static <T> Iterable<T> maybeWrapIterable(Iterable<T> delegate, double samplingRate) { return samplingRate >= 1.0 ? delegate : new SamplingIterable<>(delegate, samplingRate); }
/** * Creates a {@link FileLineIterator} over a given file, using the given encoding. * * @throws java.io.FileNotFoundException if the file does not exist * @throws IOException if the file cannot be read */ public FileLineIterator(File file, Charset encoding, boolean skipFirstLine) throws IOException { this(getFileInputStream(file), encoding, skipFirstLine); }
@Override protected Integer computeNext() { if (count < to) { return count++; } else { return endOfData(); } }
public static <T> Iterable<T> maybeWrapIterable(Iterable<T> delegate, double samplingRate) { return samplingRate >= 1.0 ? delegate : new SamplingIterable<T>(delegate, samplingRate); }
/** * Creates a {@link FileLineIterator} over a given file, using the given encoding. * * @throws java.io.FileNotFoundException if the file does not exist * @throws IOException if the file cannot be read */ public FileLineIterator(File file, Charset encoding, boolean skipFirstLine) throws IOException { this(getFileInputStream(file), encoding, skipFirstLine); }
/** * Creates a {@link FileLineIterator} over a given file, using the given encoding. * * @throws java.io.FileNotFoundException if the file does not exist * @throws IOException if the file cannot be read */ public FileLineIterator(File file, Charset encoding, boolean skipFirstLine) throws IOException { this(getFileInputStream(file), encoding, skipFirstLine); }
/** Creates a {@link FileLineIterable} over a given file, using the given encoding. */ public FileLineIterable(File file, Charset encoding, boolean skipFirstLine) throws IOException { this(FileLineIterator.getFileInputStream(file), encoding, skipFirstLine); }