Monday, February 20, 2017

Shuffler

abstract class Shuffler<T>
implements IShuffle<T> {

  private SeqValidator<T> validator = new SeqValidator<T>();

  // IShuffle methods

  public T[] shuffle(T[] seq)
  throws IllegalArgumentException {
    validator.assertSeqNotEmpty(seq);
    maneuver(seq, 0, seq.length - 1);
    return seq;
  }

  public T[] shuffle(T[] seq, int from, int to)
  throws IndexOutOfBoundsException, IllegalArgumentException {
    validator.assertValidRange(seq, from, to);
    maneuver(seq, from, to);
    return seq;
  }

  // Abstract methods

  public abstract void maneuver(T[] seq, int from, int to);
}