Source of 2.31.java


  1: @author Frank M. Carrano, Timothy M. Henry
  2: @version 5.0
  3:          // Locates a given entry within the array bag.
  4:         // Returns the index of the entry, if located, or -1 otherwise.
  5:         // Precondition: checkIntegrity has been called.
  6:    private int getIndexOf(T anEntry)
  7:         {
  8:                 int where = -1;
  9:                 boolean found = false;
 10:       int index = 0;

 12:       while (!found && (index < numberOfEntries))
 13:       {
 14:          if (anEntry.equals(bag[index]))
 15:          {
 16:             found = true;
 17:             where = index;
 18:          } // end if
 19:          index++;
 20:       } // end while

 22:       // Assertion: If where > -1, anEntry is in the array bag, and it
 23:       // equals bag[where]; otherwise, anEntry is not in the array
 24:       
 25:                 return where;
 26:         } // end getIndexOf