Sunday, February 19, 2017

ISearch

// ===============================================================
// God bless the day I discovered you.
//
//          - MALLETTE, MORRISON, RYAN ("Lookin' for Love" lyrics)
// ===============================================================

interface ISearch<T extends Comparable<T>> {

  /**
   * Search for key in the part of seq that is between from and
   * to inclusive. Return the index of a position in seq where a
   * value matching key was found or -1 if no such value exists
   * between from and to.
   *
   * @author  John P. Spurgeon
   *
   * @param   seq   a sequence of one or more values
   * @param   key   a value to find
   * @param   from  a boundary value
   * @param   to    a boundary value
   *
   * @returns an integer between from and to inclusive or -1
   * @throws  IllegalArgumentException if seq is null or
   *          seq.length is zero
   * @throws  IndexOutOfBoundsException if either from or to is
   *          less than zero or greater than seq.length - 1
   */

  int find(T[] seq, T key, int from, int to)
  throws IndexOutOfBoundsException, IllegalArgumentException;

  int find(T[] seq, T key)
  throws IllegalArgumentException;
}