/**
* Name: Team Orange
* Course: 4010-361-03
* Assignment: Project
* Date: 2/19/07
*
* Class: TeacherList.java
* Purpose: This class provides the means by which to store several Teacher objects.
*
* @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 teachers;
/**
* Default constructor.
* @author - Zack
*/
private TeacherList() {
this.teachers = new ArrayList();
}
/**
* The singleton control method
* @author Zack
*
* @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
*
* @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
*
* @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
*
* @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
*
* @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
*
* @return the list of teachers
*/
public ArrayList retrieveAllTeachers() {
return this.teachers;
}
}