@Test public void shouldSometimesReturnLastItemInCollection() { Generator<Integer> someGenerator = new RandomFromCollectionGenerator<>(1,2); for (int i = 0; i < 100; i++) { Integer generated = someGenerator.next(); if (generated % 2 == 0) return; } fail("Number 2 was not generated"); }
@Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } RandomFromCollectionGenerator(@Nonnull Collection<T> items); @SafeVarargs  RandomFromCollectionGenerator(T... items); }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } RandomFromCollectionGenerator(@Nonnull Collection<T> items); @SafeVarargs  RandomFromCollectionGenerator(T... items); @Override T next(); }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } RandomFromCollectionGenerator(@Nonnull Collection<T> items); @SafeVarargs  RandomFromCollectionGenerator(T... items); @Override T next();  }