All pastes #338145 Raw Edit

Caturady

public java v1 · immutable
·published 2007-02-03 06:05 UTC
rendered paste body
/** * Name:		Team Orange		<br /> * Course:		4010-361-03		<br /> * Assignment:	Project 		<br /> * Date:		2/19/07			<br /> * <br /> * Class:	TeacherList.java	<br /> * Purpose:	This class provides the means by which to store several Teacher objects. * <br /> * @author Zack */package dataObject;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable;import java.util.ArrayList;import java.util.Iterator;public class TeacherList implements Serializable {		/**	 * Refer to the Java API for a good explanation of this constant.	 * Essentially, it is maintained so that Java can be sure that it's	 * deserializing to the right version of an object.  It should be modified	 * when changes to the structure of the object are made.	 */		private static final long serialVersionUID = 1L;		/**	 * The Singleton object.	 */	private static TeacherList thisList;		/**	 * The list of teachers managed by this class.	 */	private ArrayList<Teacher> teachers;		/**	 * Default constructor.	 * @author - Zack	 */	private TeacherList() {		this.teachers = new ArrayList<Teacher>();	}		/**	 * The singleton control method	 * @author Zack	 * <br />	 * @return the singleton of this class	 */	public TeacherList getInstance() {		TeacherList aList = thisList;				if( thisList == null ) {			aList = new TeacherList();		}				return aList;	}		public void writeObject( ObjectOutputStream out ) throws IOException {		out.writeObject(this);		out.close();	}	public static void readObject( ObjectInputStream in ) throws IOException, ClassNotFoundException {		thisList = (TeacherList)in.readObject();		in.close();	}	/**	 * Method to add a new teacher to this list.	 * @author - Zack	 * <br />	 * @param newTeacher the teacher to add	 */	public void addTeacher( Teacher newTeacher ) {		this.teachers.add( newTeacher );	}	/**	 * Method to delete a teacher from this list.	 * @author - Zack	 * <br />	 * @param teacherToRemove the teacher to be removed	 */	public void deleteTeacher( Teacher teacherToRemove ){		this.teachers.remove( teacherToRemove );	}		/**	 * Method to update a teacher in this list.	 * @author - Zack	 * <br />	 * @param oldTeacher the teacher to be modified	 * @param newTeacher the newly modified teacher object	 */	public void updateTeacher( Teacher oldTeacher, Teacher newTeacher ) {		this.deleteTeacher( oldTeacher );		this.addTeacher( newTeacher );	}	/**	 * Method to retrieve a teacher based on the teacher's name.	 * @author - Zack	 * <br />	 * @param teacherName the name of the teacher to be retrieved contained in a 	 * 			two-element array [firstname,lastname]	 * @return the Teacher object associated with that name	 */	public Teacher retrieveTeacher( String[] teacherName ) {		Iterator iter = this.teachers.iterator();				while( iter.hasNext() ) {			Teacher currTeacher = (Teacher)iter.next();						if( currTeacher.getName().equals( teacherName ) ) {				return currTeacher;			}		}				return null;	}		/**	 * Method to return the entire list of teachers.	 * @author - Zack	 * <br />	 * @return the list of teachers 	 */	public ArrayList<Teacher> retrieveAllTeachers() {		return this.teachers;	}}