getNext() just tries to get the next non-null Event (using an index "next" is bad, EventSet should provide an Enumerator or Iterator):public Event getNext() {
    boolean looped = false;
    int start = next; //the current index is in "next", assume already processed, rememberd it
    do {
      next = (next + 1) % events.length; //go to next entry, go to the first entry if necessary
      // See if it has looped to the beginning:
      if(start == next) looped = true; //if back to where it starts, we are in a loop, apparently all the rest entries are empty (null)
      // If it loops past start, the list 
      // is empty:
      if((next == (start + 1) % events.length)
        && looped)
        return null;
    } while(events[next] == null);
   //got here? it means, we got a non-null entry
    return events[next];
  }