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];
}
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];
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货