import java.util.*;

public class UBEvent {
	private ArrayList when = new ArrayList(); // All the times this event may fire
	private boolean active = false;
	private boolean[] type; // If we choose the bit array (see doFire())
	
	public UBEvent() {
		this.active = false;
	}
	
	public UBEvent(Date when, boolean active) {
		this.when.add(when);
		this.active = active;
	}
	
	public void checkFire() {
		if (this.active) {
			Date now = new Date();
			for(int i=0;i<when.size();i++) { // Should use a proper iterator for this.
				Date current = ((Date)when.get(i));
				if (current.before(now)) {
					this.doFire(current);
				}
			}
		}
	}
	
	public boolean doFire(Date which) {
		/*
		 * Do whatever this Event was supposed to do. A basic event like this
		 * does nothing, and so returns true. A more complex event should
		 * inherit from this Event to make it's own Event class ... such as
		 * MeetingNotification, LectureNotification, etc.
		 *
		 * Or, we could make this Event class hold all types of events by making
		 * a bit array like I did for UBUser's flags. Easier to manage, but not
		 * really OOP'ish.
		 *
		 */
		return true; // The event fired successfully.
	}
	
	public void activate() {
		active = true;
	}
	public void deactivate() {
		active = false;
	}
	public boolean isActive() {
		return active;
	}
	
	public synchronized void addWhen(Date which) {
		when.add(which);
	}
	public synchronized void removeWhen(Date which) {
		Iterator it = when.iterator();
		while(it.hasNext()) {
			Date current = ((Date)it.next());
			if (current.equals(which)) {
				it.remove();
				break; // Only remove 1 when per call.
			}
		}
	}
	public synchronized void removeWhenBefore(Date which) {
		Iterator it = when.iterator();
		while(it.hasNext()) {
			Date current = ((Date)it.next());
			if (current.before(which)) {
				it.remove();
			}
		}
	}
}