code: public static void checkForValidIndex(int index, int size)
      {
          if (index < 0)
          {
              throw new IndexOutOfBoundsException(
                  "Index "+index+" is negative");
          }
          if (index >= size)
          {
              throw new IndexOutOfBoundsException(
                  "Index "+index+", size "+size);
          }
      }
docs: Checks whether the given index is valid for accessing a tuple with
  the given size, and throws an <code>IndexOutOfBoundsException</code>
  if not.
  
  @param index The index
  @param size The size
  @throws IndexOutOfBoundsException If the given index is negative
  or not smaller than then given size