/******************************************************************************* * Copyright (c) 2003, 2007 Mylyn project committers and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html *******************************************************************************/ package org.eclipse.mylyn.internal.bugzilla.core.history; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /** * @author John Anvik */ public class TaskHistory implements Iterable, Serializable { private static final long serialVersionUID = 1724420130243724426L; private final List statusEvents; private final List resolutionEvents; private final List assignmentEvents; private final List otherEvents; private final List attachmentEvents; public TaskHistory() { this.statusEvents = new ArrayList(); this.resolutionEvents = new ArrayList(); this.assignmentEvents = new ArrayList(); this.attachmentEvents = new ArrayList(); this.otherEvents = new ArrayList(); } public void addEvent(TaskRevision event) { if (event instanceof StatusEvent) { this.statusEvents.add((StatusEvent) event); return; } if (event instanceof ResolutionEvent) { this.resolutionEvents.add((ResolutionEvent) event); return; } if (event instanceof AssignmentEvent) { this.assignmentEvents.add((AssignmentEvent) event); return; } if (event instanceof AttachmentEvent) { this.attachmentEvents.add((AttachmentEvent) event); return; } this.otherEvents.add(event); } private List getEvents() { List events = new ArrayList(); events.addAll(this.statusEvents); events.addAll(this.resolutionEvents); events.addAll(this.assignmentEvents); events.addAll(this.attachmentEvents); events.addAll(this.otherEvents); Collections.sort(events); return events; } public Iterator iterator() { return getEvents().iterator(); } public int size() { return this.otherEvents.size() + this.statusEvents.size() + this.resolutionEvents.size() + this.assignmentEvents.size(); } @Override public String toString() { StringBuffer sb = new StringBuffer(); for (Object event : this) { sb.append(event); sb.append("\n"); } return sb.toString(); } public List getStatusEvents() { return statusEvents; } public List getResolutionEvents() { return resolutionEvents; } public List getOtherEvents() { return otherEvents; } public List getAttachmentEvents() { return attachmentEvents; } public List getAssignmentEvents() { return assignmentEvents; } }