Monday, February 13, 2017

Searcher

abstract class Searcher<T extends Comparable<T>>
implements ISearch<T> {

  public static int fail = -1;
  private SeqValidator<T> validator = new SeqValidator<T>();

  // ISearch methods

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

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

  // Abstract methods

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