package com.bbn.bue.common.collections;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

/**
 * This is an {@link Iterable} which provides its data in a random order
 * every time an iterator is requested. Note this must load its entire underlying
 * {@link Iterable} into memory.
 * @param <T>
 */
public final class ShufflingIterable<T> implements Iterable<T> {
  private final ImmutableList<T> data;
  private final Random rng;

  private ShufflingIterable(Iterable<T> iterable, Random rng) {
    this.data = ImmutableList.copyOf(iterable);
    this.rng = checkNotNull(rng);
  }

  public static <T> ShufflingIterable<T> from(Iterable<T> iterable, Random rng) {
    return new ShufflingIterable<T>(iterable, rng);
  }

  @Override
  public Iterator<T> iterator() {
    final List<T> shuffledList = Lists.newArrayList(data);
    Collections.shuffle(shuffledList, rng);
    return Collections.unmodifiableList(shuffledList).iterator();
  }
}


@@ -127,74 +127,8 @@
 s;%0A%0A
-import java.util.AbstractCollection;%0Aimport java.util.Collection;%0A
 impo
@@ -233,74 +233,8 @@
 m;%0A%0A
-import static com.google.common.base.Preconditions.checkArgument;%0A
 impo
@@ -491,22 +491,8 @@
 ry.%0A
- * @param %3CT%3E%0A
  */%0A
@@ -652,16 +652,22 @@
 terable(
+final 
 Iterable
@@ -671,32 +671,38 @@
 ble%3CT%3E iterable,
+ final
  Random rng) %7B%0A 
@@ -787,16 +787,328 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Returns a new %7B@link ShufflingIterable%7D for the specified iterable and random number generator.%0A   *%0A   * @param iterable the source iterable%0A   * @param rng the random number generator to use in shuffling the iterable%0A   * @return a new shuffling iterable for contents of the original iterable%0A   */%0A
   public
@@ -1145,16 +1145,22 @@
 T%3E from(
+final 
 Iterable
@@ -1172,16 +1172,22 @@
 terable,
+ final
  Random 
@@ -1226,17 +1226,16 @@
 terable%3C
-T
 %3E(iterab
@@ -1249,16 +1249,110 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Returns a new iterator that iterates over a new random ordering of the data.%0A   */%0A
   @Overr

Improve documentation for ShufflingIterable.